Skip to content

Commit b58f723

Browse files
author
Manuel
committed
chore: inject child logger in modules
1 parent 03df1b4 commit b58f723

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/core/createEnvForModule.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { constantCase } from 'constant-case';
22

33
import type { CreatedModule, ModuleFactory } from './createModule';
4+
import { createLoggerForModule } from './logger';
45

56
const createEnvForModule = (constantName: string) =>
67
Object.entries(process.env)
@@ -25,8 +26,8 @@ export const createAllModules = async (
2526
for (const [name, factory] of Object.entries(modules)) {
2627
const moduleConstantName = constantCase(name);
2728
const moduleEnv = createEnvForModule(moduleConstantName);
28-
const module = await factory({ env: moduleEnv });
29-
29+
const moduleLogger = createLoggerForModule(name);
30+
const module = await factory({ env: moduleEnv, logger: moduleLogger });
3031
createdModules.push(module);
3132
}
3233

src/core/createModule.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ClientEvents, ClientOptions } from 'discord.js';
2+
import type { Logger } from 'pino';
23
import type { ZodTypeAny } from 'zod';
34
import { z } from 'zod';
45

@@ -10,6 +11,7 @@ type InferredZodShape<Shape extends Record<string, ZodTypeAny>> = {
1011

1112
interface Context<Env extends Record<string, ZodTypeAny>> {
1213
env: InferredZodShape<Env>;
14+
logger: Logger;
1315
}
1416

1517
type ModuleFunction<Env extends Record<string, ZodTypeAny>, ReturnType> = (
@@ -29,6 +31,7 @@ type BotModule<Env extends Record<string, ZodTypeAny>> = {
2931

3032
interface CreatedModuleInput {
3133
env: unknown;
34+
logger: Logger;
3235
}
3336

3437
export interface CreatedModule {
@@ -47,6 +50,7 @@ export const createModule = <Env extends Record<string, ZodTypeAny>>(
4750

4851
const context = {
4952
env,
53+
logger: input.logger,
5054
};
5155

5256
return {

0 commit comments

Comments
 (0)