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.
- 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 -2
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +4 -4
- 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 +11 -3
- package/cjs/standardLog.d.ts.map +1 -1
- package/cjs/standardLog.js +40 -5
- package/cjs/standardLog.js.map +1 -1
- package/cjs/standardLog.spec.js +133 -85
- 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 +1478 -92
- 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 +76 -81
- 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 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -2
- 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 +11 -3
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js +38 -4
- package/esm/standardLog.js.map +1 -1
- package/esm/standardLog.spec.js +94 -46
- 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 +2 -2
- package/ts/index.ts +3 -3
- package/ts/logStore.ts +2 -2
- package/ts/logger.ts +2 -3
- package/ts/standardLog.ts +44 -6
- package/ts/types.ts +4 -2
- package/cjs/global.d.ts +0 -14
- package/cjs/global.d.ts.map +0 -1
- package/cjs/global.js +0 -39
- package/cjs/global.js.map +0 -1
- package/cjs/global.spec.d.ts +0 -2
- package/cjs/global.spec.d.ts.map +0 -1
- package/cjs/global.spec.js +0 -42
- package/cjs/global.spec.js.map +0 -1
- package/esm/global.d.ts +0 -14
- package/esm/global.d.ts.map +0 -1
- package/esm/global.js +0 -33
- package/esm/global.js.map +0 -1
- package/esm/global.spec.d.ts +0 -2
- package/esm/global.spec.d.ts.map +0 -1
- package/esm/global.spec.js +0 -40
- package/esm/global.spec.js.map +0 -1
- 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"]}
|
package/esm/global.spec.d.ts
DELETED
package/esm/global.spec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global.spec.d.ts","sourceRoot":"","sources":["../ts/global.spec.ts"],"names":[],"mappings":""}
|
package/esm/global.spec.js
DELETED
|
@@ -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
|
package/esm/global.spec.js.map
DELETED
|
@@ -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,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE1E,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;QAClC,GAAG,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAA;QACnD,GAAG,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAC1D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,UAAU,CAAC,GAAG,EAAE;QACd,GAAG,CAAC,GAAG,GAAG,SAAS,CAAA;QACnB,GAAG,CAAC,UAAU,GAAG,KAAK,CAAA;IACxB,CAAC,CAAC,CAAA;IACF,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,GAAG,GAAG,uBAAuB,EAAE,CAAA;QACrC,YAAY,CAAC,E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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
|
-
}
|