@innei/pretty-logger-core 0.3.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.
@@ -0,0 +1,190 @@
1
+ import EventEmitter from 'events';
2
+
3
+ interface ConsolaOptions {
4
+ reporters: ConsolaReporter[];
5
+ types: Record<LogType, InputLogObject>;
6
+ level: LogLevel;
7
+ defaults: InputLogObject;
8
+ throttle: number;
9
+ throttleMin: number;
10
+ stdout?: NodeJS.WriteStream;
11
+ stderr?: NodeJS.WriteStream;
12
+ mockFn?: (type: LogType, defaults: InputLogObject) => (...args: any) => void;
13
+ formatOptions: FormatOptions;
14
+ }
15
+ /**
16
+ * @see https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
17
+ */
18
+ interface FormatOptions {
19
+ columns?: number;
20
+ date?: boolean;
21
+ colors?: boolean;
22
+ compact?: boolean | number;
23
+ [key: string]: unknown;
24
+ }
25
+ interface InputLogObject {
26
+ level?: LogLevel;
27
+ tag?: string;
28
+ type?: LogType;
29
+ message?: string;
30
+ additional?: string | string[];
31
+ args?: any[];
32
+ date?: Date;
33
+ }
34
+ interface LogObject extends InputLogObject {
35
+ level: LogLevel;
36
+ type: LogType;
37
+ tag: string;
38
+ args: any[];
39
+ date: Date;
40
+ [key: string]: unknown;
41
+ }
42
+ interface ConsolaReporter {
43
+ log: (logObj: LogObject, ctx: {
44
+ options: ConsolaOptions;
45
+ }) => void;
46
+ }
47
+ interface WrappedConsola extends ConsolaInstance {
48
+ onData: (handler: (data: string) => any) => WrappedConsola;
49
+ onStdOut: (handler: (data: string) => any) => WrappedConsola;
50
+ onStdErr: (handler: (data: string) => any) => WrappedConsola;
51
+ }
52
+
53
+ type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});
54
+ declare const LogLevels: Record<LogType, number>;
55
+ type LogType = 'silent' | 'fatal' | 'error' | 'warn' | 'log' | 'info' | 'success' | 'fail' | 'ready' | 'start' | 'box' | 'debug' | 'trace' | 'verbose';
56
+ declare const LogTypes: Record<LogType, Partial<LogObject>>;
57
+
58
+ declare class Consola {
59
+ options: ConsolaOptions;
60
+ _lastLog: {
61
+ serialized?: string;
62
+ object?: LogObject;
63
+ count?: number;
64
+ time?: Date;
65
+ timeout?: ReturnType<typeof setTimeout>;
66
+ };
67
+ _mockFn?: ConsolaOptions['mockFn'];
68
+ constructor(options?: Partial<ConsolaOptions>);
69
+ get level(): LogLevel;
70
+ set level(level: LogLevel);
71
+ create(options: Partial<ConsolaOptions>): ConsolaInstance;
72
+ withDefaults(defaults: InputLogObject): ConsolaInstance;
73
+ withTag(tag: string): ConsolaInstance;
74
+ addReporter(reporter: ConsolaReporter): this;
75
+ removeReporter(reporter: ConsolaReporter): ConsolaReporter[] | this;
76
+ setReporters(reporters: ConsolaReporter[]): this;
77
+ wrapAll(): void;
78
+ restoreAll(): void;
79
+ wrapConsole(): void;
80
+ restoreConsole(): void;
81
+ wrapStd(): void;
82
+ _wrapStream(stream: NodeJS.WriteStream | undefined, type: LogType): void;
83
+ restoreStd(): void;
84
+ _restoreStream(stream?: NodeJS.WriteStream): void;
85
+ pauseLogs(): void;
86
+ resumeLogs(): void;
87
+ mockTypes(mockFn?: ConsolaOptions['mockFn']): void;
88
+ _wrapLogFn(defaults: InputLogObject, isRaw?: boolean): (...args: any[]) => false | undefined;
89
+ _logFn(defaults: InputLogObject, args: any[], isRaw?: boolean): false | undefined;
90
+ _log(logObj: LogObject): void;
91
+ }
92
+ interface LogFn {
93
+ (message: InputLogObject | any, ...args: any[]): void;
94
+ raw: (...args: any[]) => void;
95
+ }
96
+ type ConsolaInstance = Consola & Record<LogType, LogFn>;
97
+
98
+ declare function createConsola(options?: Partial<ConsolaOptions & {
99
+ fancy: boolean;
100
+ }>): ConsolaInstance;
101
+ declare const consola: ConsolaInstance;
102
+
103
+ declare class BasicReporter implements ConsolaReporter {
104
+ formatStack(stack: string, opts: FormatOptions): string;
105
+ formatArgs(args: any[], opts: FormatOptions): string;
106
+ formatDate(date: Date, opts: FormatOptions): string;
107
+ filterAndJoin(arr: any[]): string;
108
+ formatLogObj(logObj: LogObject, opts: FormatOptions): string;
109
+ log(logObj: LogObject, ctx: {
110
+ options: ConsolaOptions;
111
+ }): any;
112
+ }
113
+
114
+ declare const TYPE_COLOR_MAP: {
115
+ [k in LogType]?: string;
116
+ };
117
+ declare const LEVEL_COLOR_MAP: {
118
+ [k in LogLevel]?: string;
119
+ };
120
+ declare class FancyReporter extends BasicReporter {
121
+ formatStack(stack: string): string;
122
+ formatType(logObj: LogObject, isBadge: boolean, opts: FormatOptions): any;
123
+ formatLogObj(logObj: LogObject, opts: FormatOptions): string;
124
+ }
125
+
126
+ declare class LoggerReporter extends FancyReporter {
127
+ private latestLogTime;
128
+ formatDate(date: Date, opts: FormatOptions): string;
129
+ formatLogObj(logObj: LogObject, opts: FormatOptions): string;
130
+ }
131
+
132
+ interface FileReporterConfig {
133
+ loggerDir: string;
134
+ /**
135
+ * @default 'stdout_%d%.log'
136
+ */
137
+ stdoutFileFormat?: string;
138
+ /**
139
+ * @default 'error.log'
140
+ */
141
+ stderrFileFormat?: string;
142
+ /**
143
+ * refresh logger file stream
144
+ * @default '0 0 * * *'
145
+ */
146
+ cron?: string;
147
+ /**
148
+ * Error log will be written to stdout and stderr
149
+ * @default false
150
+ */
151
+ errWriteToStdout?: boolean;
152
+ }
153
+ declare class FileReporter extends LoggerReporter {
154
+ private readonly configs;
155
+ constructor(configs: FileReporterConfig);
156
+ private stdoutStream?;
157
+ private stderrStream?;
158
+ private __job?;
159
+ private scheduleRefreshWriteStream;
160
+ teardown(): void;
161
+ private refreshWriteStream;
162
+ log(logObj: LogObject, ctx: {
163
+ options: ConsolaOptions;
164
+ }): any;
165
+ }
166
+
167
+ interface LoggerConsolaOptions extends Partial<ConsolaOptions> {
168
+ writeToFile?: FileReporterConfig;
169
+ }
170
+ declare const createLoggerConsola: (options?: LoggerConsolaOptions) => WrappedConsola;
171
+
172
+ declare class BrowserReporter {
173
+ options: any;
174
+ defaultColor: string;
175
+ levelColorMap: Record<number, string>;
176
+ typeColorMap: Record<string, string>;
177
+ constructor(options: any);
178
+ _getLogFn(level: number): any;
179
+ log(logObj: LogObject): void;
180
+ }
181
+
182
+ declare const wrapperSubscribers: (consola: ConsolaInstance) => WrappedConsola;
183
+ declare class SubscriberReporter extends LoggerReporter {
184
+ static subscriber: EventEmitter;
185
+ log(logObj: LogObject, ctx: {
186
+ options: ConsolaOptions;
187
+ }): void;
188
+ }
189
+
190
+ export { BasicReporter, BrowserReporter, Consola, type ConsolaInstance, type ConsolaOptions, type ConsolaReporter, FancyReporter, FileReporter, type FileReporterConfig, type FormatOptions, type InputLogObject, LEVEL_COLOR_MAP, type LogLevel, LogLevels, type LogObject, type LogType, LogTypes, type LoggerConsolaOptions, LoggerReporter, SubscriberReporter, TYPE_COLOR_MAP, type WrappedConsola, consola, createConsola, createLoggerConsola, wrapperSubscribers };
@@ -0,0 +1,190 @@
1
+ import EventEmitter from 'events';
2
+
3
+ interface ConsolaOptions {
4
+ reporters: ConsolaReporter[];
5
+ types: Record<LogType, InputLogObject>;
6
+ level: LogLevel;
7
+ defaults: InputLogObject;
8
+ throttle: number;
9
+ throttleMin: number;
10
+ stdout?: NodeJS.WriteStream;
11
+ stderr?: NodeJS.WriteStream;
12
+ mockFn?: (type: LogType, defaults: InputLogObject) => (...args: any) => void;
13
+ formatOptions: FormatOptions;
14
+ }
15
+ /**
16
+ * @see https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
17
+ */
18
+ interface FormatOptions {
19
+ columns?: number;
20
+ date?: boolean;
21
+ colors?: boolean;
22
+ compact?: boolean | number;
23
+ [key: string]: unknown;
24
+ }
25
+ interface InputLogObject {
26
+ level?: LogLevel;
27
+ tag?: string;
28
+ type?: LogType;
29
+ message?: string;
30
+ additional?: string | string[];
31
+ args?: any[];
32
+ date?: Date;
33
+ }
34
+ interface LogObject extends InputLogObject {
35
+ level: LogLevel;
36
+ type: LogType;
37
+ tag: string;
38
+ args: any[];
39
+ date: Date;
40
+ [key: string]: unknown;
41
+ }
42
+ interface ConsolaReporter {
43
+ log: (logObj: LogObject, ctx: {
44
+ options: ConsolaOptions;
45
+ }) => void;
46
+ }
47
+ interface WrappedConsola extends ConsolaInstance {
48
+ onData: (handler: (data: string) => any) => WrappedConsola;
49
+ onStdOut: (handler: (data: string) => any) => WrappedConsola;
50
+ onStdErr: (handler: (data: string) => any) => WrappedConsola;
51
+ }
52
+
53
+ type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});
54
+ declare const LogLevels: Record<LogType, number>;
55
+ type LogType = 'silent' | 'fatal' | 'error' | 'warn' | 'log' | 'info' | 'success' | 'fail' | 'ready' | 'start' | 'box' | 'debug' | 'trace' | 'verbose';
56
+ declare const LogTypes: Record<LogType, Partial<LogObject>>;
57
+
58
+ declare class Consola {
59
+ options: ConsolaOptions;
60
+ _lastLog: {
61
+ serialized?: string;
62
+ object?: LogObject;
63
+ count?: number;
64
+ time?: Date;
65
+ timeout?: ReturnType<typeof setTimeout>;
66
+ };
67
+ _mockFn?: ConsolaOptions['mockFn'];
68
+ constructor(options?: Partial<ConsolaOptions>);
69
+ get level(): LogLevel;
70
+ set level(level: LogLevel);
71
+ create(options: Partial<ConsolaOptions>): ConsolaInstance;
72
+ withDefaults(defaults: InputLogObject): ConsolaInstance;
73
+ withTag(tag: string): ConsolaInstance;
74
+ addReporter(reporter: ConsolaReporter): this;
75
+ removeReporter(reporter: ConsolaReporter): ConsolaReporter[] | this;
76
+ setReporters(reporters: ConsolaReporter[]): this;
77
+ wrapAll(): void;
78
+ restoreAll(): void;
79
+ wrapConsole(): void;
80
+ restoreConsole(): void;
81
+ wrapStd(): void;
82
+ _wrapStream(stream: NodeJS.WriteStream | undefined, type: LogType): void;
83
+ restoreStd(): void;
84
+ _restoreStream(stream?: NodeJS.WriteStream): void;
85
+ pauseLogs(): void;
86
+ resumeLogs(): void;
87
+ mockTypes(mockFn?: ConsolaOptions['mockFn']): void;
88
+ _wrapLogFn(defaults: InputLogObject, isRaw?: boolean): (...args: any[]) => false | undefined;
89
+ _logFn(defaults: InputLogObject, args: any[], isRaw?: boolean): false | undefined;
90
+ _log(logObj: LogObject): void;
91
+ }
92
+ interface LogFn {
93
+ (message: InputLogObject | any, ...args: any[]): void;
94
+ raw: (...args: any[]) => void;
95
+ }
96
+ type ConsolaInstance = Consola & Record<LogType, LogFn>;
97
+
98
+ declare function createConsola(options?: Partial<ConsolaOptions & {
99
+ fancy: boolean;
100
+ }>): ConsolaInstance;
101
+ declare const consola: ConsolaInstance;
102
+
103
+ declare class BasicReporter implements ConsolaReporter {
104
+ formatStack(stack: string, opts: FormatOptions): string;
105
+ formatArgs(args: any[], opts: FormatOptions): string;
106
+ formatDate(date: Date, opts: FormatOptions): string;
107
+ filterAndJoin(arr: any[]): string;
108
+ formatLogObj(logObj: LogObject, opts: FormatOptions): string;
109
+ log(logObj: LogObject, ctx: {
110
+ options: ConsolaOptions;
111
+ }): any;
112
+ }
113
+
114
+ declare const TYPE_COLOR_MAP: {
115
+ [k in LogType]?: string;
116
+ };
117
+ declare const LEVEL_COLOR_MAP: {
118
+ [k in LogLevel]?: string;
119
+ };
120
+ declare class FancyReporter extends BasicReporter {
121
+ formatStack(stack: string): string;
122
+ formatType(logObj: LogObject, isBadge: boolean, opts: FormatOptions): any;
123
+ formatLogObj(logObj: LogObject, opts: FormatOptions): string;
124
+ }
125
+
126
+ declare class LoggerReporter extends FancyReporter {
127
+ private latestLogTime;
128
+ formatDate(date: Date, opts: FormatOptions): string;
129
+ formatLogObj(logObj: LogObject, opts: FormatOptions): string;
130
+ }
131
+
132
+ interface FileReporterConfig {
133
+ loggerDir: string;
134
+ /**
135
+ * @default 'stdout_%d%.log'
136
+ */
137
+ stdoutFileFormat?: string;
138
+ /**
139
+ * @default 'error.log'
140
+ */
141
+ stderrFileFormat?: string;
142
+ /**
143
+ * refresh logger file stream
144
+ * @default '0 0 * * *'
145
+ */
146
+ cron?: string;
147
+ /**
148
+ * Error log will be written to stdout and stderr
149
+ * @default false
150
+ */
151
+ errWriteToStdout?: boolean;
152
+ }
153
+ declare class FileReporter extends LoggerReporter {
154
+ private readonly configs;
155
+ constructor(configs: FileReporterConfig);
156
+ private stdoutStream?;
157
+ private stderrStream?;
158
+ private __job?;
159
+ private scheduleRefreshWriteStream;
160
+ teardown(): void;
161
+ private refreshWriteStream;
162
+ log(logObj: LogObject, ctx: {
163
+ options: ConsolaOptions;
164
+ }): any;
165
+ }
166
+
167
+ interface LoggerConsolaOptions extends Partial<ConsolaOptions> {
168
+ writeToFile?: FileReporterConfig;
169
+ }
170
+ declare const createLoggerConsola: (options?: LoggerConsolaOptions) => WrappedConsola;
171
+
172
+ declare class BrowserReporter {
173
+ options: any;
174
+ defaultColor: string;
175
+ levelColorMap: Record<number, string>;
176
+ typeColorMap: Record<string, string>;
177
+ constructor(options: any);
178
+ _getLogFn(level: number): any;
179
+ log(logObj: LogObject): void;
180
+ }
181
+
182
+ declare const wrapperSubscribers: (consola: ConsolaInstance) => WrappedConsola;
183
+ declare class SubscriberReporter extends LoggerReporter {
184
+ static subscriber: EventEmitter;
185
+ log(logObj: LogObject, ctx: {
186
+ options: ConsolaOptions;
187
+ }): void;
188
+ }
189
+
190
+ export { BasicReporter, BrowserReporter, Consola, type ConsolaInstance, type ConsolaOptions, type ConsolaReporter, FancyReporter, FileReporter, type FileReporterConfig, type FormatOptions, type InputLogObject, LEVEL_COLOR_MAP, type LogLevel, LogLevels, type LogObject, type LogType, LogTypes, type LoggerConsolaOptions, LoggerReporter, SubscriberReporter, TYPE_COLOR_MAP, type WrappedConsola, consola, createConsola, createLoggerConsola, wrapperSubscribers };