standard-log 11.4.0 → 11.5.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/README.md +5 -0
- 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 +4 -4
- 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 +9 -2
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +201 -269
- 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 +200 -163
- 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 +4 -4
- 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 +9 -2
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +3 -3
- package/ts/index.ts +7 -2
- package/ts/logger.ts +3 -4
- package/ts/standardLog.ctx.ts +8 -0
- package/ts/standardLog.ts +2 -14
- package/ts/types.ts +10 -2
package/README.md
CHANGED
|
@@ -41,6 +41,11 @@ log.info('info message')
|
|
|
41
41
|
// by default debug() will not be printed
|
|
42
42
|
// because production mode defaults log level to `info`
|
|
43
43
|
log.debug('debug message')
|
|
44
|
+
|
|
45
|
+
// If the message is consume resource to generage,
|
|
46
|
+
// you can use `log.on()` so that it will be called only
|
|
47
|
+
// if the level is met.
|
|
48
|
+
log.on(logLevels.trace, () => prettify(someValue))
|
|
44
49
|
```
|
|
45
50
|
|
|
46
51
|
![Rendering example][rendering-example]
|
package/cjs/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export * from './formatter.js';
|
|
|
4
4
|
export * from './logLevels.js';
|
|
5
5
|
export * from './memory.js';
|
|
6
6
|
export { configGlobal, createStandardLog, createStandardLogForTest, getLogger, suppressLogs } from './standardLog.js';
|
|
7
|
-
export type { StandardLog, StandardLogForTest
|
|
8
|
-
export
|
|
7
|
+
export type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js';
|
|
8
|
+
export type { ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, Logger, LoggerOptions, LogLevel, LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, ReporterFilter, StandardLogInstance, StandardLogOptions } from './types.js';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,OAAO,EACL,YAAY,EAAE,iBAAiB,EAAE,wBAAwB,EACzD,SAAS,EAAE,YAAY,EACxB,MAAM,kBAAkB,CAAA;AACzB,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,OAAO,EACL,YAAY,EAAE,iBAAiB,EAAE,wBAAwB,EACzD,SAAS,EAAE,YAAY,EACxB,MAAM,kBAAkB,CAAA;AACzB,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAClF,YAAY,EACV,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAC5F,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EACzF,mBAAmB,EAAE,kBAAkB,EACxC,MAAM,YAAY,CAAA"}
|
package/cjs/index.js
CHANGED
|
@@ -26,5 +26,4 @@ Object.defineProperty(exports, "createStandardLog", { enumerable: true, get: fun
|
|
|
26
26
|
Object.defineProperty(exports, "createStandardLogForTest", { enumerable: true, get: function () { return standardLog_js_1.createStandardLogForTest; } });
|
|
27
27
|
Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return standardLog_js_1.getLogger; } });
|
|
28
28
|
Object.defineProperty(exports, "suppressLogs", { enumerable: true, get: function () { return standardLog_js_1.suppressLogs; } });
|
|
29
|
-
__exportStar(require("./types.js"), exports);
|
|
30
29
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,8CAA2B;AAC3B,iDAA8B;AAC9B,iDAA8B;AAC9B,8CAA2B;AAC3B,mDAGyB;AAFvB,8GAAA,YAAY,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAAE,0HAAA,wBAAwB,OAAA;AACzD,2GAAA,SAAS,OAAA;AAAE,8GAAA,YAAY,OAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,8CAA2B;AAC3B,iDAA8B;AAC9B,iDAA8B;AAC9B,8CAA2B;AAC3B,mDAGyB;AAFvB,8GAAA,YAAY,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAAE,0HAAA,wBAAwB,OAAA;AACzD,2GAAA,SAAS,OAAA;AAAE,8GAAA,YAAY,OAAA","sourcesContent":["export * from './console.js'\nexport * from './errors.js'\nexport * from './formatter.js'\nexport * from './logLevels.js'\nexport * from './memory.js'\nexport {\n configGlobal, createStandardLog, createStandardLogForTest,\n getLogger, suppressLogs\n} from './standardLog.js'\nexport type { GetLogger, StandardLog, StandardLogForTest } from './standardLog.js'\nexport type {\n ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, Logger, LoggerOptions, LogLevel,\n LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, ReporterFilter,\n StandardLogInstance, StandardLogOptions\n} from './types.js'\n\n"]}
|
package/cjs/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAyB,MAAM,EAAE,aAAa,EAAE,cAAc,EAAe,MAAM,YAAY,CAAA;AAG3G,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAC5D,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GACnD,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAyB,MAAM,EAAE,aAAa,EAAE,cAAc,EAAe,MAAM,YAAY,CAAA;AAG3G,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAC5D,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GACnD,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,CAwD5B"}
|
package/cjs/logger.js
CHANGED
|
@@ -38,11 +38,10 @@ function createLogger(store, id, options) {
|
|
|
38
38
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
39
39
|
args[_i] = arguments[_i];
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
if (shouldLog(store, level, logger.level))
|
|
41
|
+
if (shouldLog(store, logLevels_js_1.logLevels.debug, logger.level))
|
|
43
42
|
write({
|
|
44
43
|
id: id,
|
|
45
|
-
level:
|
|
44
|
+
level: logLevels_js_1.logLevels.debug,
|
|
46
45
|
args: __spreadArray([++counter], args, true),
|
|
47
46
|
timestamp: new Date()
|
|
48
47
|
});
|
|
@@ -51,11 +50,12 @@ function createLogger(store, id, options) {
|
|
|
51
50
|
on: {
|
|
52
51
|
writable: false,
|
|
53
52
|
value: function (level, logFn) {
|
|
53
|
+
var _a;
|
|
54
54
|
var logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level) : level;
|
|
55
55
|
if (shouldLog(store, logLevel, logger.level)) {
|
|
56
56
|
var methodName = store.logLevelStore.getName(logLevel);
|
|
57
57
|
var bindedMethod = logger[methodName].bind(logger);
|
|
58
|
-
var result = logFn(bindedMethod);
|
|
58
|
+
var result = logFn(bindedMethod, (_a = logger.level) !== null && _a !== void 0 ? _a : store.logLevel);
|
|
59
59
|
if (result)
|
|
60
60
|
bindedMethod(result);
|
|
61
61
|
}
|
package/cjs/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA0C;AAK1C,SAAgB,YAAY,CAC1B,KAAe,EAAE,EAAU,EAAE,OAAuB;;IAEpD,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACnB,IAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAA;IAC1C,IAAA,KAAwE,OAAO,OAAO,KAAK,QAAQ;QACvG,CAAC,CAAC,CAAC,UAAA,EAAE,IAAI,OAAA,EAAE,KAAK,OAAO,EAAd,CAAc,EAAE,KAAK,CAAC,SAAS,CAAC;QACzC,CAAC,CAAC,OAAO,YAAY,MAAM;YACzB,CAAC,CAAC,CAAC,UAAA,EAAE,IAAI,OAAA,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAhB,CAAgB,EAAE,KAAK,CAAC,SAAS,CAAC;YAC3C,CAAC,CAAC,OAAO,OAAO,KAAK,UAAU;gBAC7B,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;gBAC5B,CAAC,CAAC,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,EAAE,CAAC,OAAO,CAAC,CAAC,EANxB,MAAM,QAAA,EAAE,SAAS,QAMO,CAAA;IAE/B,SAAS,KAAK,CAAC,KAAe;QAC5B,gBAAgB,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,IAAM,MAAM,GAAG;QACb,KAAK,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK;QACrB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AED;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAe,EAAE,WAAqB,EAAE,WAAiC;IAC1F,OAAO,WAAW,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AAClF,CAAC","sourcesContent":["import { logLevels } from './logLevels.js'\nimport { LogStore } from './logStore.js'\nimport type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'\nimport { LogLevel } from './types.js'\n\nexport function createLogger<N extends string = LogMethodNames>(\n store: LogStore, id: string, options?: LoggerOptions\n): Logger<N | LogMethodNames> {\n id = sanitizeId(id)\n const writeTo = options?.writeTo ?? (() => true)\n const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'\n ? [id => id === writeTo, store.reporters]\n : writeTo instanceof RegExp\n ? [id => writeTo.test(id), store.reporters]\n : typeof writeTo === 'function'\n ? [writeTo, store.reporters]\n : [() => true, [writeTo]]\n\n function write(entry: LogEntry) {\n writeToReporters(reporters, entry, filter)\n }\n\n const logger = {\n level: options?.level,\n write\n } as any\n\n Object.defineProperties(logger, {\n id: { value: id, writable: false },\n count: {\n writable: false,\n value: ((counter) => (...args: any[]) => {\n if (shouldLog(store, logLevels.debug, logger.level))\n write({\n id,\n level: logLevels.debug,\n args: [++counter, ...args],\n timestamp: new Date()\n })\n })(0)\n },\n on: {\n writable: false,\n value: (level: number | N | LogMethodNames, logFn: LogFunction) => {\n const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level\n if (shouldLog(store, logLevel, logger.level)) {\n const methodName = store.logLevelStore.getName(logLevel)\n const bindedMethod = logger[methodName].bind(logger)\n const result = logFn(bindedMethod, logger.level ?? store.logLevel)\n if (result) bindedMethod(result)\n }\n }\n }\n })\n store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {\n Object.defineProperty(logger, name, {\n writable: false,\n value: (...args: any[]) => {\n if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })\n }\n })\n })\n return logger\n}\n\nfunction sanitizeId(id: string) {\n return id.replace(/[`~!#$%^&*()=+[\\]{},|<>?]/g, '-')\n}\n\nfunction writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter: (reporterId: string) => boolean) {\n reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))\n}\n\n/**\n * Determines should you log.\n * @param loggerLevel Log level of the logger.\n * It can be undefined which the global log level will be used.\n */\nfunction shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {\n return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LogStore } from './logStore.js';
|
|
2
|
+
import type { LogMethodNames, StandardLogInstance } from './types.js';
|
|
3
|
+
export declare const ctx: {
|
|
4
|
+
configured?: boolean;
|
|
5
|
+
gsl?: {
|
|
6
|
+
store: LogStore;
|
|
7
|
+
standardLog: StandardLogInstance<LogMethodNames>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=standardLog.ctx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardLog.ctx.d.ts","sourceRoot":"","sources":["../ts/standardLog.ctx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,eAAO,MAAM,GAAG,EAAE;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,WAAW,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAA;KAAE,CAAA;CACjE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardLog.ctx.js","sourceRoot":"","sources":["../ts/standardLog.ctx.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAIrB,QAAA,GAAG,GAGZ,IAAA,kBAAM,GAAE,CAAA","sourcesContent":["import { record } from 'type-plus'\nimport type { LogStore } from './logStore.js'\nimport type { LogMethodNames, StandardLogInstance } from './types.js'\n\nexport const ctx: {\n configured?: boolean,\n gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }\n} = record()\n"]}
|
package/cjs/standardLog.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { LogStore } from './logStore.js';
|
|
2
2
|
import { MemoryLogReporter } from './memory.js';
|
|
3
|
-
import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js';
|
|
4
|
-
export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
5
|
-
logLevel: number;
|
|
6
|
-
toLogLevelName(level: number): string;
|
|
7
|
-
toLogLevel(name: N): number;
|
|
8
|
-
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
9
|
-
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
10
|
-
}
|
|
3
|
+
import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogInstance, StandardLogOptions } from './types.js';
|
|
11
4
|
export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
|
|
12
5
|
}
|
|
13
6
|
export declare function createStandardLog<N extends string = LogMethodNames>(options?: StandardLogOptions<N>): StandardLog<N>;
|
|
@@ -25,12 +18,5 @@ export declare function createStandardLogForTest<N extends string = LogMethodNam
|
|
|
25
18
|
export declare function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R;
|
|
26
19
|
export declare type GetLogger<N extends string = LogMethodNames> = (id: string, options?: LoggerOptions) => Logger<LogMethodNames | N>;
|
|
27
20
|
export declare function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions): Logger<LogMethodNames | N>;
|
|
28
|
-
export declare const ctx: {
|
|
29
|
-
configured?: boolean;
|
|
30
|
-
gsl?: {
|
|
31
|
-
store: LogStore;
|
|
32
|
-
standardLog: StandardLogInstance<LogMethodNames>;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
21
|
export declare function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>): void;
|
|
36
22
|
//# sourceMappingURL=standardLog.d.ts.map
|
package/cjs/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/cjs/standardLog.js
CHANGED
|
@@ -11,12 +11,13 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.configGlobal = exports.
|
|
14
|
+
exports.configGlobal = exports.getLogger = exports.suppressLogs = exports.createStandardLogForTest = exports.createStandardLogClosure = exports.createStandardLog = void 0;
|
|
15
15
|
var type_plus_1 = require("type-plus");
|
|
16
16
|
var logger_js_1 = require("./logger.js");
|
|
17
17
|
var logLevels_js_1 = require("./logLevels.js");
|
|
18
18
|
var logStore_js_1 = require("./logStore.js");
|
|
19
19
|
var memory_js_1 = require("./memory.js");
|
|
20
|
+
var standardLog_ctx_js_1 = require("./standardLog.ctx.js");
|
|
20
21
|
function createStandardLog(options) {
|
|
21
22
|
var _a;
|
|
22
23
|
var closure = createStandardLogClosure(options);
|
|
@@ -24,8 +25,8 @@ function createStandardLog(options) {
|
|
|
24
25
|
var log = closure.standardLog.getLogger('standard-log');
|
|
25
26
|
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.");
|
|
26
27
|
}
|
|
27
|
-
if (!
|
|
28
|
-
|
|
28
|
+
if (!standardLog_ctx_js_1.ctx.gsl)
|
|
29
|
+
standardLog_ctx_js_1.ctx.gsl = closure;
|
|
29
30
|
return closure.standardLog;
|
|
30
31
|
}
|
|
31
32
|
exports.createStandardLog = createStandardLog;
|
|
@@ -100,31 +101,30 @@ function getLogger(id, options) {
|
|
|
100
101
|
return getGlobalSL().getLogger(id, options);
|
|
101
102
|
}
|
|
102
103
|
exports.getLogger = getLogger;
|
|
103
|
-
exports.ctx = (0, type_plus_1.record)();
|
|
104
104
|
function getGlobalSL() {
|
|
105
|
-
if (!
|
|
106
|
-
|
|
107
|
-
return
|
|
105
|
+
if (!standardLog_ctx_js_1.ctx.gsl)
|
|
106
|
+
standardLog_ctx_js_1.ctx.gsl = createStandardLogClosure();
|
|
107
|
+
return standardLog_ctx_js_1.ctx.gsl.standardLog;
|
|
108
108
|
}
|
|
109
109
|
function configGlobal(options) {
|
|
110
|
-
if (
|
|
111
|
-
var log =
|
|
110
|
+
if (standardLog_ctx_js_1.ctx.configured) {
|
|
111
|
+
var log = standardLog_ctx_js_1.ctx.gsl.standardLog.getLogger('standard-log');
|
|
112
112
|
log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.');
|
|
113
113
|
}
|
|
114
|
-
if (
|
|
114
|
+
if (standardLog_ctx_js_1.ctx.gsl) {
|
|
115
115
|
if (options.logLevel) {
|
|
116
|
-
|
|
116
|
+
standardLog_ctx_js_1.ctx.gsl.store.logLevel = options.logLevel;
|
|
117
117
|
}
|
|
118
118
|
if (options.reporters) {
|
|
119
|
-
var reporters =
|
|
119
|
+
var reporters = standardLog_ctx_js_1.ctx.gsl.store.reporters;
|
|
120
120
|
reporters.length = 0;
|
|
121
121
|
reporters.push.apply(reporters, options.reporters);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
else {
|
|
125
|
-
|
|
125
|
+
standardLog_ctx_js_1.ctx.gsl = createStandardLogClosure(options);
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
standardLog_ctx_js_1.ctx.configured = true;
|
|
128
128
|
}
|
|
129
129
|
exports.configGlobal = configGlobal;
|
|
130
130
|
//# sourceMappingURL=standardLog.js.map
|
package/cjs/standardLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uCAA4C;AAC5C,yCAA0C;AAC1C,+CAAoE;AACpE,6CAAwD;AACxD,yCAAwE;
|
|
1
|
+
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uCAA4C;AAC5C,yCAA0C;AAC1C,+CAAoE;AACpE,6CAAwD;AACxD,yCAAwE;AACxE,2DAA0C;AAM1C,SAAgB,iBAAiB,CAC/B,OAA+B;;IAE/B,IAAM,OAAO,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;IACjD,IAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,EAAE,EAAL,CAAK,CAAC,EAAE;QACxC,IAAM,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CA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AI,CAAC,wBAAG,CAAC,GAAG;QAAE,wBAAG,CAAC,GAAG,GAAG,wBAAwB,EAAE,CAAA;IAElD,OAAO,wBAAG,CAAC,GAAI,CAAC,WAAqC,CAAA;AACvD,CAAC;AAED,SAAgB,YAAY,CAAC,OAAiD;IAC5E,IAAI,wBAAG,CAAC,UAAU,EAAE;QAClB,IAAM,GAAG,GAAG,wBAAG,CAAC,GAAI,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QAC1D,GAAG,CAAC,IAAI,CAAC,kJAAkJ,CAAC,CAAA;KAC7J;IAED,IAAI,wBAAG,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,wBAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;SAC1C;QACD,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,IAAM,SAAS,GAAG,wBAAG,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAA;YACzC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAA;YACpB,SAAS,CAAC,IAAI,OAAd,SAAS,EAAS,OAAO,CAAC,SAAS,EAAC;SACrC;KACF;SACI;QACH,wBAAG,CAAC,GAAG,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;KAC5C;IACD,wBAAG,CAAC,UAAU,GAAG,IAAI,CAAA;AACvB,CAAC;AApBD,oCAoBC","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/cjs/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;
|
|
@@ -38,8 +38,15 @@ export declare type LogEntry = {
|
|
|
38
38
|
timestamp: Date;
|
|
39
39
|
};
|
|
40
40
|
export declare type LogMethod = (...args: any[]) => void;
|
|
41
|
-
export declare type LogFunction = (
|
|
41
|
+
export declare type LogFunction = (log: LogMethod, logLevel: number) => string | void;
|
|
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/cjs/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,aA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;CACnB,CAAA;AAED,oBAAY,QAAQ,GAAG,MAAM,CAAA;AAE7B,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC7B"}
|
package/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 = (
|
|
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, logLevel: number) => string | void\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"]}
|