@nest-yalc-2/logger 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__tests__/logger.factory.spec.ts +9 -9
- package/src/__tests__/logger.helper.spec.ts +1 -1
- package/src/index.d.ts +7 -7
- package/src/index.js +13 -24
- package/src/index.js.map +1 -1
- package/src/index.ts +7 -7
- package/src/logger-nest.service.d.ts +4 -4
- package/src/logger-nest.service.js +6 -6
- package/src/logger-nest.service.js.map +1 -1
- package/src/logger-nest.service.ts +4 -3
- package/src/logger.factory.d.ts +1 -1
- package/src/logger.factory.js +14 -46
- package/src/logger.factory.js.map +1 -1
- package/src/logger.factory.ts +5 -5
- package/src/logger.service.d.ts +1 -1
- package/src/logger.service.js +2 -2
- package/src/logger.service.js.map +1 -1
- package/src/logger.service.ts +3 -2
- package/src/typeorm-logger.d.ts +1 -1
- package/src/typeorm-logger.js +9 -9
- package/src/typeorm-logger.js.map +1 -1
- package/src/typeorm-logger.ts +2 -2
- package/src/__tests__/logger-console.service.spec.ts +0 -136
- package/src/__tests__/logger-pino.service.spec.ts +0 -149
- package/src/logger-abstract.service.d.ts +0 -65
- package/src/logger-abstract.service.js +0 -91
- package/src/logger-abstract.service.js.map +0 -1
- package/src/logger-abstract.service.ts +0 -210
- package/src/logger-console.service.d.ts +0 -5
- package/src/logger-console.service.js +0 -23
- package/src/logger-console.service.js.map +0 -1
- package/src/logger-console.service.ts +0 -80
- package/src/logger-pino.service.d.ts +0 -10
- package/src/logger-pino.service.js +0 -89
- package/src/logger-pino.service.js.map +0 -1
- package/src/logger-pino.service.ts +0 -161
- package/src/logger.enum.d.ts +0 -17
- package/src/logger.enum.js +0 -35
- package/src/logger.enum.js.map +0 -1
- package/src/logger.enum.ts +0 -32
- package/src/logger.event.d.ts +0 -11
- package/src/logger.event.js +0 -16
- package/src/logger.event.js.map +0 -1
- package/src/logger.event.ts +0 -11
- package/src/logger.helper.d.ts +0 -4
- package/src/logger.helper.js +0 -36
- package/src/logger.helper.js.map +0 -1
- package/src/logger.helper.ts +0 -40
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
expect,
|
|
3
|
-
jest,
|
|
4
|
-
describe,
|
|
5
|
-
it,
|
|
6
|
-
beforeEach,
|
|
7
|
-
beforeAll,
|
|
8
|
-
afterAll,
|
|
9
|
-
afterEach,
|
|
10
|
-
} from '@jest/globals';
|
|
11
|
-
import { type ConsoleLogger as TConsoleLogger } from '../logger-console.service.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Not sure why this is needed, but it is. Jest has reference errors when try to import the logger-console.service.js file
|
|
15
|
-
* probably still caused by the ESM
|
|
16
|
-
*/
|
|
17
|
-
jest.unstable_mockModule('@nest-yalc-2/logger/logger.factory.js', async () => {
|
|
18
|
-
return {
|
|
19
|
-
AppLoggerFactory: jest.fn(),
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
import { ConsoleLogger } from '../logger-console.service.js';
|
|
24
|
-
import { LOG_LEVEL_ALL } from '../logger.enum.js';
|
|
25
|
-
|
|
26
|
-
const logOptions = {
|
|
27
|
-
context: 'test',
|
|
28
|
-
data: { pass: 'data' },
|
|
29
|
-
masks: ['pass'],
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
describe('Console logger service test', () => {
|
|
33
|
-
let logger: TConsoleLogger;
|
|
34
|
-
|
|
35
|
-
beforeEach(async () => {
|
|
36
|
-
logger = new ConsoleLogger('test', LOG_LEVEL_ALL);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('Test undefined levels', async () => {
|
|
40
|
-
const methodLog = jest.spyOn(console, 'log');
|
|
41
|
-
const methodError = jest.spyOn(console, 'error');
|
|
42
|
-
const methodWarn = jest.spyOn(console, 'warn');
|
|
43
|
-
logger = new ConsoleLogger('test', undefined);
|
|
44
|
-
logger.log('test');
|
|
45
|
-
logger.error('test');
|
|
46
|
-
logger.warn('test');
|
|
47
|
-
|
|
48
|
-
expect(methodLog).not.toHaveBeenCalled();
|
|
49
|
-
expect(methodError).not.toHaveBeenCalled();
|
|
50
|
-
expect(methodWarn).not.toHaveBeenCalled();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('Test log', async () => {
|
|
54
|
-
const method = jest.spyOn(console, 'log');
|
|
55
|
-
logger.log('test');
|
|
56
|
-
|
|
57
|
-
expect(method).toHaveBeenCalled();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('Test log with options', async () => {
|
|
61
|
-
const method = jest.spyOn(console, 'log');
|
|
62
|
-
logger.log('test', logOptions);
|
|
63
|
-
|
|
64
|
-
expect(method).toHaveBeenCalled();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('Test error', async () => {
|
|
68
|
-
const method = jest.spyOn(console, 'error');
|
|
69
|
-
logger.error('error', 'trace', { data: 'test' });
|
|
70
|
-
|
|
71
|
-
expect(method).toHaveBeenCalled();
|
|
72
|
-
expect(method).toHaveBeenCalledWith('[test]', 'error', 'trace', {
|
|
73
|
-
message: 'test',
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('Test error with options', async () => {
|
|
78
|
-
const method = jest.spyOn(console, 'error');
|
|
79
|
-
logger.error('test', undefined, logOptions);
|
|
80
|
-
|
|
81
|
-
expect(method).toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('Test warn', async () => {
|
|
85
|
-
const method = jest.spyOn(console, 'warn');
|
|
86
|
-
logger.warn('warn');
|
|
87
|
-
|
|
88
|
-
expect(method).toHaveBeenCalled();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('Test warn with options', async () => {
|
|
92
|
-
const method = jest.spyOn(console, 'warn');
|
|
93
|
-
logger.warn('test', logOptions);
|
|
94
|
-
|
|
95
|
-
expect(method).toHaveBeenCalled();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('Test debug', async () => {
|
|
99
|
-
const method = jest.spyOn(console, 'debug');
|
|
100
|
-
logger.debug?.('debug');
|
|
101
|
-
|
|
102
|
-
expect(method).toHaveBeenCalled();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('Test debug with options', async () => {
|
|
106
|
-
const method = jest.spyOn(console, 'debug');
|
|
107
|
-
logger.debug?.('test', logOptions);
|
|
108
|
-
|
|
109
|
-
expect(method).toHaveBeenCalled();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('Test verbose', async () => {
|
|
113
|
-
const method = jest.spyOn(console, 'info');
|
|
114
|
-
logger.verbose?.('verbose');
|
|
115
|
-
|
|
116
|
-
expect(method).toHaveBeenCalled();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('Test verbose with options', async () => {
|
|
120
|
-
const method = jest.spyOn(console, 'info');
|
|
121
|
-
logger.verbose?.('test', logOptions);
|
|
122
|
-
|
|
123
|
-
expect(method).toHaveBeenCalled();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('setLogLevels should validate levels and emit events', async () => {
|
|
127
|
-
const emitter = { emit: jest.fn() } as any;
|
|
128
|
-
logger.setLogLevels(LOG_LEVEL_ALL);
|
|
129
|
-
logger.error('boom', 'trace', { eventEmitter: emitter, useFallbackEvent: true });
|
|
130
|
-
expect(emitter.emit).toHaveBeenCalled();
|
|
131
|
-
emitter.emit.mockClear();
|
|
132
|
-
logger.error('skip', 'trace', { eventEmitter: emitter, event: false as any });
|
|
133
|
-
expect(emitter.emit).not.toHaveBeenCalled();
|
|
134
|
-
expect(() => logger.setLogLevels(['invalid' as any])).toThrow();
|
|
135
|
-
});
|
|
136
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
expect,
|
|
3
|
-
jest,
|
|
4
|
-
describe,
|
|
5
|
-
it,
|
|
6
|
-
beforeEach,
|
|
7
|
-
afterEach,
|
|
8
|
-
} from '@jest/globals';
|
|
9
|
-
|
|
10
|
-
import { Logger } from 'pino';
|
|
11
|
-
import { PinoLogger, FLUSH_INTERVAL, flush } from '../index.js';
|
|
12
|
-
import { LOG_LEVEL_ALL } from '../logger.enum.js';
|
|
13
|
-
|
|
14
|
-
const logOptions = {
|
|
15
|
-
context: 'test',
|
|
16
|
-
data: { pass: 'data' },
|
|
17
|
-
masks: ['pass'],
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
describe('Pino logger service test', () => {
|
|
21
|
-
let pino: Logger;
|
|
22
|
-
const container: { logger?: PinoLogger } = {
|
|
23
|
-
logger: new PinoLogger('test', LOG_LEVEL_ALL),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
beforeEach(async () => {
|
|
27
|
-
container.logger = new PinoLogger('test', LOG_LEVEL_ALL);
|
|
28
|
-
pino = container.logger?.getLogger();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
jest.useRealTimers();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('Test log', async () => {
|
|
36
|
-
const method = jest.spyOn(pino, 'info');
|
|
37
|
-
container.logger?.log('test');
|
|
38
|
-
|
|
39
|
-
expect(method).toHaveBeenCalled();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('Test log with options', async () => {
|
|
43
|
-
const method = jest.spyOn(pino, 'info');
|
|
44
|
-
container.logger?.log('info', logOptions);
|
|
45
|
-
|
|
46
|
-
expect(method).toHaveBeenCalled();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('Test error', async () => {
|
|
50
|
-
const method = jest.spyOn(pino, 'error');
|
|
51
|
-
container.logger?.error('error', 'trace');
|
|
52
|
-
|
|
53
|
-
expect(method).toHaveBeenCalled();
|
|
54
|
-
// expect(method).toHaveBeenCalledWith({ context: 'test' }, 'error trace');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('Test error with options', async () => {
|
|
58
|
-
const method = jest.spyOn(pino, 'error');
|
|
59
|
-
container.logger?.error('error', undefined, logOptions);
|
|
60
|
-
|
|
61
|
-
expect(method).toHaveBeenCalled();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('Test warn', async () => {
|
|
65
|
-
const method = jest.spyOn(pino, 'warn');
|
|
66
|
-
container.logger?.warn('warn');
|
|
67
|
-
|
|
68
|
-
expect(method).toHaveBeenCalled();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('Test warn with options', async () => {
|
|
72
|
-
const method = jest.spyOn(pino, 'warn');
|
|
73
|
-
container.logger?.warn('warn', logOptions);
|
|
74
|
-
|
|
75
|
-
expect(method).toHaveBeenCalled();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('Test debug', async () => {
|
|
79
|
-
const method = jest.spyOn(pino, 'debug');
|
|
80
|
-
container.logger?.debug?.('debug');
|
|
81
|
-
|
|
82
|
-
expect(method).toHaveBeenCalled();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('Test debug with options', async () => {
|
|
86
|
-
const method = jest.spyOn(pino, 'debug');
|
|
87
|
-
container.logger?.debug?.('debug', logOptions);
|
|
88
|
-
|
|
89
|
-
expect(method).toHaveBeenCalled();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('Test verbose with options', async () => {
|
|
93
|
-
const method = jest.spyOn(pino, 'trace');
|
|
94
|
-
container.logger?.verbose?.('verbose', logOptions);
|
|
95
|
-
|
|
96
|
-
expect(method).toHaveBeenCalled();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('Test verbose & flush', async () => {
|
|
100
|
-
jest.useFakeTimers();
|
|
101
|
-
|
|
102
|
-
jest.mock('process', () => ({
|
|
103
|
-
on: jest.fn((fn) => {
|
|
104
|
-
fn();
|
|
105
|
-
}),
|
|
106
|
-
}));
|
|
107
|
-
|
|
108
|
-
const _logger = new PinoLogger('test', LOG_LEVEL_ALL);
|
|
109
|
-
|
|
110
|
-
const method = jest.spyOn(pino, 'trace');
|
|
111
|
-
_logger.verbose?.('verbose');
|
|
112
|
-
|
|
113
|
-
// Fast-forward until all timers have been executed
|
|
114
|
-
jest.advanceTimersByTime(FLUSH_INTERVAL + 1000);
|
|
115
|
-
|
|
116
|
-
expect(method).toHaveBeenCalled();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('Test on application shutdown', async () => {
|
|
120
|
-
const method = jest.spyOn(pino, 'info');
|
|
121
|
-
container.logger?.log('test');
|
|
122
|
-
await container.logger?.onApplicationShutdown();
|
|
123
|
-
expect(method).toHaveBeenCalledWith({ context: 'test' }, 'test');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('Test flush when logger has been destroyed', async () => {
|
|
127
|
-
const method = jest.spyOn(pino, 'flush');
|
|
128
|
-
method.mockImplementation((callback: any) => {
|
|
129
|
-
callback();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
delete container.logger;
|
|
133
|
-
await flush();
|
|
134
|
-
expect(container.logger).toBeUndefined();
|
|
135
|
-
expect(method).toHaveBeenCalled();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('Test flush with error', async () => {
|
|
139
|
-
const method = jest.spyOn(pino, 'flush');
|
|
140
|
-
method.mockImplementation((callback: any) => {
|
|
141
|
-
callback(new Error('test'));
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
expect(
|
|
145
|
-
async () => await container.logger?.onApplicationShutdown(),
|
|
146
|
-
).rejects.toThrow();
|
|
147
|
-
expect(method).toHaveBeenCalled();
|
|
148
|
-
});
|
|
149
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { LoggerService, LogLevel } from '@nestjs/common';
|
|
2
|
-
import { type EventEmitter2 } from '@nestjs/event-emitter';
|
|
3
|
-
import { PluginSystem } from '@nest-yalc-2/utils/plugin.helper.js';
|
|
4
|
-
import { YalcGlobalClsService } from '../../app/src/cls.module.js';
|
|
5
|
-
export interface LogMethodOptions {
|
|
6
|
-
message?: any;
|
|
7
|
-
data?: any;
|
|
8
|
-
config?: any;
|
|
9
|
-
masks?: string[];
|
|
10
|
-
context?: string;
|
|
11
|
-
stack?: string;
|
|
12
|
-
event?: string | false;
|
|
13
|
-
}
|
|
14
|
-
export type LogMethod = (message: any, options?: LogMethodOptions) => void;
|
|
15
|
-
export type LogMethodError = (message: any, stack?: string, options?: LogMethodOptions) => void;
|
|
16
|
-
export interface ILoggerPluginMethods<TClsService = any> extends Record<string, {
|
|
17
|
-
(...args: any[]): void;
|
|
18
|
-
} | undefined> {
|
|
19
|
-
onBeforeLogging?: (message: any, options: LogMethodOptions, clsService: TClsService) => void;
|
|
20
|
-
}
|
|
21
|
-
export interface ImprovedLoggerService extends ImprovedLoggerServiceMethods, PluginSystem<ILoggerPluginMethods> {
|
|
22
|
-
}
|
|
23
|
-
export interface ImprovedLoggerServiceMethods extends LoggerService {
|
|
24
|
-
log: LogMethod;
|
|
25
|
-
error: LogMethodError;
|
|
26
|
-
warn: LogMethod;
|
|
27
|
-
debug?: LogMethod | undefined;
|
|
28
|
-
verbose?: LogMethod;
|
|
29
|
-
}
|
|
30
|
-
export declare const EVENT_LOG_DEFAULT = "EVENT_LOG_DEFAULT";
|
|
31
|
-
export interface IImprovedLoggerOptions {
|
|
32
|
-
event?: {
|
|
33
|
-
eventEmitter?: EventEmitter2 | false;
|
|
34
|
-
useFallbackEvent?: boolean;
|
|
35
|
-
} | false;
|
|
36
|
-
clsService?: YalcGlobalClsService;
|
|
37
|
-
overrideLoggerLevels?: LogLevel[];
|
|
38
|
-
}
|
|
39
|
-
declare const LoggerAbstractService_base: {
|
|
40
|
-
new (...args: any[]): {
|
|
41
|
-
[x: string]: any;
|
|
42
|
-
plugins: import("@nest-yalc-2/utils/plugin.helper.js").Plugin<ILoggerPluginMethods<any>>[];
|
|
43
|
-
registerPlugin(plugin: import("@nest-yalc-2/utils/plugin.helper.js").Plugin<ILoggerPluginMethods<any>>): void;
|
|
44
|
-
unregisterPlugin(plugin: import("@nest-yalc-2/utils/plugin.helper.js").Plugin<ILoggerPluginMethods<any>>): void;
|
|
45
|
-
invokePlugins(methodName: keyof ILoggerPluginMethods<any>, ...args: any[]): void;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
export declare abstract class LoggerAbstractService extends LoggerAbstractService_base implements ImprovedLoggerService {
|
|
49
|
-
protected context: string;
|
|
50
|
-
protected logLevels: LogLevel[] | undefined;
|
|
51
|
-
protected methods: ImprovedLoggerServiceMethods;
|
|
52
|
-
protected options: IImprovedLoggerOptions;
|
|
53
|
-
readonly isImprovedLoggerService = true;
|
|
54
|
-
constructor(context: string, logLevels: LogLevel[] | undefined, methods: ImprovedLoggerServiceMethods, options?: IImprovedLoggerOptions);
|
|
55
|
-
setLogLevels(levels: LogLevel[]): void;
|
|
56
|
-
initializeLogger(): void;
|
|
57
|
-
log: LogMethod;
|
|
58
|
-
error: LogMethodError;
|
|
59
|
-
warn: LogMethod;
|
|
60
|
-
debug?: LogMethod | undefined;
|
|
61
|
-
verbose?: LogMethod;
|
|
62
|
-
beforeLogging(message: any, options: LogMethodOptions): void;
|
|
63
|
-
}
|
|
64
|
-
export declare function beforeLogging(message: any, options?: LogMethodOptions & IImprovedLoggerOptions['event']): void;
|
|
65
|
-
export {};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LoggerAbstractService = exports.EVENT_LOG_DEFAULT = void 0;
|
|
4
|
-
exports.beforeLogging = beforeLogging;
|
|
5
|
-
const logger_enum_js_1 = require("./logger.enum.js");
|
|
6
|
-
const plugin_helper_js_1 = require("@nest-yalc-2/utils/plugin.helper.js");
|
|
7
|
-
exports.EVENT_LOG_DEFAULT = 'EVENT_LOG_DEFAULT';
|
|
8
|
-
class LoggerAbstractService extends (0, plugin_helper_js_1.WithPluginSystem)() {
|
|
9
|
-
constructor(context, logLevels, methods, options = {}) {
|
|
10
|
-
super();
|
|
11
|
-
this.context = context;
|
|
12
|
-
this.logLevels = logLevels;
|
|
13
|
-
this.methods = methods;
|
|
14
|
-
this.options = options;
|
|
15
|
-
this.isImprovedLoggerService = true;
|
|
16
|
-
this.initializeLogger();
|
|
17
|
-
}
|
|
18
|
-
setLogLevels(levels) {
|
|
19
|
-
this.logLevels = levels;
|
|
20
|
-
this.initializeLogger();
|
|
21
|
-
}
|
|
22
|
-
initializeLogger() {
|
|
23
|
-
const enabledLevels = {};
|
|
24
|
-
this.logLevels?.forEach((level) => {
|
|
25
|
-
if (!(level.toUpperCase() in logger_enum_js_1.LogLevelEnum))
|
|
26
|
-
throw new Error(`ERROR: Logger Level: ${level} is not supported!`);
|
|
27
|
-
enabledLevels[level] = true;
|
|
28
|
-
});
|
|
29
|
-
this.log = (message, options = {}) => {
|
|
30
|
-
void this.beforeLogging(message, options);
|
|
31
|
-
(enabledLevels[logger_enum_js_1.LogLevelEnum.LOG] === true &&
|
|
32
|
-
this.methods[logger_enum_js_1.LogLevelEnum.LOG]
|
|
33
|
-
? this.methods[logger_enum_js_1.LogLevelEnum.LOG]
|
|
34
|
-
: () => { })(message, options);
|
|
35
|
-
};
|
|
36
|
-
this.error = (message, stack, options = {}) => {
|
|
37
|
-
options.stack = stack;
|
|
38
|
-
void this.beforeLogging(message, options);
|
|
39
|
-
(enabledLevels[logger_enum_js_1.LogLevelEnum.ERROR] === true &&
|
|
40
|
-
this.methods[logger_enum_js_1.LogLevelEnum.ERROR]
|
|
41
|
-
? this.methods[logger_enum_js_1.LogLevelEnum.ERROR]
|
|
42
|
-
: () => { })(message, stack, options);
|
|
43
|
-
};
|
|
44
|
-
this.warn = (message, options = {}) => {
|
|
45
|
-
void this.beforeLogging(message, options);
|
|
46
|
-
(enabledLevels[logger_enum_js_1.LogLevelEnum.WARN] === true &&
|
|
47
|
-
this.methods[logger_enum_js_1.LogLevelEnum.WARN]
|
|
48
|
-
? this.methods[logger_enum_js_1.LogLevelEnum.WARN]
|
|
49
|
-
: () => { })(message, options);
|
|
50
|
-
};
|
|
51
|
-
if (enabledLevels[logger_enum_js_1.LogLevelEnum.DEBUG] === true &&
|
|
52
|
-
this.methods[logger_enum_js_1.LogLevelEnum.DEBUG])
|
|
53
|
-
this.debug = (message, options = {}) => {
|
|
54
|
-
void this.beforeLogging(message, options);
|
|
55
|
-
this.methods[logger_enum_js_1.LogLevelEnum.DEBUG](message, options);
|
|
56
|
-
};
|
|
57
|
-
if (enabledLevels[logger_enum_js_1.LogLevelEnum.VERBOSE] === true &&
|
|
58
|
-
this.methods[logger_enum_js_1.LogLevelEnum.VERBOSE])
|
|
59
|
-
this.verbose = (message, options = {}) => {
|
|
60
|
-
void this.beforeLogging(message, options);
|
|
61
|
-
this.methods[logger_enum_js_1.LogLevelEnum.VERBOSE](message, options);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
beforeLogging(message, options) {
|
|
65
|
-
this.options.event = this.options.event ?? {};
|
|
66
|
-
this.invokePlugins('onBeforeLogging', message, options, this.options.clsService);
|
|
67
|
-
return beforeLogging(message, options);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.LoggerAbstractService = LoggerAbstractService;
|
|
71
|
-
function beforeLogging(message, options = {}) {
|
|
72
|
-
const emitter = options && options.eventEmitter;
|
|
73
|
-
if (!emitter)
|
|
74
|
-
return;
|
|
75
|
-
const useFallbackEvent = (options && options.useFallbackEvent) ?? false;
|
|
76
|
-
const defaultEventName = useFallbackEvent ? exports.EVENT_LOG_DEFAULT : false;
|
|
77
|
-
const eventName = options.event ?? defaultEventName;
|
|
78
|
-
if (!eventName)
|
|
79
|
-
return;
|
|
80
|
-
const { event } = require('@nest-yalc-2/event-manager/event.js');
|
|
81
|
-
event(eventName, {
|
|
82
|
-
event: { emitter },
|
|
83
|
-
data: options?.data,
|
|
84
|
-
config: options?.config,
|
|
85
|
-
masks: options?.masks,
|
|
86
|
-
message,
|
|
87
|
-
logger: false,
|
|
88
|
-
stack: options?.stack,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=logger-abstract.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger-abstract.service.js","sourceRoot":"","sources":["logger-abstract.service.ts"],"names":[],"mappings":";;;AA0LA,sCAuBC;AA/MD,qDAAgD;AAGhD,0EAG6C;AAuDhC,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAiBrD,MAAsB,qBACpB,SAAQ,IAAA,mCAAgB,GAAwB;IAYhD,YACY,OAAe,EACf,SAAiC,EACjC,OAAqC,EACrC,UAAkC,EAAE;QAE9C,KAAK,EAAE,CAAC;QALE,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAwB;QACjC,YAAO,GAAP,OAAO,CAA8B;QACrC,YAAO,GAAP,OAAO,CAA6B;QAbhC,4BAAuB,GAAG,IAAI,CAAC;QAiB7C,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,YAAY,CAAC,MAAkB;QAC7B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;QACxB,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,gBAAgB;QACd,MAAM,aAAa,GAA+B,EAAE,CAAC;QACrD,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAChC,IAAI,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,6BAAY,CAAC;gBACxC,MAAM,IAAI,KAAK,CAAC,wBAAwB,KAAK,oBAAoB,CAAC,CAAC;YAErE,aAAa,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,GAAG,CAAC,OAAY,EAAE,UAA4B,EAAE,EAAE,EAAE;YAC1D,KAAK,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC1C,CAAC,aAAa,CAAC,6BAAY,CAAC,GAAG,CAAC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C,IAAI,KAAK,CAAC;IACxE,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAC,yBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC;IACtE,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,gBAAgB,CAAC;IAEpD,IAAI,CAAC,SAAS;QAAE,OAAO;IAEvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC;IACjE,KAAK,CAAC,SAAS,EAAE;QACf,KAAK,EAAE,EAAE,OAAO,EAAE;QAClB,IAAI,EAAE,OAAO,EAAE,IAAI;QACnB,MAAM,EAAE,OAAO,EAAE,MAAM;QACvB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,OAAO;QACP,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,OAAO,EAAE,KAAK;KACtB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import { LoggerService, LogLevel } from '@nestjs/common';
|
|
3
|
-
import { LogLevelEnum } from './logger.enum.js';
|
|
4
|
-
import { type EventEmitter2 } from '@nestjs/event-emitter';
|
|
5
|
-
// Removed event import to break circular dependency
|
|
6
|
-
import {
|
|
7
|
-
PluginSystem,
|
|
8
|
-
WithPluginSystem,
|
|
9
|
-
} from '@nest-yalc-2/utils/plugin.helper.js';
|
|
10
|
-
import { YalcGlobalClsService } from '../../app/src/cls.module.js';
|
|
11
|
-
|
|
12
|
-
export interface LogMethodOptions {
|
|
13
|
-
message?: any;
|
|
14
|
-
/**
|
|
15
|
-
* The data is the place where you want to add the extra information
|
|
16
|
-
* that are not returned back as a response but they can be sent to the logger or the event emitter.
|
|
17
|
-
*/
|
|
18
|
-
data?: any;
|
|
19
|
-
/**
|
|
20
|
-
* This can be used to log the configuration values of the event.
|
|
21
|
-
* This might be helpful to filter the logs based on extra configuration values
|
|
22
|
-
* that are not the basic error level, statusCode etc.
|
|
23
|
-
*/
|
|
24
|
-
config?: any;
|
|
25
|
-
masks?: string[];
|
|
26
|
-
context?: string;
|
|
27
|
-
stack?: string;
|
|
28
|
-
/**
|
|
29
|
-
* If false, it will not trigger an event.
|
|
30
|
-
* If string, it will trigger an event with the string as the event name instead of the default event name.
|
|
31
|
-
*/
|
|
32
|
-
event?: string | false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type LogMethod = (message: any, options?: LogMethodOptions) => void;
|
|
36
|
-
export type LogMethodError = (
|
|
37
|
-
message: any,
|
|
38
|
-
stack?: string,
|
|
39
|
-
options?: LogMethodOptions,
|
|
40
|
-
) => void;
|
|
41
|
-
|
|
42
|
-
export interface ILoggerPluginMethods<TClsService = any> extends Record<
|
|
43
|
-
string,
|
|
44
|
-
{ (...args: any[]): void } | undefined
|
|
45
|
-
> {
|
|
46
|
-
onBeforeLogging?: (
|
|
47
|
-
message: any,
|
|
48
|
-
options: LogMethodOptions,
|
|
49
|
-
clsService: TClsService,
|
|
50
|
-
) => void;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface ImprovedLoggerService
|
|
54
|
-
extends ImprovedLoggerServiceMethods, PluginSystem<ILoggerPluginMethods> {}
|
|
55
|
-
|
|
56
|
-
export interface ImprovedLoggerServiceMethods extends LoggerService {
|
|
57
|
-
log: LogMethod;
|
|
58
|
-
error: LogMethodError;
|
|
59
|
-
warn: LogMethod;
|
|
60
|
-
debug?: LogMethod | undefined;
|
|
61
|
-
verbose?: LogMethod;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const EVENT_LOG_DEFAULT = 'EVENT_LOG_DEFAULT';
|
|
65
|
-
|
|
66
|
-
export interface IImprovedLoggerOptions {
|
|
67
|
-
event?:
|
|
68
|
-
| {
|
|
69
|
-
eventEmitter?: EventEmitter2 | false;
|
|
70
|
-
/**
|
|
71
|
-
* if set to true, it trigger an event with the name of EVENT_LOG_DEFAULT even
|
|
72
|
-
* if we didn't specified the event name
|
|
73
|
-
*/
|
|
74
|
-
useFallbackEvent?: boolean;
|
|
75
|
-
}
|
|
76
|
-
| false;
|
|
77
|
-
clsService?: YalcGlobalClsService;
|
|
78
|
-
overrideLoggerLevels?: LogLevel[];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export abstract class LoggerAbstractService
|
|
82
|
-
extends WithPluginSystem<ILoggerPluginMethods>()
|
|
83
|
-
implements ImprovedLoggerService
|
|
84
|
-
{
|
|
85
|
-
public readonly isImprovedLoggerService = true;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* This constructor override its empty method based on passed
|
|
89
|
-
* logLevels and this.methods
|
|
90
|
-
*
|
|
91
|
-
* @param logLevels
|
|
92
|
-
* @param this.methods
|
|
93
|
-
*/
|
|
94
|
-
constructor(
|
|
95
|
-
protected context: string,
|
|
96
|
-
protected logLevels: LogLevel[] | undefined,
|
|
97
|
-
protected methods: ImprovedLoggerServiceMethods,
|
|
98
|
-
protected options: IImprovedLoggerOptions = {},
|
|
99
|
-
) {
|
|
100
|
-
super();
|
|
101
|
-
|
|
102
|
-
this.initializeLogger();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
setLogLevels(levels: LogLevel[]) {
|
|
106
|
-
this.logLevels = levels;
|
|
107
|
-
this.initializeLogger();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
initializeLogger() {
|
|
111
|
-
const enabledLevels: { [key: string]: boolean } = {};
|
|
112
|
-
this.logLevels?.forEach((level) => {
|
|
113
|
-
if (!(level.toUpperCase() in LogLevelEnum))
|
|
114
|
-
throw new Error(`ERROR: Logger Level: ${level} is not supported!`);
|
|
115
|
-
|
|
116
|
-
enabledLevels[level] = true;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
this.log = (message: any, options: LogMethodOptions = {}) => {
|
|
120
|
-
void this.beforeLogging(message, options);
|
|
121
|
-
(enabledLevels[LogLevelEnum.LOG] === true &&
|
|
122
|
-
this.methods[LogLevelEnum.LOG]
|
|
123
|
-
? this.methods[LogLevelEnum.LOG]
|
|
124
|
-
: () => {})(message, options);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
this.error = (
|
|
128
|
-
message: any,
|
|
129
|
-
stack?: string,
|
|
130
|
-
options: LogMethodOptions = {},
|
|
131
|
-
) => {
|
|
132
|
-
options.stack = stack;
|
|
133
|
-
void this.beforeLogging(message, options);
|
|
134
|
-
|
|
135
|
-
(enabledLevels[LogLevelEnum.ERROR] === true &&
|
|
136
|
-
this.methods[LogLevelEnum.ERROR]
|
|
137
|
-
? this.methods[LogLevelEnum.ERROR]
|
|
138
|
-
: () => {})(message, stack, options);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
this.warn = (message: any, options: LogMethodOptions = {}) => {
|
|
142
|
-
void this.beforeLogging(message, options);
|
|
143
|
-
|
|
144
|
-
(enabledLevels[LogLevelEnum.WARN] === true &&
|
|
145
|
-
this.methods[LogLevelEnum.WARN]
|
|
146
|
-
? this.methods[LogLevelEnum.WARN]
|
|
147
|
-
: () => {})(message, options);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
enabledLevels[LogLevelEnum.DEBUG] === true &&
|
|
152
|
-
this.methods[LogLevelEnum.DEBUG]
|
|
153
|
-
)
|
|
154
|
-
this.debug = (message: any, options: LogMethodOptions = {}) => {
|
|
155
|
-
void this.beforeLogging(message, options);
|
|
156
|
-
this.methods[LogLevelEnum.DEBUG]!(message, options);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
enabledLevels[LogLevelEnum.VERBOSE] === true &&
|
|
161
|
-
this.methods[LogLevelEnum.VERBOSE]
|
|
162
|
-
)
|
|
163
|
-
this.verbose = (message: any, options: LogMethodOptions = {}) => {
|
|
164
|
-
void this.beforeLogging(message, options);
|
|
165
|
-
this.methods[LogLevelEnum.VERBOSE]!(message, options);
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
log!: LogMethod;
|
|
170
|
-
error!: LogMethodError;
|
|
171
|
-
warn!: LogMethod;
|
|
172
|
-
debug?: LogMethod | undefined;
|
|
173
|
-
verbose?: LogMethod;
|
|
174
|
-
|
|
175
|
-
beforeLogging(message: any, options: LogMethodOptions) {
|
|
176
|
-
this.options.event = this.options.event ?? {};
|
|
177
|
-
this.invokePlugins(
|
|
178
|
-
'onBeforeLogging',
|
|
179
|
-
message,
|
|
180
|
-
options,
|
|
181
|
-
this.options.clsService,
|
|
182
|
-
);
|
|
183
|
-
return beforeLogging(message, options);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function beforeLogging(
|
|
188
|
-
message: any,
|
|
189
|
-
options: LogMethodOptions & IImprovedLoggerOptions['event'] = {},
|
|
190
|
-
) {
|
|
191
|
-
const emitter = options && options.eventEmitter;
|
|
192
|
-
if (!emitter) return;
|
|
193
|
-
|
|
194
|
-
const useFallbackEvent = (options && options.useFallbackEvent) ?? false;
|
|
195
|
-
const defaultEventName = useFallbackEvent ? EVENT_LOG_DEFAULT : false;
|
|
196
|
-
const eventName = options.event ?? defaultEventName;
|
|
197
|
-
|
|
198
|
-
if (!eventName) return;
|
|
199
|
-
|
|
200
|
-
const { event } = require('@nest-yalc-2/event-manager/event.js');
|
|
201
|
-
event(eventName, {
|
|
202
|
-
event: { emitter },
|
|
203
|
-
data: options?.data,
|
|
204
|
-
config: options?.config,
|
|
205
|
-
masks: options?.masks,
|
|
206
|
-
message,
|
|
207
|
-
logger: false,
|
|
208
|
-
stack: options?.stack,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { LogLevel } from '@nestjs/common';
|
|
2
|
-
import { IImprovedLoggerOptions, LoggerAbstractService } from './logger-abstract.service.js';
|
|
3
|
-
export declare class ConsoleLogger extends LoggerAbstractService {
|
|
4
|
-
constructor(context: string, logLevels: LogLevel[] | undefined, options?: IImprovedLoggerOptions);
|
|
5
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConsoleLogger = void 0;
|
|
4
|
-
const logger_abstract_service_js_1 = require("./logger-abstract.service.js");
|
|
5
|
-
const logger_helper_js_1 = require("./logger.helper.js");
|
|
6
|
-
const logOnlyDefined = (...args) => {
|
|
7
|
-
return args.filter(function (element) {
|
|
8
|
-
return element !== undefined;
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
class ConsoleLogger extends logger_abstract_service_js_1.LoggerAbstractService {
|
|
12
|
-
constructor(context, logLevels, options = {}) {
|
|
13
|
-
super(context, logLevels, {
|
|
14
|
-
log: (message, options, ...rest) => console.log(...logOnlyDefined(`[${options?.context ?? context}]`, message, (0, logger_helper_js_1.maskDataInObject)(options?.data, options?.masks, options?.stack), options?.config, ...rest)),
|
|
15
|
-
error: (message, trace, options, ...rest) => console.error(...logOnlyDefined(`[${options?.context ?? context}]`, message, trace, (0, logger_helper_js_1.maskDataInObject)(options?.data, options?.masks), options?.config, ...rest)),
|
|
16
|
-
debug: (message, options, ...rest) => console.debug(...logOnlyDefined(`[${options?.context ?? context}]`, message, (0, logger_helper_js_1.maskDataInObject)(options?.data, options?.masks, options?.stack), options?.config, ...rest)),
|
|
17
|
-
warn: (message, options, ...rest) => console.warn(...logOnlyDefined(`[${options?.context ?? context}]`, message, (0, logger_helper_js_1.maskDataInObject)(options?.data, options?.masks, options?.stack), options?.config, ...rest)),
|
|
18
|
-
verbose: (message, options, ...rest) => console.info(...logOnlyDefined(`[${options?.context ?? context}]`, message, (0, logger_helper_js_1.maskDataInObject)(options?.data, options?.masks, options?.stack), options?.config, ...rest)),
|
|
19
|
-
}, options);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.ConsoleLogger = ConsoleLogger;
|
|
23
|
-
//# sourceMappingURL=logger-console.service.js.map
|