standard-log 9.1.2 → 9.1.5
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/logStore.d.ts +2 -2
- package/cjs/logStore.d.ts.map +1 -1
- package/cjs/logStore.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 +6 -9
- 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 +54 -48
- package/cjs/standardLog.spec.js.map +1 -1
- package/cjs/types.d.ts +3 -2
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +10141 -1665
- 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 +22 -12
- 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/logStore.d.ts +2 -2
- package/esm/logStore.d.ts.map +1 -1
- package/esm/logStore.js +4 -2
- package/esm/logStore.js.map +1 -1
- package/esm/logger.d.ts +1 -2
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +5 -4
- package/esm/logger.js.map +1 -1
- package/esm/standardLog.d.ts +6 -9
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js +7 -6
- package/esm/standardLog.js.map +1 -1
- package/esm/standardLog.spec.js +56 -49
- package/esm/standardLog.spec.js.map +1 -1
- package/esm/testUtil.js +2 -1
- package/esm/testUtil.js.map +1 -1
- package/esm/types.d.ts +3 -2
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +6 -6
- package/ts/index.ts +2 -2
- package/ts/logStore.ts +2 -2
- package/ts/logger.ts +2 -3
- package/ts/standardLog.ts +13 -11
- package/ts/types.ts +4 -2
package/README.md
CHANGED
|
@@ -32,7 +32,6 @@ For the full list of changes, please check the [change log](./CHANGELOG.md).
|
|
|
32
32
|
- Send logs to multiple reporters, e.g. console, file, memory, or remote service.
|
|
33
33
|
- Custom formatting and filtering for each reporter.
|
|
34
34
|
- Security focus. After the system is created, it cannot be changed.
|
|
35
|
-
- Compliant with the [`just-func`] paradigm.
|
|
36
35
|
|
|
37
36
|
## Usage
|
|
38
37
|
|
|
@@ -46,7 +45,7 @@ import { createStandardLog } from 'standard-log'
|
|
|
46
45
|
|
|
47
46
|
const standardLog = createStandarLog(/* options */)
|
|
48
47
|
|
|
49
|
-
const log = standardLog.getLogger(
|
|
48
|
+
const log = standardLog.getLogger('my-app')
|
|
50
49
|
|
|
51
50
|
log.error('error message')
|
|
52
51
|
log.warn('warn message')
|
|
@@ -60,7 +59,7 @@ log.debug('debug message')
|
|
|
60
59
|
|
|
61
60
|
(above is logged with `standard-log-color`)
|
|
62
61
|
|
|
63
|
-
You can configure a logger by doing `getLogger(
|
|
62
|
+
You can configure a logger by doing `getLogger(id, options)`:
|
|
64
63
|
|
|
65
64
|
`options.level: number`:
|
|
66
65
|
|
package/cjs/console.spec.js
CHANGED
package/cjs/console.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.spec.js","sourceRoot":"","sources":["../ts/console.spec.ts"],"names":[],"mappings":";;AAAA,mDAAoD;AACpD,uCAGmB;AACnB,6CAAwC;AAExC,QAAQ,CAAC,mB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WAAW,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;SAChE,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,SAAS,iBAAiB;IACxB,IAAM,MAAM,GAAU,EAAE,CAAA;IACxB,IAAM,KAAK,GAAU,EAAE,CAAA;IACvB,IAAM,KAAK,GAAU,EAAE,CAAA;IACvB,IAAM,MAAM,GAAU,EAAE,CAAA;IACxB,OAAO;QACL,MAAM,QAAA;QACN,KAAK,OAAA;QACL,KAAK,OAAA;QACL,MAAM,QAAA;QACN,KAAK,EAAL;YAAM,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QAC3C,IAAI,EAAJ;YAAK,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QACzC,IAAI,EAAJ;YAAK,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QACzC,KAAK,EAAL;YAAM,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;KAC5C,CAAA;AACH,CAAC","sourcesContent":["import { createStandardLog } from './standardLog.js'\nimport {\n ConsoleLogFormatter, createConsoleLogReporter,\n LogFilter, logLevels, plainLogFormatter, toConsoleMethod\n} from './index.js'\nimport { polyfill } from './platform.js'\n\ndescribe('toConsoleMethod()', () => {\n it('converts any level to standard console method names: debug, info, warn, error', () => {\n expect(toConsoleMethod(1)).toEqual('error')\n expect(toConsoleMethod(399)).toEqual('error')\n expect(toConsoleMethod(400)).toEqual('error')\n\n expect(toConsoleMethod(401)).toEqual('warn')\n expect(toConsoleMethod(499)).toEqual('warn')\n expect(toConsoleMethod(500)).toEqual('warn')\n\n expect(toConsoleMethod(501)).toEqual('info')\n expect(toConsoleMethod(700)).toEqual('info')\n\n expect(toConsoleMethod(701)).toEqual('debug')\n expect(toConsoleMethod(800)).toEqual('debug')\n expect(toConsoleMethod(801)).toEqual('debug')\n expect(toConsoleMethod(Infinity)).toEqual('debug')\n })\n it('converts to debug for 0 (none) or negative (not valid) level', () => {\n // these are invalid input.\n // so instead of hiding them and not logged,\n // log them so that it is easier to discover.\n expect(toConsoleMethod(-1)).toEqual('debug')\n expect(toConsoleMethod(0)).toEqual('debug')\n })\n})\ndescribe('rendering tests', () => {\n test('plain rendering', () => {\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter });\n ['emergency', 'info', 'warn', 'debug'].forEach(level => {\n reporter.write({ id: 'plain', level: (logLevels as any)[level], args: ['hello', 'world'], timestamp: new Date() })\n })\n })\n})\n\n\ndescribe('createConsoleLogReporter', () => {\n let fakeConsole = createFakeConsole()\n beforeEach(() => polyfill.console = fakeConsole = createFakeConsole())\n\n describe('id', () => {\n test('default is \"console\"', () => {\n const reporter = createConsoleLogReporter()\n expect(reporter.id).toBe('console')\n })\n test('can be overridden', () => {\n const reporter = createConsoleLogReporter({ id: 'neo-console' })\n expect(reporter.id).toBe('neo-console')\n })\n })\n\n describe('log level', () => {\n test('error, alert, critical and emergency logs are written to console.error', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.critical, args: ['critical'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.alert, args: ['alert'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.error, args: ['error'], timestamp: new Date() })\n\n expect(fakeConsole.errors.length).toBe(4)\n })\n\n test('warn logs are written to console.warn', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.warn, args: ['warn'], timestamp: new Date() })\n\n expect(fakeConsole.warns.length).toBe(1)\n })\n\n test('notice and info logs are written to console.info', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.notice, args: ['notice'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.info, args: ['info'], timestamp: new Date() })\n\n expect(fakeConsole.infos.length).toBe(2)\n })\n\n\n test('debug, trace, and planck logs are written to console.debug', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.debug, args: ['debug'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.trace, args: ['trace'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.planck, args: ['planck'], timestamp: new Date() })\n\n expect(fakeConsole.debugs.length).toBe(3)\n })\n })\n\n describe('custom logs', () => {\n test('are written according to their log level value', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n const sl = createStandardLog({\n logLevel: logLevels.all,\n customLevels: {\n 'high': 50,\n 'important': 450,\n 'interest': 650,\n 'silly': 1000\n },\n reporters: [reporter]\n })\n const log = sl.getLogger([id])\n log.high('a')\n log.important('b')\n log.interest('c')\n log.silly('d')\n\n expect(fakeConsole.errors.length).toBe(1)\n expect(fakeConsole.warns.length).toBe(1)\n expect(fakeConsole.infos.length).toBe(1)\n expect(fakeConsole.debugs.length).toBe(1)\n })\n })\n\n const idFormatter: ConsoleLogFormatter = (entry) => [entry.id]\n\n describe('formatter', () => {\n test('use specific formatter', () => {\n const id = 'id-only'\n const reporter = createConsoleLogReporter({ formatter: idFormatter })\n expect(reporter.formatter).toBe(idFormatter)\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['id-only']])\n })\n })\n\n describe('filter', () => {\n const filter: LogFilter = (entry) => entry.id !== 'secret'\n test('use specific filter', () => {\n const reporter = createConsoleLogReporter({ formatter: idFormatter, filter })\n expect(reporter.filter).toBe(filter)\n\n reporter.write({ id: 'normal', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id: 'secret', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['normal']])\n })\n })\n\n test('write log entry with multiple arguments', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter })\n\n const entry = { id, level: logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() }\n\n reporter.write(entry)\n\n expect(fakeConsole.infos).toEqual([\n [entry.timestamp.toISOString(), 'log', '(INFO)', 'a', 'b', 'c']\n ])\n })\n})\n\nfunction createFakeConsole() {\n const errors: any[] = []\n const infos: any[] = []\n const warns: any[] = []\n const debugs: any[] = []\n return {\n errors,\n infos,\n warns,\n debugs,\n error(...args: any[]) { errors.push(args) },\n info(...args: any[]) { infos.push(args) },\n warn(...args: any[]) { warns.push(args) },\n debug(...args: any[]) { debugs.push(args) }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"console.spec.js","sourceRoot":"","sources":["../ts/console.spec.ts"],"names":[],"mappings":";;AAAA,mDAAoD;AACpD,uCAGmB;AACnB,6CAAwC;AAExC,QAAQ,CAAC,mBAAmB,EAAE;IAC5B,EAAE,CAAC,+EAA+E,EAAE;QAClF,MAAM,CAAC,IAAA,0BAAe,EAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC7C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAE7C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC5C,MAAM,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AAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QAC3C,IAAI,EAAJ;YAAK,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QACzC,IAAI,EAAJ;YAAK,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QACzC,KAAK,EAAL;YAAM,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;KAC5C,CAAA;AACH,CAAC","sourcesContent":["import { createStandardLog } from './standardLog.js'\nimport {\n ConsoleLogFormatter, createConsoleLogReporter,\n LogFilter, logLevels, plainLogFormatter, toConsoleMethod\n} from './index.js'\nimport { polyfill } from './platform.js'\n\ndescribe('toConsoleMethod()', () => {\n it('converts any level to standard console method names: debug, info, warn, error', () => {\n expect(toConsoleMethod(1)).toEqual('error')\n expect(toConsoleMethod(399)).toEqual('error')\n expect(toConsoleMethod(400)).toEqual('error')\n\n expect(toConsoleMethod(401)).toEqual('warn')\n expect(toConsoleMethod(499)).toEqual('warn')\n expect(toConsoleMethod(500)).toEqual('warn')\n\n expect(toConsoleMethod(501)).toEqual('info')\n expect(toConsoleMethod(700)).toEqual('info')\n\n expect(toConsoleMethod(701)).toEqual('debug')\n expect(toConsoleMethod(800)).toEqual('debug')\n expect(toConsoleMethod(801)).toEqual('debug')\n expect(toConsoleMethod(Infinity)).toEqual('debug')\n })\n it('converts to debug for 0 (none) or negative (not valid) level', () => {\n // these are invalid input.\n // so instead of hiding them and not logged,\n // log them so that it is easier to discover.\n expect(toConsoleMethod(-1)).toEqual('debug')\n expect(toConsoleMethod(0)).toEqual('debug')\n })\n})\ndescribe('rendering tests', () => {\n test('plain rendering', () => {\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter });\n ['emergency', 'info', 'warn', 'debug'].forEach(level => {\n reporter.write({ id: 'plain', level: (logLevels as any)[level], args: ['hello', 'world'], timestamp: new Date() })\n })\n })\n})\n\n\ndescribe('createConsoleLogReporter', () => {\n let fakeConsole = createFakeConsole()\n beforeEach(() => polyfill.console = fakeConsole = createFakeConsole())\n\n describe('id', () => {\n test('default is \"console\"', () => {\n const reporter = createConsoleLogReporter()\n expect(reporter.id).toBe('console')\n })\n test('can be overridden', () => {\n const reporter = createConsoleLogReporter({ id: 'neo-console' })\n expect(reporter.id).toBe('neo-console')\n })\n })\n\n describe('log level', () => {\n test('error, alert, critical and emergency logs are written to console.error', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.critical, args: ['critical'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.alert, args: ['alert'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.error, args: ['error'], timestamp: new Date() })\n\n expect(fakeConsole.errors.length).toBe(4)\n })\n\n test('warn logs are written to console.warn', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.warn, args: ['warn'], timestamp: new Date() })\n\n expect(fakeConsole.warns.length).toBe(1)\n })\n\n test('notice and info logs are written to console.info', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.notice, args: ['notice'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.info, args: ['info'], timestamp: new Date() })\n\n expect(fakeConsole.infos.length).toBe(2)\n })\n\n\n test('debug, trace, and planck logs are written to console.debug', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.debug, args: ['debug'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.trace, args: ['trace'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.planck, args: ['planck'], timestamp: new Date() })\n\n expect(fakeConsole.debugs.length).toBe(3)\n })\n })\n\n describe('custom logs', () => {\n test('are written according to their log level value', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n const sl = createStandardLog({\n logLevel: logLevels.all,\n customLevels: {\n 'high': 50,\n 'important': 450,\n 'interest': 650,\n 'silly': 1000\n },\n reporters: [reporter]\n })\n const log = sl.getLogger(id)\n log.high('a')\n log.important('b')\n log.interest('c')\n log.silly('d')\n\n expect(fakeConsole.errors.length).toBe(1)\n expect(fakeConsole.warns.length).toBe(1)\n expect(fakeConsole.infos.length).toBe(1)\n expect(fakeConsole.debugs.length).toBe(1)\n })\n })\n\n const idFormatter: ConsoleLogFormatter = (entry) => [entry.id]\n\n describe('formatter', () => {\n test('use specific formatter', () => {\n const id = 'id-only'\n const reporter = createConsoleLogReporter({ formatter: idFormatter })\n expect(reporter.formatter).toBe(idFormatter)\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['id-only']])\n })\n })\n\n describe('filter', () => {\n const filter: LogFilter = (entry) => entry.id !== 'secret'\n test('use specific filter', () => {\n const reporter = createConsoleLogReporter({ formatter: idFormatter, filter })\n expect(reporter.filter).toBe(filter)\n\n reporter.write({ id: 'normal', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id: 'secret', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['normal']])\n })\n })\n\n test('write log entry with multiple arguments', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter })\n\n const entry = { id, level: logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() }\n\n reporter.write(entry)\n\n expect(fakeConsole.infos).toEqual([\n [entry.timestamp.toISOString(), 'log', '(INFO)', 'a', 'b', 'c']\n ])\n })\n})\n\nfunction createFakeConsole() {\n const errors: any[] = []\n const infos: any[] = []\n const warns: any[] = []\n const debugs: any[] = []\n return {\n errors,\n infos,\n warns,\n debugs,\n error(...args: any[]) { errors.push(args) },\n info(...args: any[]) { infos.push(args) },\n warn(...args: any[]) { warns.push(args) },\n debug(...args: any[]) { debugs.push(args) }\n }\n}\n"]}
|
package/cjs/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './errors.js';
|
|
|
3
3
|
export * from './formatter.js';
|
|
4
4
|
export * from './logLevels.js';
|
|
5
5
|
export * from './memory.js';
|
|
6
|
-
export { configGlobal, createStandardLog, createStandardLogForTest, getLogger,
|
|
6
|
+
export { configGlobal, createStandardLog, createStandardLogForTest, getLogger, suppressLogs } from './standardLog.js';
|
|
7
|
+
export type { StandardLog, StandardLogInstance } from './standardLog.js';
|
|
7
8
|
export * from './types.js';
|
|
8
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,WAAW,EAAE,mBAAmB,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,WAAW,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACxE,cAAc,YAAY,CAAA"}
|
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;
|
|
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;AAGzB,6CAA0B","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 { StandardLog, StandardLogInstance } from './standardLog.js'\nexport * from './types.js'\n"]}
|
package/cjs/logStore.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Logger, LogLevel, LogReporter, StandardLogOptions } from './types.js';
|
|
2
|
-
export declare function createLogStore(options: Required<StandardLogOptions
|
|
1
|
+
import type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions } from './types.js';
|
|
2
|
+
export declare function createLogStore<N extends string = LogMethodNames>(options: Required<StandardLogOptions<N>>): LogStore;
|
|
3
3
|
export interface LogStore {
|
|
4
4
|
loggers: Record<string, Logger>;
|
|
5
5
|
reporters: LogReporter[];
|
package/cjs/logStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logStore.d.ts","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"logStore.d.ts","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEnG,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAAE,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAOpH;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA;CAChD;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACtC;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB;mBAWxC,MAAM;mBAGN,MAAM;;;;;EAWxB"}
|
package/cjs/logStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logStore.js","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":";;;AACA,uCAA0D;AAC1D,2CAAuD;AACvD,+CAAsE;AAGtE,SAAgB,cAAc,
|
|
1
|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AI,CAAC,EAAE,CAAC,CAAA;gBAEpF,OAAO,MAAM,CAAA;YACf,CAAC,EAAE,IAAA,kBAAM,EAAC,KAAK,CAAC,YAAY,EAAE,UAAA,IAAI,IAAI,OAAA,CAAC,EAAE,IAAI,MAAA,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,EAA3C,CAA2C,CAAC,CAAC,CAAA;QACrF,CAAC;KACF,CAAA;AACH,CAAC;AAzBD,sCAyBC","sourcesContent":["\nimport { mapKey, reduceByKey, reduceKey } from 'type-plus'\nimport { createConsoleLogReporter } from './console.js'\nimport { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'\nimport type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions } from './types.js'\n\nexport function createLogStore<N extends string = LogMethodNames>(options: Required<StandardLogOptions<N>>): LogStore {\n return {\n loggers: {},\n reporters: options.reporters || [createConsoleLogReporter()],\n logLevel: options.logLevel,\n logLevelStore: logLevelStore(options)\n }\n}\n\nexport interface LogStore {\n loggers: Record<string, Logger>,\n reporters: LogReporter[],\n logLevel: LogLevel,\n logLevelStore: ReturnType<typeof logLevelStore>\n}\n\nexport interface LogLevelStoreOptions {\n customLevels?: Record<string, number>\n}\n\nexport function logLevelStore(options: LogLevelStoreOptions) {\n const customLevels = options.customLevels || {}\n\n const store = {\n customLevels,\n customLevelsReverse: reduceByKey(customLevels, (p, k) => {\n p[customLevels[k]] = k\n return p\n }, {} as Record<number, string>)\n }\n return {\n getName(level: number) {\n return store.customLevelsReverse[level] ?? toLogLevelName(level)\n },\n getLevel(name: string) {\n return store.customLevels[name] ?? toLogLevel(name)\n },\n getAllLevels() {\n return reduceKey(logLevels, (result, name) => {\n if (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })\n\n return result\n }, mapKey(store.customLevels, name => ({ name, level: store.customLevels[name] })))\n }\n }\n}\n"]}
|
package/cjs/logger.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { StackTraceMeta } from '@just-func/types';
|
|
2
1
|
import { LogStore } from './logStore.js';
|
|
3
2
|
import type { Logger, LoggerOptions, LogMethodNames } from './types.js';
|
|
4
|
-
export declare function createLogger<T extends string = LogMethodNames>(
|
|
3
|
+
export declare function createLogger<T extends string = LogMethodNames>(store: LogStore, id: string, options?: LoggerOptions): Logger;
|
|
5
4
|
//# sourceMappingURL=logger.d.ts.map
|
package/cjs/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AAGA,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,CAyDR"}
|
package/cjs/logger.js
CHANGED
|
@@ -12,18 +12,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.createLogger = void 0;
|
|
13
13
|
var errors_js_1 = require("./errors.js");
|
|
14
14
|
var logLevels_js_1 = require("./logLevels.js");
|
|
15
|
-
function createLogger(
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
var _c = typeof writeTo === 'string'
|
|
15
|
+
function createLogger(store, id, options) {
|
|
16
|
+
var _a;
|
|
17
|
+
validateId(id, options);
|
|
18
|
+
var writeTo = (_a = options === null || options === void 0 ? void 0 : options.writeTo) !== null && _a !== void 0 ? _a : (function () { return true; });
|
|
19
|
+
var _b = typeof writeTo === 'string'
|
|
21
20
|
? [function (id) { return id === writeTo; }, store.reporters]
|
|
22
21
|
: writeTo instanceof RegExp
|
|
23
22
|
? [function (id) { return writeTo.test(id); }, store.reporters]
|
|
24
23
|
: typeof writeTo === 'function'
|
|
25
24
|
? [writeTo, store.reporters]
|
|
26
|
-
: [function () { return true; }, [writeTo]], filter =
|
|
25
|
+
: [function () { return true; }, [writeTo]], filter = _b[0], reporters = _b[1];
|
|
27
26
|
function write(entry) {
|
|
28
27
|
writeToReporters(reporters, entry, filter);
|
|
29
28
|
}
|
package/cjs/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yCAAuC;AACvC,+CAA0C;AAK1C,SAAgB,YAAY,CAC1B,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yCAAuC;AACvC,+CAA0C;AAK1C,SAAgB,YAAY,CAC1B,KAAe,EAAE,EAAU,EAAE,OAAuB;;IAEpD,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IACvB,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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C;IAC7G,SAAS,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAZ,CAAY,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,EAAlB,CAAkB,CAAC,CAAA;AACtE,CAAC;AAED;;;;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 type { StackTraceMeta } from '@just-func/types'\nimport { InvalidId } from './errors.js'\nimport { 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<T extends string = LogMethodNames>(\n store: LogStore, id: string, options?: LoggerOptions\n): Logger {\n validateId(id, options)\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 const level = logLevels.debug\n if (shouldLog(store, level, logger.level))\n write({\n id,\n level,\n args: [++counter, ...args],\n timestamp: new Date()\n })\n })(0)\n },\n on: {\n writable: false,\n value: (level: number | T, 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)\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 validateId(id: string, meta?: StackTraceMeta) {\n if (/[`~!#$%^&*()=+[\\]{},|<>?]/.test(id)) throw new InvalidId(id, meta)\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"]}
|
package/cjs/standardLog.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { StackTraceMeta } from '@just-func/types';
|
|
2
1
|
import { LogStore } from './logStore.js';
|
|
2
|
+
import { MemoryLogReporter } from './memory.js';
|
|
3
3
|
import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js';
|
|
4
4
|
export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
5
5
|
logLevel: number;
|
|
6
6
|
toLogLevelName(level: number): string;
|
|
7
7
|
toLogLevel(name: N): number;
|
|
8
|
-
getLogger(
|
|
8
|
+
getLogger(id: string, options?: LoggerOptions): Logger<N>;
|
|
9
9
|
}
|
|
10
10
|
export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
|
|
11
11
|
}
|
|
@@ -14,18 +14,15 @@ export declare function createStandardLogClosure<N extends string = LogMethodNam
|
|
|
14
14
|
store: LogStore;
|
|
15
15
|
standardLog: StandardLog<N>;
|
|
16
16
|
};
|
|
17
|
-
export declare
|
|
18
|
-
reporter:
|
|
19
|
-
logLevel: number;
|
|
20
|
-
toLogLevelName: (level: number) => string;
|
|
21
|
-
toLogLevel: (name: LogMethodNames) => number;
|
|
22
|
-
getLogger: (params: [id: string, options?: LoggerOptions | undefined], meta?: StackTraceMeta | undefined) => Logger<LogMethodNames>;
|
|
17
|
+
export declare type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
|
|
18
|
+
reporter: MemoryLogReporter;
|
|
23
19
|
};
|
|
20
|
+
export declare function createStandardLogForTest<N extends string = LogMethodNames>(logLevel?: LogLevel): StandardLogForTest<N>;
|
|
24
21
|
/**
|
|
25
22
|
* Suppress logging within the code block.
|
|
26
23
|
*/
|
|
27
24
|
export declare function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R;
|
|
28
|
-
export declare function getLogger<N extends string = LogMethodNames>(
|
|
25
|
+
export declare function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions): Logger<N>;
|
|
29
26
|
export declare const ctx: {
|
|
30
27
|
configured?: boolean;
|
|
31
28
|
gsl?: {
|
package/cjs/standardLog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardLog.d.ts","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"
|
|
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;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAErG,MAAM,WAAW,mBAAmB,CAAC,CAA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AE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,aAE/F;AAED,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;AAQZ,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC,QAoB7E"}
|
package/cjs/standardLog.js
CHANGED
|
@@ -36,11 +36,10 @@ function createStandardLogClosure(options) {
|
|
|
36
36
|
toLogLevel: function (name) {
|
|
37
37
|
return store.logLevelStore.getLevel(name);
|
|
38
38
|
},
|
|
39
|
-
getLogger: function (
|
|
40
|
-
var id = _a[0], options = _a[1];
|
|
39
|
+
getLogger: function (id, options) {
|
|
41
40
|
if (store.loggers[id])
|
|
42
41
|
return store.loggers[id];
|
|
43
|
-
return store.loggers[id] = (0, logger_js_1.createLogger)(
|
|
42
|
+
return store.loggers[id] = (0, logger_js_1.createLogger)(store, id, __assign({ ssf: this.getLogger }, options));
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
};
|
|
@@ -65,8 +64,8 @@ function suppressLogs(block) {
|
|
|
65
64
|
return result;
|
|
66
65
|
}
|
|
67
66
|
exports.suppressLogs = suppressLogs;
|
|
68
|
-
function getLogger(
|
|
69
|
-
return getGlobalSL().getLogger(
|
|
67
|
+
function getLogger(id, options) {
|
|
68
|
+
return getGlobalSL().getLogger(id, options);
|
|
70
69
|
}
|
|
71
70
|
exports.getLogger = getLogger;
|
|
72
71
|
exports.ctx = (0, type_plus_1.record)();
|
|
@@ -78,7 +77,7 @@ function getGlobalSL() {
|
|
|
78
77
|
function configGlobal(options) {
|
|
79
78
|
var _a;
|
|
80
79
|
if (exports.ctx.configured) {
|
|
81
|
-
var log = (_a = exports.ctx.gsl) === null || _a === void 0 ? void 0 : _a.standardLog.getLogger(
|
|
80
|
+
var log = (_a = exports.ctx.gsl) === null || _a === void 0 ? void 0 : _a.standardLog.getLogger('standard-log');
|
|
82
81
|
log === null || log === void 0 ? void 0 : log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.');
|
|
83
82
|
}
|
|
84
83
|
if (exports.ctx.gsl) {
|
package/cjs/standardLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uCAA4C;AAC5C,yCAA0C;AAC1C,+CAA0C;AAC1C,6CAAwD;AACxD,yCAAwE;AAaxE,SAAgB,iBAAiB,CAC/B,OAA+B;IAE/B,IAAM,OAAO,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;IACjD,IAAI,CAAC,WAAG,CAAC,GAAG;QAAE,WAAG,CAAC,GAAG,GAAG,OAAc,CAAA;IACtC,OAAO,OAAO,CAAC,WAAW,CAAA;AAC5B,CAAC;AAND,8CAMC;AAED,SAAgB,wBAAwB,CACtC,OAA+B;IAE/B,IAAM,KAAK,GAAG,IAAA,4BAAc,EAAC,IAAA,oBAAQ,EAAC,EAAE,QAAQ,EAAE,wBAAS,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;IAE7E,OAAO;QACL,KAAK,OAAA;QACL,WAAW,EAAE;YACX,IAAI,QAAQ,KAAK,OAAO,KAAK,CAAC,QAAQ,CAAA,CAAC,CAAC;YAExC,cAAc,EAAd,UAAe,KAAa;gBAC1B,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAC3C,CAAC;YACD,UAAU,EAAV,UAAW,IAAY;gBACrB,OAAO,KAAK,CAA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B,CAAC;AApBD,oCAoBC","sourcesContent":["import { record, required } from 'type-plus'\nimport { createLogger } from './logger.js'\nimport { logLevels } from './logLevels.js'\nimport { createLogStore, LogStore } from './logStore.js'\nimport { createMemoryLogReporter, MemoryLogReporter } from './memory.js'\nimport type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js'\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>\n}\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 (!ctx.gsl) ctx.gsl = closure as any\n return closure.standardLog\n}\n\nexport function createStandardLogClosure<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): { store: LogStore, standardLog: StandardLog<N> } {\n const store = createLogStore(required({ logLevel: logLevels.info }, options))\n\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 }\n }\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 standardLog = createStandardLog<N>({ reporters: [reporter], logLevel })\n return { ...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 function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {\n return getGlobalSL<N>().getLogger(id, options)\n}\n\nexport const ctx: {\n configured?: boolean,\n gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }\n} = record()\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 while (reporters.length > 0) reporters.pop()\n reporters.push(...options.reporters)\n }\n }\n else {\n ctx.gsl = createStandardLogClosure(options)\n }\n ctx.configured = true\n}\n"]}
|