standard-log 12.0.3 → 12.0.4
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/cjs/types.d.ts +50 -1
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/esm/types.d.ts +50 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +2 -2
- package/ts/types.ts +50 -1
package/cjs/types.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import type { StackTraceMeta } from '@just-func/types';
|
|
2
2
|
export type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
|
|
3
|
+
/**
|
|
4
|
+
* A map of custom log levels.
|
|
5
|
+
*
|
|
6
|
+
* Each logger created will have a method for each custom level.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createStandardLog } from 'standard-log'
|
|
10
|
+
*
|
|
11
|
+
* const sl = createStandardLog({ customLevels: { foo: 100 } })
|
|
12
|
+
* const logger = sl.getLogger('my-logger')
|
|
13
|
+
*
|
|
14
|
+
* logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
3
17
|
customLevels?: Record<CustomLevelNames, number>;
|
|
4
18
|
logLevel?: number;
|
|
5
19
|
reporters?: LogReporter[];
|
|
@@ -41,10 +55,45 @@ export type LogMethod = (...args: any[]) => void;
|
|
|
41
55
|
export type LogFunction = (log: LogMethod, logLevel: number) => string | void;
|
|
42
56
|
export type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
|
|
43
57
|
export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
58
|
+
/**
|
|
59
|
+
* The current log level.
|
|
60
|
+
*/
|
|
44
61
|
logLevel: number;
|
|
62
|
+
/**
|
|
63
|
+
* Convert log level number to log level name.
|
|
64
|
+
*/
|
|
45
65
|
toLogLevelName(level: number): string;
|
|
66
|
+
/**
|
|
67
|
+
* Convert log level name to log level number.
|
|
68
|
+
*/
|
|
46
69
|
toLogLevel(name: N): number;
|
|
70
|
+
/**
|
|
71
|
+
* Get a logger instance with the specified id.
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { createStandardLog } from 'standard-log'
|
|
75
|
+
*
|
|
76
|
+
* const sl = createStandardLog()
|
|
77
|
+
* const logger = sl.getLogger('my-logger')
|
|
78
|
+
*
|
|
79
|
+
* logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
47
82
|
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
83
|
+
/**
|
|
84
|
+
* Get a non-console logger instance with the specified id.
|
|
85
|
+
*
|
|
86
|
+
* The resulting logger will only write to the reporters that are not console reporters.
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { createStandardLog } from 'standard-log'
|
|
90
|
+
*
|
|
91
|
+
* const sl = createStandardLog({ reporter: [createConsoleReporter(), createRemoteReporter(...)] })
|
|
92
|
+
* const logger = sl.getNonConsoleLogger('my-logger')
|
|
93
|
+
*
|
|
94
|
+
* logger.info('Hello world!') // will only write to remote reporter
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
48
97
|
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
49
98
|
}
|
|
50
99
|
/**
|
|
@@ -73,7 +122,7 @@ export interface LogReporter<T = any> {
|
|
|
73
122
|
*/
|
|
74
123
|
readonly filter?: LogFilter;
|
|
75
124
|
/**
|
|
76
|
-
*
|
|
125
|
+
* Indicates if this is a console reporter.
|
|
77
126
|
* There is only one console reporter can be present in the system.
|
|
78
127
|
*/
|
|
79
128
|
readonly isConsoleReporter?: boolean;
|
package/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"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AAM,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAE7B,MAAM,WAAW,WAAW;IAC3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAC3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAC1B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAC1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;CAC3B"}
|
package/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {\n\tcustomLevels?: Record<CustomLevelNames, number>\n\tlogLevel?: number\n\treporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n\tlevel?: number\n\twriteTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<N extends string = LogMethodNames> = {\n\treadonly id: string\n\t/**\n\t * Logger local log level.\n\t */\n\tlevel?: number\n\t/**\n\t * Logs with an increment counter.\n\t * This is useful during debugging to check for steps executed.\n\t */\n\tcount(...args: any[]): void\n\ton(level: number | N, logFunction: LogFunction): void\n\t/**\n\t * Write custom log entries.\n\t */\n\twrite(entry: LogEntry): void\n} & { [k in N]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames =\n\t| 'emergency'\n\t| 'alert'\n\t| 'critical'\n\t| 'error'\n\t| 'warn'\n\t| 'notice'\n\t| 'info'\n\t| 'debug'\n\t| 'trace'\n\t| 'planck'\n\nexport type LogEntry = {\n\tid: string\n\tlevel: number\n\t// args instead of messages because it is `any[]` instead of `string[]`\n\targs: any[]\n\ttimestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = (log: LogMethod, logLevel: number) => string | void\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n\tlogLevel: number\n\ttoLogLevelName(level: number): string\n\ttoLogLevel(name: N): number\n\tgetLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n\tgetNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string; level: number }\n\nexport interface LogReporter<T = any> {\n\treadonly id: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\treadonly formatter: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\treadonly filter?: LogFilter\n\t/**\n\t *
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {\n\t/**\n\t * A map of custom log levels.\n\t *\n\t * Each logger created will have a method for each custom level.\n\t *\n\t * ```ts\n\t * import { createStandardLog } from 'standard-log'\n\t *\n\t * const sl = createStandardLog({ customLevels: { foo: 100 } })\n\t * const logger = sl.getLogger('my-logger')\n\t *\n\t * logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!\n\t * ```\n\t */\n\tcustomLevels?: Record<CustomLevelNames, number>\n\tlogLevel?: number\n\treporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n\tlevel?: number\n\twriteTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<N extends string = LogMethodNames> = {\n\treadonly id: string\n\t/**\n\t * Logger local log level.\n\t */\n\tlevel?: number\n\t/**\n\t * Logs with an increment counter.\n\t * This is useful during debugging to check for steps executed.\n\t */\n\tcount(...args: any[]): void\n\ton(level: number | N, logFunction: LogFunction): void\n\t/**\n\t * Write custom log entries.\n\t */\n\twrite(entry: LogEntry): void\n} & { [k in N]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames =\n\t| 'emergency'\n\t| 'alert'\n\t| 'critical'\n\t| 'error'\n\t| 'warn'\n\t| 'notice'\n\t| 'info'\n\t| 'debug'\n\t| 'trace'\n\t| 'planck'\n\nexport type LogEntry = {\n\tid: string\n\tlevel: number\n\t// args instead of messages because it is `any[]` instead of `string[]`\n\targs: any[]\n\ttimestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = (log: LogMethod, logLevel: number) => string | void\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n\t/**\n\t * The current log level.\n\t */\n\tlogLevel: number\n\t/**\n\t * Convert log level number to log level name.\n\t */\n\ttoLogLevelName(level: number): string\n\t/**\n\t * Convert log level name to log level number.\n\t */\n\ttoLogLevel(name: N): number\n\t/**\n\t * Get a logger instance with the specified id.\n\t *\n\t * ```ts\n\t * import { createStandardLog } from 'standard-log'\n\t *\n\t * const sl = createStandardLog()\n\t * const logger = sl.getLogger('my-logger')\n\t *\n\t * logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!\n\t * ```\n\t */\n\tgetLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n\t/**\n\t * Get a non-console logger instance with the specified id.\n\t *\n\t * The resulting logger will only write to the reporters that are not console reporters.\n\t *\n\t * ```ts\n\t * import { createStandardLog } from 'standard-log'\n\t *\n\t * const sl = createStandardLog({ reporter: [createConsoleReporter(), createRemoteReporter(...)] })\n\t * const logger = sl.getNonConsoleLogger('my-logger')\n\t *\n\t * logger.info('Hello world!') // will only write to remote reporter\n\t * ```\n\t */\n\tgetNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string; level: number }\n\nexport interface LogReporter<T = any> {\n\treadonly id: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\treadonly formatter: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\treadonly filter?: LogFilter\n\t/**\n\t * Indicates if this is a console reporter.\n\t * There is only one console reporter can be present in the system.\n\t */\n\treadonly isConsoleReporter?: boolean\n\twrite(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n\tid?: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\tformatter?: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\tfilter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n\tdebug(...args: any[]): void\n\tinfo(...args: any[]): void\n\twarn(...args: any[]): void\n\terror(...args: any[]): void\n}\n"]}
|
package/esm/types.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import type { StackTraceMeta } from '@just-func/types';
|
|
2
2
|
export type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
|
|
3
|
+
/**
|
|
4
|
+
* A map of custom log levels.
|
|
5
|
+
*
|
|
6
|
+
* Each logger created will have a method for each custom level.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createStandardLog } from 'standard-log'
|
|
10
|
+
*
|
|
11
|
+
* const sl = createStandardLog({ customLevels: { foo: 100 } })
|
|
12
|
+
* const logger = sl.getLogger('my-logger')
|
|
13
|
+
*
|
|
14
|
+
* logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
3
17
|
customLevels?: Record<CustomLevelNames, number>;
|
|
4
18
|
logLevel?: number;
|
|
5
19
|
reporters?: LogReporter[];
|
|
@@ -41,10 +55,45 @@ export type LogMethod = (...args: any[]) => void;
|
|
|
41
55
|
export type LogFunction = (log: LogMethod, logLevel: number) => string | void;
|
|
42
56
|
export type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
|
|
43
57
|
export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
58
|
+
/**
|
|
59
|
+
* The current log level.
|
|
60
|
+
*/
|
|
44
61
|
logLevel: number;
|
|
62
|
+
/**
|
|
63
|
+
* Convert log level number to log level name.
|
|
64
|
+
*/
|
|
45
65
|
toLogLevelName(level: number): string;
|
|
66
|
+
/**
|
|
67
|
+
* Convert log level name to log level number.
|
|
68
|
+
*/
|
|
46
69
|
toLogLevel(name: N): number;
|
|
70
|
+
/**
|
|
71
|
+
* Get a logger instance with the specified id.
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { createStandardLog } from 'standard-log'
|
|
75
|
+
*
|
|
76
|
+
* const sl = createStandardLog()
|
|
77
|
+
* const logger = sl.getLogger('my-logger')
|
|
78
|
+
*
|
|
79
|
+
* logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
47
82
|
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
83
|
+
/**
|
|
84
|
+
* Get a non-console logger instance with the specified id.
|
|
85
|
+
*
|
|
86
|
+
* The resulting logger will only write to the reporters that are not console reporters.
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { createStandardLog } from 'standard-log'
|
|
90
|
+
*
|
|
91
|
+
* const sl = createStandardLog({ reporter: [createConsoleReporter(), createRemoteReporter(...)] })
|
|
92
|
+
* const logger = sl.getNonConsoleLogger('my-logger')
|
|
93
|
+
*
|
|
94
|
+
* logger.info('Hello world!') // will only write to remote reporter
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
48
97
|
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
49
98
|
}
|
|
50
99
|
/**
|
|
@@ -73,7 +122,7 @@ export interface LogReporter<T = any> {
|
|
|
73
122
|
*/
|
|
74
123
|
readonly filter?: LogFilter;
|
|
75
124
|
/**
|
|
76
|
-
*
|
|
125
|
+
* Indicates if this is a console reporter.
|
|
77
126
|
* There is only one console reporter can be present in the system.
|
|
78
127
|
*/
|
|
79
128
|
readonly isConsoleReporter?: boolean;
|
package/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,MAAM,MAAM,kBAAkB,CAAC,gBAAgB,SAAS,MAAM,GAAG,cAAc,IAAI;IAClF,YAAY,CAAC,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAA;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,WAAW,aAAc,SAAQ,cAAc;IACpD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,WAAW,GAAG,cAAc,CAAA;CACtC;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI;IACvD,QAAQ,CAAC,EAAE,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,SAAS,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAA;AAEpD,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3D,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IACnC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;IACnC;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAA;IAC3B;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IACpC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC5B;AAED,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI;IACzC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX;;;OAGG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAE7B,MAAM,WAAW,WAAW;IAC3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAC3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAC1B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAC1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;CAC3B"}
|
package/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {\n\tcustomLevels?: Record<CustomLevelNames, number>\n\tlogLevel?: number\n\treporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n\tlevel?: number\n\twriteTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<N extends string = LogMethodNames> = {\n\treadonly id: string\n\t/**\n\t * Logger local log level.\n\t */\n\tlevel?: number\n\t/**\n\t * Logs with an increment counter.\n\t * This is useful during debugging to check for steps executed.\n\t */\n\tcount(...args: any[]): void\n\ton(level: number | N, logFunction: LogFunction): void\n\t/**\n\t * Write custom log entries.\n\t */\n\twrite(entry: LogEntry): void\n} & { [k in N]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames =\n\t| 'emergency'\n\t| 'alert'\n\t| 'critical'\n\t| 'error'\n\t| 'warn'\n\t| 'notice'\n\t| 'info'\n\t| 'debug'\n\t| 'trace'\n\t| 'planck'\n\nexport type LogEntry = {\n\tid: string\n\tlevel: number\n\t// args instead of messages because it is `any[]` instead of `string[]`\n\targs: any[]\n\ttimestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = (log: LogMethod, logLevel: number) => string | void\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n\tlogLevel: number\n\ttoLogLevelName(level: number): string\n\ttoLogLevel(name: N): number\n\tgetLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n\tgetNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string; level: number }\n\nexport interface LogReporter<T = any> {\n\treadonly id: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\treadonly formatter: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\treadonly filter?: LogFilter\n\t/**\n\t *
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {\n\t/**\n\t * A map of custom log levels.\n\t *\n\t * Each logger created will have a method for each custom level.\n\t *\n\t * ```ts\n\t * import { createStandardLog } from 'standard-log'\n\t *\n\t * const sl = createStandardLog({ customLevels: { foo: 100 } })\n\t * const logger = sl.getLogger('my-logger')\n\t *\n\t * logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!\n\t * ```\n\t */\n\tcustomLevels?: Record<CustomLevelNames, number>\n\tlogLevel?: number\n\treporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n\tlevel?: number\n\twriteTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<N extends string = LogMethodNames> = {\n\treadonly id: string\n\t/**\n\t * Logger local log level.\n\t */\n\tlevel?: number\n\t/**\n\t * Logs with an increment counter.\n\t * This is useful during debugging to check for steps executed.\n\t */\n\tcount(...args: any[]): void\n\ton(level: number | N, logFunction: LogFunction): void\n\t/**\n\t * Write custom log entries.\n\t */\n\twrite(entry: LogEntry): void\n} & { [k in N]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames =\n\t| 'emergency'\n\t| 'alert'\n\t| 'critical'\n\t| 'error'\n\t| 'warn'\n\t| 'notice'\n\t| 'info'\n\t| 'debug'\n\t| 'trace'\n\t| 'planck'\n\nexport type LogEntry = {\n\tid: string\n\tlevel: number\n\t// args instead of messages because it is `any[]` instead of `string[]`\n\targs: any[]\n\ttimestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = (log: LogMethod, logLevel: number) => string | void\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n\t/**\n\t * The current log level.\n\t */\n\tlogLevel: number\n\t/**\n\t * Convert log level number to log level name.\n\t */\n\ttoLogLevelName(level: number): string\n\t/**\n\t * Convert log level name to log level number.\n\t */\n\ttoLogLevel(name: N): number\n\t/**\n\t * Get a logger instance with the specified id.\n\t *\n\t * ```ts\n\t * import { createStandardLog } from 'standard-log'\n\t *\n\t * const sl = createStandardLog()\n\t * const logger = sl.getLogger('my-logger')\n\t *\n\t * logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!\n\t * ```\n\t */\n\tgetLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n\t/**\n\t * Get a non-console logger instance with the specified id.\n\t *\n\t * The resulting logger will only write to the reporters that are not console reporters.\n\t *\n\t * ```ts\n\t * import { createStandardLog } from 'standard-log'\n\t *\n\t * const sl = createStandardLog({ reporter: [createConsoleReporter(), createRemoteReporter(...)] })\n\t * const logger = sl.getNonConsoleLogger('my-logger')\n\t *\n\t * logger.info('Hello world!') // will only write to remote reporter\n\t * ```\n\t */\n\tgetNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string; level: number }\n\nexport interface LogReporter<T = any> {\n\treadonly id: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\treadonly formatter: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\treadonly filter?: LogFilter\n\t/**\n\t * Indicates if this is a console reporter.\n\t * There is only one console reporter can be present in the system.\n\t */\n\treadonly isConsoleReporter?: boolean\n\twrite(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n\tid?: string\n\t/**\n\t * Specifies the formatter to be used by the reporter.\n\t * Using this you can customize how the reporter writes the log entry.\n\t */\n\tformatter?: LogFormatter<T>\n\t/**\n\t * Specifies a filter to determine should the log be written.\n\t */\n\tfilter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n\tdebug(...args: any[]): void\n\tinfo(...args: any[]): void\n\twarn(...args: any[]): void\n\terror(...args: any[]): void\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "standard-log",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.4",
|
|
4
4
|
"description": "The standard log library",
|
|
5
5
|
"homepage": "https://github.com/unional/standard-log/tree/main/packages/log",
|
|
6
6
|
"bugs": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@types/jest": "^29.1.1",
|
|
71
71
|
"@types/ms": "^0.7.31",
|
|
72
72
|
"@types/node": "^18.0.0",
|
|
73
|
-
"@types/ramda": "^0.
|
|
73
|
+
"@types/ramda": "^0.29.0",
|
|
74
74
|
"assertron": "^11.0.0",
|
|
75
75
|
"compression-webpack-plugin": "^10.0.0",
|
|
76
76
|
"cross-env": "^7.0.3",
|
package/ts/types.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import type { StackTraceMeta } from '@just-func/types'
|
|
2
2
|
|
|
3
3
|
export type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
|
|
4
|
+
/**
|
|
5
|
+
* A map of custom log levels.
|
|
6
|
+
*
|
|
7
|
+
* Each logger created will have a method for each custom level.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createStandardLog } from 'standard-log'
|
|
11
|
+
*
|
|
12
|
+
* const sl = createStandardLog({ customLevels: { foo: 100 } })
|
|
13
|
+
* const logger = sl.getLogger('my-logger')
|
|
14
|
+
*
|
|
15
|
+
* logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
4
18
|
customLevels?: Record<CustomLevelNames, number>
|
|
5
19
|
logLevel?: number
|
|
6
20
|
reporters?: LogReporter[]
|
|
@@ -59,10 +73,45 @@ export type LogFunction = (log: LogMethod, logLevel: number) => string | void
|
|
|
59
73
|
export type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)
|
|
60
74
|
|
|
61
75
|
export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
76
|
+
/**
|
|
77
|
+
* The current log level.
|
|
78
|
+
*/
|
|
62
79
|
logLevel: number
|
|
80
|
+
/**
|
|
81
|
+
* Convert log level number to log level name.
|
|
82
|
+
*/
|
|
63
83
|
toLogLevelName(level: number): string
|
|
84
|
+
/**
|
|
85
|
+
* Convert log level name to log level number.
|
|
86
|
+
*/
|
|
64
87
|
toLogLevel(name: N): number
|
|
88
|
+
/**
|
|
89
|
+
* Get a logger instance with the specified id.
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { createStandardLog } from 'standard-log'
|
|
93
|
+
*
|
|
94
|
+
* const sl = createStandardLog()
|
|
95
|
+
* const logger = sl.getLogger('my-logger')
|
|
96
|
+
*
|
|
97
|
+
* logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
65
100
|
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
|
|
101
|
+
/**
|
|
102
|
+
* Get a non-console logger instance with the specified id.
|
|
103
|
+
*
|
|
104
|
+
* The resulting logger will only write to the reporters that are not console reporters.
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { createStandardLog } from 'standard-log'
|
|
108
|
+
*
|
|
109
|
+
* const sl = createStandardLog({ reporter: [createConsoleReporter(), createRemoteReporter(...)] })
|
|
110
|
+
* const logger = sl.getNonConsoleLogger('my-logger')
|
|
111
|
+
*
|
|
112
|
+
* logger.info('Hello world!') // will only write to remote reporter
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
66
115
|
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
|
|
67
116
|
}
|
|
68
117
|
|
|
@@ -92,7 +141,7 @@ export interface LogReporter<T = any> {
|
|
|
92
141
|
*/
|
|
93
142
|
readonly filter?: LogFilter
|
|
94
143
|
/**
|
|
95
|
-
*
|
|
144
|
+
* Indicates if this is a console reporter.
|
|
96
145
|
* There is only one console reporter can be present in the system.
|
|
97
146
|
*/
|
|
98
147
|
readonly isConsoleReporter?: boolean
|