standard-log 9.1.1 → 9.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +2 -3
  2. package/cjs/console.spec.js +1 -1
  3. package/cjs/console.spec.js.map +1 -1
  4. package/cjs/index.d.ts +2 -2
  5. package/cjs/index.d.ts.map +1 -1
  6. package/cjs/index.js +4 -4
  7. package/cjs/index.js.map +1 -1
  8. package/cjs/logStore.d.ts +2 -2
  9. package/cjs/logStore.d.ts.map +1 -1
  10. package/cjs/logStore.js.map +1 -1
  11. package/cjs/logger.d.ts +1 -2
  12. package/cjs/logger.d.ts.map +1 -1
  13. package/cjs/logger.js +6 -7
  14. package/cjs/logger.js.map +1 -1
  15. package/cjs/standardLog.d.ts +11 -3
  16. package/cjs/standardLog.d.ts.map +1 -1
  17. package/cjs/standardLog.js +40 -5
  18. package/cjs/standardLog.js.map +1 -1
  19. package/cjs/standardLog.spec.js +133 -85
  20. package/cjs/standardLog.spec.js.map +1 -1
  21. package/cjs/types.d.ts +3 -2
  22. package/cjs/types.d.ts.map +1 -1
  23. package/cjs/types.js.map +1 -1
  24. package/dist/standard-log.es5.js +1478 -92
  25. package/dist/standard-log.es5.js.gz +0 -0
  26. package/dist/standard-log.es5.js.map +1 -1
  27. package/dist/standard-log.es5.js.map.gz +0 -0
  28. package/dist/standard-log.esm.js +76 -81
  29. package/dist/standard-log.esm.js.gz +0 -0
  30. package/dist/standard-log.esm.js.map +1 -1
  31. package/dist/standard-log.esm.js.map.gz +0 -0
  32. package/esm/console.spec.js +1 -1
  33. package/esm/console.spec.js.map +1 -1
  34. package/esm/index.d.ts +2 -2
  35. package/esm/index.d.ts.map +1 -1
  36. package/esm/index.js +1 -2
  37. package/esm/index.js.map +1 -1
  38. package/esm/logStore.d.ts +2 -2
  39. package/esm/logStore.d.ts.map +1 -1
  40. package/esm/logStore.js +4 -2
  41. package/esm/logStore.js.map +1 -1
  42. package/esm/logger.d.ts +1 -2
  43. package/esm/logger.d.ts.map +1 -1
  44. package/esm/logger.js +5 -4
  45. package/esm/logger.js.map +1 -1
  46. package/esm/standardLog.d.ts +11 -3
  47. package/esm/standardLog.d.ts.map +1 -1
  48. package/esm/standardLog.js +38 -4
  49. package/esm/standardLog.js.map +1 -1
  50. package/esm/standardLog.spec.js +94 -46
  51. package/esm/standardLog.spec.js.map +1 -1
  52. package/esm/testUtil.js +2 -1
  53. package/esm/testUtil.js.map +1 -1
  54. package/esm/types.d.ts +3 -2
  55. package/esm/types.d.ts.map +1 -1
  56. package/esm/types.js.map +1 -1
  57. package/package.json +2 -2
  58. package/ts/index.ts +3 -3
  59. package/ts/logStore.ts +2 -2
  60. package/ts/logger.ts +2 -3
  61. package/ts/standardLog.ts +44 -6
  62. package/ts/types.ts +4 -2
  63. package/cjs/global.d.ts +0 -14
  64. package/cjs/global.d.ts.map +0 -1
  65. package/cjs/global.js +0 -39
  66. package/cjs/global.js.map +0 -1
  67. package/cjs/global.spec.d.ts +0 -2
  68. package/cjs/global.spec.d.ts.map +0 -1
  69. package/cjs/global.spec.js +0 -42
  70. package/cjs/global.spec.js.map +0 -1
  71. package/esm/global.d.ts +0 -14
  72. package/esm/global.d.ts.map +0 -1
  73. package/esm/global.js +0 -33
  74. package/esm/global.js.map +0 -1
  75. package/esm/global.spec.d.ts +0 -2
  76. package/esm/global.spec.d.ts.map +0 -1
  77. package/esm/global.spec.js +0 -40
  78. package/esm/global.spec.js.map +0 -1
  79. package/ts/global.ts +0 -43
package/esm/global.js DELETED
@@ -1,33 +0,0 @@
1
- import { record } from 'type-plus';
2
- import { createStandardLogClosure } from './standardLog.js';
3
- export function getLogger(params, meta) {
4
- return getGlobalSL().getLogger(params, meta);
5
- }
6
- export const ctx = record();
7
- function getGlobalSL() {
8
- if (!ctx.gsl)
9
- ctx.gsl = createStandardLogClosure();
10
- return ctx.gsl.standardLog;
11
- }
12
- export function configGlobal(options) {
13
- if (ctx.configured) {
14
- const log = ctx.gsl?.standardLog.getLogger(['standard-log']);
15
- log?.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.');
16
- }
17
- if (ctx.gsl) {
18
- if (options.logLevel) {
19
- ctx.gsl.store.logLevel = options.logLevel;
20
- }
21
- if (options.reporters) {
22
- const reporters = ctx.gsl.store.reporters;
23
- while (reporters.length > 0)
24
- reporters.pop();
25
- reporters.push(...options.reporters);
26
- }
27
- }
28
- else {
29
- ctx.gsl = createStandardLogClosure(options);
30
- }
31
- ctx.configured = true;
32
- }
33
- //# sourceMappingURL=global.js.map
package/esm/global.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"global.js","sourceRoot":"","sources":["../ts/global.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAElC,OAAO,EAAE,wBAAwB,EAAuB,MAAM,kBAAkB,CAAA;AAGhF,MAAM,UAAU,SAAS,CACvB,MAA6C,EAAE,IAAqB;IACpE,OAAO,WAAW,EAAK,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AACjD,CAAC;AAED,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAM,EAAE,CAAA;AAEZ,SAAS,WAAW;IAClB,IAAI,CAAC,GAAG,CAAC,GAAG;QAAE,GAAG,CAAC,GAAG,GAAG,wBAAwB,EAAE,CAAA;IAElD,OAAO,GAAG,CAAC,GAAI,CAAC,WAAqC,CAAA;AACvD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAiD;IAC5E,IAAI,GAAG,CAAC,UAAU,EAAE;QAClB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,CAAC,CAAA;QAC5D,GAAG,EAAE,IAAI,CAAC,kJAAkJ,CAAC,CAAA;KAC9J;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,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC;gBAAE,SAAS,CAAC,GAAG,EAAE,CAAA;YAC5C,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 { StackTraceMeta } from '@just-func/types'\nimport { record } from 'type-plus'\nimport { LogStore } from './logStore.js'\nimport { createStandardLogClosure, StandardLogInstance } from './standardLog.js'\nimport { LoggerOptions, LogMethodNames, StandardLogOptions } from './types.js'\n\nexport function getLogger<N extends string = LogMethodNames>(\n params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta) {\n return getGlobalSL<N>().getLogger(params, meta)\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"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=global.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"global.spec.d.ts","sourceRoot":"","sources":["../ts/global.spec.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import { a } from 'assertron';
2
- import { configGlobal, ctx } from './global.js';
3
- import { createMemoryLogReporter, getLogger, logLevels } from './index.js';
4
- describe('getLogger()', () => {
5
- it('gets a logger that logs to console by default', () => {
6
- const log = getLogger(['default']);
7
- log.info('from global log, expected to be printed');
8
- log.debug('from global log, this should not be printed');
9
- });
10
- });
11
- describe('configGlobal()', () => {
12
- beforeEach(() => {
13
- ctx.gsl = undefined;
14
- ctx.configured = false;
15
- });
16
- it('configure the global instance', () => {
17
- const mem = createMemoryLogReporter();
18
- configGlobal({ logLevel: logLevels.error, reporters: [mem] });
19
- const log = getLogger(['default']);
20
- log.error('error message');
21
- log.info('info message');
22
- expect(mem.logs.length).toBe(1);
23
- });
24
- it('can call after getLogger', () => {
25
- const log = getLogger(['default']);
26
- log.info('from global log, expected to be printed');
27
- const mem = createMemoryLogReporter();
28
- configGlobal({ logLevel: logLevels.error, reporters: [mem] });
29
- log.error('from global log, expected to be printed');
30
- log.info('from global log, this should not be printed');
31
- expect(mem.logs.length).toBe(1);
32
- });
33
- it('will emit a warning when called twice', () => {
34
- const mem = createMemoryLogReporter();
35
- configGlobal({ reporters: [mem] });
36
- configGlobal({ reporters: [] });
37
- a.satisfies(mem.logs, [{ id: 'standard-log', level: logLevels.warn, args: [/being called more than once/] }]);
38
- });
39
- });
40
- //# sourceMappingURL=global.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"global.spec.js","sourceRoot":"","sources":["../ts/global.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,WAAW,CAAA;AAC7B,OAA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,yCAAyC,CAAC,CAAA;QAEnD,MAAM,GAAG,GAAG,uBAAuB,EAAE,CAAA;QACrC,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC7D,GAAG,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAA;QACpD,GAAG,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAA;QACvD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;IACF,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,GAAG,GAAG,uBAAuB,EAAE,CAAA;QACrC,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAClC,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAA;QAC/B,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,6BAA6B,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/G,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { a } from 'assertron'\nimport { configGlobal, ctx } from './global.js'\nimport { createMemoryLogReporter, getLogger, logLevels } from './index.js'\n\ndescribe('getLogger()', () => {\n it('gets a logger that logs to console by default', () => {\n const log = getLogger(['default'])\n log.info('from global log, expected to be printed')\n log.debug('from global log, this should not be printed')\n })\n})\n\ndescribe('configGlobal()', () => {\n beforeEach(() => {\n ctx.gsl = undefined\n ctx.configured = false\n })\n it('configure the global instance', () => {\n const mem = createMemoryLogReporter()\n configGlobal({ logLevel: logLevels.error, reporters: [mem] })\n\n const log = getLogger(['default'])\n log.error('error message')\n log.info('info message')\n expect(mem.logs.length).toBe(1)\n })\n it('can call after getLogger', () => {\n const log = getLogger(['default'])\n log.info('from global log, expected to be printed')\n\n const mem = createMemoryLogReporter()\n configGlobal({ logLevel: logLevels.error, reporters: [mem] })\n log.error('from global log, expected to be printed')\n log.info('from global log, this should not be printed')\n expect(mem.logs.length).toBe(1)\n })\n it('will emit a warning when called twice', () => {\n const mem = createMemoryLogReporter()\n configGlobal({ reporters: [mem] })\n configGlobal({ reporters: [] })\n a.satisfies(mem.logs, [{ id: 'standard-log', level: logLevels.warn, args: [/being called more than once/] }])\n })\n})\n"]}
package/ts/global.ts DELETED
@@ -1,43 +0,0 @@
1
- import { StackTraceMeta } from '@just-func/types'
2
- import { record } from 'type-plus'
3
- import { LogStore } from './logStore.js'
4
- import { createStandardLogClosure, StandardLogInstance } from './standardLog.js'
5
- import { LoggerOptions, LogMethodNames, StandardLogOptions } from './types.js'
6
-
7
- export function getLogger<N extends string = LogMethodNames>(
8
- params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta) {
9
- return getGlobalSL<N>().getLogger(params, meta)
10
- }
11
-
12
- export const ctx: {
13
- configured?: boolean,
14
- gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }
15
- } = record()
16
-
17
- function getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {
18
- if (!ctx.gsl) ctx.gsl = createStandardLogClosure()
19
-
20
- return ctx.gsl!.standardLog as StandardLogInstance<N>
21
- }
22
-
23
- export function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {
24
- if (ctx.configured) {
25
- const log = ctx.gsl?.standardLog.getLogger(['standard-log'])
26
- log?.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.')
27
- }
28
-
29
- if (ctx.gsl) {
30
- if (options.logLevel) {
31
- ctx.gsl.store.logLevel = options.logLevel
32
- }
33
- if (options.reporters) {
34
- const reporters = ctx.gsl.store.reporters
35
- while (reporters.length > 0) reporters.pop()
36
- reporters.push(...options.reporters)
37
- }
38
- }
39
- else {
40
- ctx.gsl = createStandardLogClosure(options)
41
- }
42
- ctx.configured = true
43
- }