standard-log 11.4.0 → 11.4.1
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/index.d.ts +2 -2
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +1 -1
- package/cjs/logger.d.ts.map +1 -1
- package/cjs/logger.js +2 -3
- package/cjs/logger.js.map +1 -1
- package/cjs/standardLog.ctx.d.ts +10 -0
- package/cjs/standardLog.ctx.d.ts.map +1 -0
- package/cjs/standardLog.ctx.js +6 -0
- package/cjs/standardLog.ctx.js.map +1 -0
- package/cjs/standardLog.d.ts +1 -15
- package/cjs/standardLog.d.ts.map +1 -1
- package/cjs/standardLog.js +14 -14
- package/cjs/standardLog.js.map +1 -1
- package/cjs/types.d.ts +8 -1
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +32 -31
- 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 +48 -32
- 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/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +1 -1
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +2 -3
- package/esm/logger.js.map +1 -1
- package/esm/standardLog.ctx.d.ts +10 -0
- package/esm/standardLog.ctx.d.ts.map +1 -0
- package/esm/standardLog.ctx.js +3 -0
- package/esm/standardLog.ctx.js.map +1 -0
- package/esm/standardLog.d.ts +1 -15
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js +1 -1
- package/esm/standardLog.js.map +1 -1
- package/esm/types.d.ts +8 -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 +7 -2
- package/ts/logger.ts +2 -3
- package/ts/standardLog.ctx.ts +8 -0
- package/ts/standardLog.ts +2 -14
- package/ts/types.ts +9 -1
package/esm/standardLog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardLog.d.ts","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAA2B,iBAAiB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"standardLog.d.ts","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAA2B,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAExE,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE1H,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,CAAE,SAAQ,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;CACvG;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACjE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC9B,WAAW,CAAC,CAAC,CAAC,CAShB;AAID,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACxE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC9B;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,CA2ClD;AASD,oBAAY,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,iBAAiB,CAAA;CAAE,CAAA;AAEpH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACxE,QAAQ,GAAE,QAA0B,GACnC,kBAAkB,CAAC,CAAC,CAAC,CAIvB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;AASlF,oBAAY,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC,CAAA;AAE9H,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,8BAE/F;AAQD,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC,QAoB7E"}
|
package/esm/standardLog.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createLogger } from './logger.js';
|
|
|
3
3
|
import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js';
|
|
4
4
|
import { createLogStore } from './logStore.js';
|
|
5
5
|
import { createMemoryLogReporter } from './memory.js';
|
|
6
|
+
import { ctx } from './standardLog.ctx.js';
|
|
6
7
|
export function createStandardLog(options) {
|
|
7
8
|
var _a;
|
|
8
9
|
const closure = createStandardLogClosure(options);
|
|
@@ -80,7 +81,6 @@ export function suppressLogs(block, ...logs) {
|
|
|
80
81
|
export function getLogger(id, options) {
|
|
81
82
|
return getGlobalSL().getLogger(id, options);
|
|
82
83
|
}
|
|
83
|
-
export const ctx = record();
|
|
84
84
|
function getGlobalSL() {
|
|
85
85
|
if (!ctx.gsl)
|
|
86
86
|
ctx.gsl = createStandardLogClosure();
|
package/esm/standardLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAY,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAqB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAY,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAqB,MAAM,aAAa,CAAA;AACxE,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAM1C,MAAM,UAAU,iBAAiB,CAC/B,OAA+B;;IAE/B,MAAM,OAAO,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;IACjD,IAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;QACxC,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QACzD,GAAG,CAAC,QAAQ,CAAC,+JAA+J,CAAC,CAAA;KAC9K;IAED,IAAI,CAAC,GAAG,CAAC,GAAG;QAAE,GAAG,CAAC,G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1D,GAAG,CAAC,IAAI,CAAC,kJAAkJ,CAAC,CAAA;KAC7J;IAED,IAAI,GAAG,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;SAC1C;QACD,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAA;YACzC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAA;YACpB,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;SACrC;KACF;SACI;QACH,GAAG,CAAC,GAAG,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;KAC5C;IACD,GAAG,CAAC,UAAU,GAAG,IAAI,CAAA;AACvB,CAAC","sourcesContent":["import { record, required } from 'type-plus'\nimport { createLogger } from './logger.js'\nimport { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js'\nimport { createLogStore, LogStore } from './logStore.js'\nimport { createMemoryLogReporter, MemoryLogReporter } from './memory.js'\nimport { ctx } from './standardLog.ctx.js'\nimport type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogInstance, StandardLogOptions } from './types.js'\n\nexport interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {\n}\n\nexport function createStandardLog<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): StandardLog<N> {\n const closure = createStandardLogClosure(options)\n if (options?.reporters?.some(r => !r.id)) {\n const log = closure.standardLog.getLogger('standard-log')\n log.critical(`Detected reporter with empty id. This is not allowed as it will create problems with feature like 'getNonConsoleLogger()'. Please add an id to your reporter.`)\n }\n\n if (!ctx.gsl) ctx.gsl = closure as any\n return closure.standardLog\n}\n\nfunction noop() { }\n\nexport function createStandardLogClosure<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): { store: LogStore, standardLog: StandardLog<N> } {\n // TODO reporter.id must not be empty\n const store = createLogStore(required({ logLevel: logLevels.info }, options))\n const nonConsoleReporters = options?.reporters?.filter(r => !r.isConsoleReporter).map(r => r.id) ?? []\n const logMethods = DEFAULT_LOG_METHOD_NAMES\n .concat(Object.keys(options?.customLevels ?? {}))\n .concat(['on', 'count', 'write'])\n return {\n store,\n standardLog: {\n get logLevel() { return store.logLevel },\n\n toLogLevelName(level: number) {\n return store.logLevelStore.getName(level)\n },\n toLogLevel(name: string) {\n return store.logLevelStore.getLevel(name)\n },\n getLogger(id: string, options?: LoggerOptions) {\n if (store.loggers[id]) return store.loggers[id] as any\n return store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any\n },\n getNonConsoleLogger(id, options?) {\n if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id] as any\n\n if (store.loggers[id]) {\n const log = this.getLogger('standard-log')\n log.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`)\n return store.nonConsoleLoggers[id] = createDummyLogger(logMethods)\n }\n\n return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0\n ? createDummyLogger(logMethods)\n : createLogger(store, id, {\n ssf: this.getNonConsoleLogger,\n ...options,\n writeTo(reporterId) {\n return nonConsoleReporters.indexOf(reporterId) >= 0\n }\n })\n },\n }\n }\n}\n\nfunction createDummyLogger(logMethods: string[]) {\n return logMethods.reduce((p, m) => {\n p[m] = noop\n return p\n }, record()) as Logger\n}\n\nexport type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & { reporter: MemoryLogReporter }\n\nexport function createStandardLogForTest<N extends string = LogMethodNames>(\n logLevel: LogLevel = logLevels.debug\n): StandardLogForTest<N> {\n const reporter = createMemoryLogReporter()\n const closure = createStandardLogClosure<N>({ reporters: [reporter], logLevel })\n return { ...closure.standardLog, reporter }\n}\n\n/**\n * Suppress logging within the code block.\n */\nexport function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R\nexport function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {\n const origLevels = logs.map(l => l.level)\n logs.forEach(l => l.level = logLevels.none)\n const result = block()\n logs.forEach((l, i) => l.level = origLevels[i])\n return result\n}\n\nexport type GetLogger<N extends string = LogMethodNames> = (id: string, options?: LoggerOptions) => Logger<LogMethodNames | N>\n\nexport function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {\n return getGlobalSL<N>().getLogger(id, options)\n}\n\nfunction getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {\n if (!ctx.gsl) ctx.gsl = createStandardLogClosure()\n\n return ctx.gsl!.standardLog as StandardLogInstance<N>\n}\n\nexport function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {\n if (ctx.configured) {\n const log = ctx.gsl!.standardLog.getLogger('standard-log')\n log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.')\n }\n\n if (ctx.gsl) {\n if (options.logLevel) {\n ctx.gsl.store.logLevel = options.logLevel\n }\n if (options.reporters) {\n const reporters = ctx.gsl.store.reporters\n reporters.length = 0\n reporters.push(...options.reporters)\n }\n }\n else {\n ctx.gsl = createStandardLogClosure(options)\n }\n ctx.configured = true\n}\n"]}
|
package/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StackTraceMeta } from '@just-func/types';
|
|
1
|
+
import type { StackTraceMeta } from '@just-func/types';
|
|
2
2
|
export declare type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
|
|
3
3
|
customLevels?: Record<CustomLevelNames, number>;
|
|
4
4
|
logLevel?: number;
|
|
@@ -40,6 +40,13 @@ export declare type LogEntry = {
|
|
|
40
40
|
export declare type LogMethod = (...args: any[]) => void;
|
|
41
41
|
export declare type LogFunction = ((log: LogMethod) => void) | (() => string);
|
|
42
42
|
export declare type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
|
|
43
|
+
export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
44
|
+
logLevel: number;
|
|
45
|
+
toLogLevelName(level: number): string;
|
|
46
|
+
toLogLevel(name: N): number;
|
|
47
|
+
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
48
|
+
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
49
|
+
}
|
|
43
50
|
/**
|
|
44
51
|
* Formats a log entry.
|
|
45
52
|
* Depends on the reporter, it can expect a different return type.
|
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,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,oBAAY,kBAAkB,CAAC,gBAAgB,SAAS,MAAM,GAAG,cAAc,IAAI;IACjF,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;IACf,OAAO,CAAC,EAAE,WAAW,GAAG,cAAc,CAAA;CACvC;AAED,oBAAY,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI;IACtD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,WAAW,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
|
|
|
1
|
-
{"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 = LogMethodNames> = {\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<N 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 | N, logFunction: LogFunction): void,\n /**\n * Write custom log entries.\n */\n write(entry: LogEntry): void\n} & { [k in N]: 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"]}
|
|
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 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<N 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 | N, logFunction: LogFunction): void,\n /**\n * Write custom log entries.\n */\n write(entry: LogEntry): void\n} & { [k in N]: 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\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n logLevel: number,\n toLogLevelName(level: number): string,\n toLogLevel(name: N): number,\n getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,\n getNonConsoleLogger(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 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
|
@@ -7,5 +7,10 @@ export {
|
|
|
7
7
|
configGlobal, createStandardLog, createStandardLogForTest,
|
|
8
8
|
getLogger, suppressLogs
|
|
9
9
|
} from './standardLog.js'
|
|
10
|
-
export type { StandardLog, StandardLogForTest
|
|
11
|
-
export
|
|
10
|
+
export type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js'
|
|
11
|
+
export type {
|
|
12
|
+
ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, Logger, LoggerOptions, LogLevel,
|
|
13
|
+
LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, ReporterFilter,
|
|
14
|
+
StandardLogInstance, StandardLogOptions
|
|
15
|
+
} from './types.js'
|
|
16
|
+
|
package/ts/logger.ts
CHANGED
|
@@ -30,11 +30,10 @@ export function createLogger<N extends string = LogMethodNames>(
|
|
|
30
30
|
count: {
|
|
31
31
|
writable: false,
|
|
32
32
|
value: ((counter) => (...args: any[]) => {
|
|
33
|
-
|
|
34
|
-
if (shouldLog(store, level, logger.level))
|
|
33
|
+
if (shouldLog(store, logLevels.debug, logger.level))
|
|
35
34
|
write({
|
|
36
35
|
id,
|
|
37
|
-
level,
|
|
36
|
+
level: logLevels.debug,
|
|
38
37
|
args: [++counter, ...args],
|
|
39
38
|
timestamp: new Date()
|
|
40
39
|
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { record } from 'type-plus'
|
|
2
|
+
import type { LogStore } from './logStore.js'
|
|
3
|
+
import type { LogMethodNames, StandardLogInstance } from './types.js'
|
|
4
|
+
|
|
5
|
+
export const ctx: {
|
|
6
|
+
configured?: boolean,
|
|
7
|
+
gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }
|
|
8
|
+
} = record()
|
package/ts/standardLog.ts
CHANGED
|
@@ -3,15 +3,8 @@ import { createLogger } from './logger.js'
|
|
|
3
3
|
import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js'
|
|
4
4
|
import { createLogStore, LogStore } from './logStore.js'
|
|
5
5
|
import { createMemoryLogReporter, MemoryLogReporter } from './memory.js'
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
9
|
-
logLevel: number,
|
|
10
|
-
toLogLevelName(level: number): string,
|
|
11
|
-
toLogLevel(name: N): number,
|
|
12
|
-
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,
|
|
13
|
-
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
|
|
14
|
-
}
|
|
6
|
+
import { ctx } from './standardLog.ctx.js'
|
|
7
|
+
import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogInstance, StandardLogOptions } from './types.js'
|
|
15
8
|
|
|
16
9
|
export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
|
|
17
10
|
}
|
|
@@ -113,11 +106,6 @@ export function getLogger<N extends string = LogMethodNames>(id: string, options
|
|
|
113
106
|
return getGlobalSL<N>().getLogger(id, options)
|
|
114
107
|
}
|
|
115
108
|
|
|
116
|
-
export const ctx: {
|
|
117
|
-
configured?: boolean,
|
|
118
|
-
gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }
|
|
119
|
-
} = record()
|
|
120
|
-
|
|
121
109
|
function getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {
|
|
122
110
|
if (!ctx.gsl) ctx.gsl = createStandardLogClosure()
|
|
123
111
|
|
package/ts/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StackTraceMeta } from '@just-func/types'
|
|
1
|
+
import type { StackTraceMeta } from '@just-func/types'
|
|
2
2
|
|
|
3
3
|
export type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
|
|
4
4
|
customLevels?: Record<CustomLevelNames, number>,
|
|
@@ -48,6 +48,14 @@ export type LogFunction = ((log: LogMethod) => void) | (() => string)
|
|
|
48
48
|
|
|
49
49
|
export type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)
|
|
50
50
|
|
|
51
|
+
export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
52
|
+
logLevel: number,
|
|
53
|
+
toLogLevelName(level: number): string,
|
|
54
|
+
toLogLevel(name: N): number,
|
|
55
|
+
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,
|
|
56
|
+
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
/**
|
|
52
60
|
* Formats a log entry.
|
|
53
61
|
* Depends on the reporter, it can expect a different return type.
|