Skip to content

Commit

Permalink
wip: add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mathysth committed Mar 17, 2024
1 parent 30c8067 commit 47ef014
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/core/src/services/logger.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { CosmosConfig } from '@config/config';
import { injectable } from 'inversify';
import { type Logger, pino } from 'pino';
import pretty from 'pino-pretty';
import { Env } from 'src';

type PinoType = Logger<never>;

/**
* Available environement
*/
export enum ENV_STATE_ENUM {
PROD = 'PROD',
DEV = 'DEV',
}

@injectable()
export class LoggerService {
private _pino: PinoType;

public constructor(config: CosmosConfig) {
const env = config.get<ENV_STATE_ENUM>(config.getEnvKey('ENV'));
console.log(env);
if (env === ENV_STATE_ENUM.DEV) {
this._pino = pino(
pretty({
colorize: true,
}),
);
} else {
this._pino = pino();
}
}

/**
* Access to pino library
*/
get pino(): PinoType {
return this._pino;
}

private set pino(logger: PinoType) {
this._pino = logger;
}
}

0 comments on commit 47ef014

Please sign in to comment.