Skip to content

Commit 1274fed

Browse files
committed
fix: logger messages
1 parent c9875ca commit 1274fed

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
1111
### Update
1212

1313
- Update core
14+
- Fix logger messages
1415

1516
---
1617

lib/utils/logger.util.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import pino from 'pino';
1+
import pino, { BaseLogger } from 'pino';
22
import { LoggerOptions } from 'pino';
33

44
class DefaultLogger {
5-
protected static pino: any;
5+
protected static pino: BaseLogger = null as unknown as BaseLogger;
66
protected static config: LoggerOptions = {
77
transport: {
88
target: 'pino-pretty',
99
options: {
1010
translateTime: 'HH:MM:ss',
11-
messageFormat: '{levelLabel} {pid} {msg}',
1211
ignore: 'pid,hostname',
1312
prettyPrint: {
1413
colorize: true,
@@ -18,7 +17,7 @@ class DefaultLogger {
1817
},
1918
};
2019

21-
public static init() {
20+
public static instance() {
2221
if (!DefaultLogger.pino) {
2322
this.pino = pino(DefaultLogger.config);
2423
}
@@ -38,17 +37,19 @@ export const checkEnv = (callback: Function, type?: LogsType): void => {
3837
}
3938
};
4039

40+
const loggerInstance = DefaultLogger.instance();
41+
4142
const Logger = {
4243
info: (message: string) => {
43-
const callback = () => DefaultLogger.init().info({}, message);
44+
const callback = () => loggerInstance.info(message);
4445
checkEnv(callback, 'info');
4546
},
4647
error: (message: string) => {
47-
const callback = () => DefaultLogger.init().error({}, message);
48+
const callback = () => loggerInstance.error(message);
4849
checkEnv(callback, 'error');
4950
},
5051
warn: (message: string) => {
51-
const callback = () => DefaultLogger.init().warn({}, message);
52+
const callback = () => loggerInstance.warn(message);
5253
checkEnv(callback, 'warn');
5354
},
5455
};

tests/utils/logger.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { checkEnv } from '@types-ddd';
1+
import { Logger, checkEnv } from '@types-ddd';
22

33
describe('Logger', () => {
44
it('should log if is not production and log is not off', () => {
@@ -88,4 +88,10 @@ describe('Logger', () => {
8888

8989
expect(callback).not.toHaveBeenCalled();
9090
});
91+
92+
it('logger must print message', () => {
93+
process.env.NODE_ENV = undefined;
94+
process.env.TYPES_DDD_LOGS = undefined;
95+
Logger.info('some success message');
96+
});
9197
});

0 commit comments

Comments
 (0)