standard-log 9.1.2 → 9.1.3
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/README.md +2 -3
- package/cjs/console.spec.js +1 -1
- package/cjs/console.spec.js.map +1 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/logger.d.ts +1 -2
- package/cjs/logger.d.ts.map +1 -1
- package/cjs/logger.js +6 -7
- package/cjs/logger.js.map +1 -1
- package/cjs/standardLog.d.ts +3 -4
- package/cjs/standardLog.d.ts.map +1 -1
- package/cjs/standardLog.js +5 -6
- package/cjs/standardLog.js.map +1 -1
- package/cjs/standardLog.spec.js +47 -47
- package/cjs/standardLog.spec.js.map +1 -1
- package/cjs/types.d.ts +2 -1
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +11 -13
- package/dist/standard-log.es5.js.gz +0 -0
- package/dist/standard-log.es5.js.map +1 -1
- package/dist/standard-log.es5.js.map.gz +0 -0
- package/dist/standard-log.esm.js +7 -7
- package/dist/standard-log.esm.js.gz +0 -0
- package/dist/standard-log.esm.js.map +1 -1
- package/dist/standard-log.esm.js.map.gz +0 -0
- package/esm/console.spec.js +1 -1
- package/esm/console.spec.js.map +1 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/logger.d.ts +1 -2
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +2 -2
- package/esm/logger.js.map +1 -1
- package/esm/standardLog.d.ts +3 -4
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js +5 -5
- package/esm/standardLog.js.map +1 -1
- package/esm/standardLog.spec.js +47 -47
- package/esm/standardLog.spec.js.map +1 -1
- package/esm/types.d.ts +2 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +1 -1
- package/ts/index.ts +2 -2
- package/ts/logger.ts +2 -3
- package/ts/standardLog.ts +6 -8
- package/ts/types.ts +3 -1
package/esm/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { StackTraceMeta } from '@just-func/types';
|
|
1
2
|
export declare type StandardLogOptions<CustomLevelNames extends string = string> = {
|
|
2
3
|
customLevels?: Record<CustomLevelNames, number>;
|
|
3
4
|
logLevel?: number;
|
|
4
5
|
reporters?: LogReporter[];
|
|
5
6
|
};
|
|
6
|
-
export interface LoggerOptions {
|
|
7
|
+
export interface LoggerOptions extends StackTraceMeta {
|
|
7
8
|
level?: number;
|
|
8
9
|
writeTo?: LogReporter | ReporterFilter;
|
|
9
10
|
}
|
package/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB,CAAC,gBAAgB,SAAS,MAAM,GAAG,MAAM,IAAI;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAA;CAC1B,CAAA;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,oBAAY,kBAAkB,CAAC,gBAAgB,SAAS,MAAM,GAAG,MAAM,IAAI;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAA;CAC1B,CAAA;AAED,MAAM,WAAW,aAAc,SAAQ,cAAc;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IAC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"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["import { StackTraceMeta } from '@just-func/types'\n\nexport type StandardLogOptions<CustomLevelNames extends string = string> = {\n customLevels?: Record<CustomLevelNames, number>,\n logLevel?: number,\n reporters?: LogReporter[]\n}\n\nexport interface LoggerOptions extends StackTraceMeta {\n level?: number,\n writeTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<T extends string = LogMethodNames> = {\n readonly id: string,\n /**\n * Logger local log level.\n */\n level?: number,\n /**\n * Logs with an increment counter.\n * This is useful during debugging to check for steps executed.\n */\n count(...args: any[]): void,\n on(level: number | T, logFunction: LogFunction): void,\n /**\n * Write custom log entries.\n */\n write(entry: LogEntry): void\n} & { [k in T]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck'\n\nexport type LogEntry = {\n id: string,\n level: number,\n // args instead of messages because it is `any[]` instead of `string[]`\n args: any[],\n timestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = ((log: LogMethod) => void) | (() => string)\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\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 readonly id: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n readonly formatter: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n readonly filter?: LogFilter,\n /**\n * Indicate if this is a console reporter.\n * There is only one console reporter can be present in the system.\n */\n readonly isConsoleReporter?: boolean,\n write(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n id?: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n formatter?: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n filter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n debug(...args: any[]): void,\n info(...args: any[]): void,\n warn(...args: any[]): void,\n error(...args: any[]): void,\n}\n"]}
|
package/package.json
CHANGED
package/ts/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './logLevels.js'
|
|
|
5
5
|
export * from './memory.js'
|
|
6
6
|
export {
|
|
7
7
|
configGlobal, createStandardLog, createStandardLogForTest,
|
|
8
|
-
getLogger,
|
|
8
|
+
getLogger, suppressLogs
|
|
9
9
|
} from './standardLog.js'
|
|
10
|
+
export type { StandardLog, StandardLogInstance } from './standardLog.js'
|
|
10
11
|
export * from './types.js'
|
|
11
|
-
|
package/ts/logger.ts
CHANGED
|
@@ -6,10 +6,9 @@ import type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogR
|
|
|
6
6
|
import { LogLevel } from './types.js'
|
|
7
7
|
|
|
8
8
|
export function createLogger<T extends string = LogMethodNames>(
|
|
9
|
-
|
|
10
|
-
meta?: StackTraceMeta
|
|
9
|
+
store: LogStore, id: string, options?: LoggerOptions
|
|
11
10
|
): Logger {
|
|
12
|
-
validateId(id,
|
|
11
|
+
validateId(id, options)
|
|
13
12
|
const writeTo = options?.writeTo ?? (() => true)
|
|
14
13
|
const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'
|
|
15
14
|
? [id => id === writeTo, store.reporters]
|
package/ts/standardLog.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { StackTraceMeta } from '@just-func/types'
|
|
2
1
|
import { record, required } from 'type-plus'
|
|
3
2
|
import { createLogger } from './logger.js'
|
|
4
3
|
import { logLevels } from './logLevels.js'
|
|
@@ -10,7 +9,7 @@ export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
|
10
9
|
logLevel: number,
|
|
11
10
|
toLogLevelName(level: number): string,
|
|
12
11
|
toLogLevel(name: N): number,
|
|
13
|
-
getLogger(
|
|
12
|
+
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
|
|
@@ -40,9 +39,9 @@ export function createStandardLogClosure<N extends string = LogMethodNames>(
|
|
|
40
39
|
toLogLevel(name: string) {
|
|
41
40
|
return store.logLevelStore.getLevel(name)
|
|
42
41
|
},
|
|
43
|
-
getLogger(
|
|
42
|
+
getLogger(id: string, options?: LoggerOptions) {
|
|
44
43
|
if (store.loggers[id]) return store.loggers[id] as any
|
|
45
|
-
return store.loggers[id] = createLogger(
|
|
44
|
+
return store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -66,9 +65,8 @@ export function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {
|
|
|
66
65
|
return result
|
|
67
66
|
}
|
|
68
67
|
|
|
69
|
-
export function getLogger<N extends string = LogMethodNames>(
|
|
70
|
-
|
|
71
|
-
return getGlobalSL<N>().getLogger(params, meta)
|
|
68
|
+
export function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {
|
|
69
|
+
return getGlobalSL<N>().getLogger(id, options)
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
export const ctx: {
|
|
@@ -84,7 +82,7 @@ function getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N
|
|
|
84
82
|
|
|
85
83
|
export function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {
|
|
86
84
|
if (ctx.configured) {
|
|
87
|
-
const log = ctx.gsl?.standardLog.getLogger(
|
|
85
|
+
const log = ctx.gsl?.standardLog.getLogger('standard-log')
|
|
88
86
|
log?.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.')
|
|
89
87
|
}
|
|
90
88
|
|
package/ts/types.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { StackTraceMeta } from '@just-func/types'
|
|
2
|
+
|
|
1
3
|
export type StandardLogOptions<CustomLevelNames extends string = string> = {
|
|
2
4
|
customLevels?: Record<CustomLevelNames, number>,
|
|
3
5
|
logLevel?: number,
|
|
4
6
|
reporters?: LogReporter[]
|
|
5
7
|
}
|
|
6
8
|
|
|
7
|
-
export interface LoggerOptions {
|
|
9
|
+
export interface LoggerOptions extends StackTraceMeta {
|
|
8
10
|
level?: number,
|
|
9
11
|
writeTo?: LogReporter | ReporterFilter
|
|
10
12
|
}
|