standard-log 9.1.0 → 9.1.3
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 +35 -5
- 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/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 +2 -1
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +50 -59
- 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 +55 -65
- 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/logger.d.ts +1 -2
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +2 -2
- 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 +37 -4
- package/esm/standardLog.js.map +1 -1
- package/esm/standardLog.spec.js +93 -46
- package/esm/standardLog.spec.js.map +1 -1
- package/esm/types.d.ts +2 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +1 -1
- package/ts/index.ts +3 -3
- package/ts/logger.ts +2 -3
- package/ts/standardLog.ts +44 -6
- package/ts/types.ts +3 -1
- package/cjs/global.d.ts +0 -13
- package/cjs/global.d.ts.map +0 -1
- package/cjs/global.js +0 -33
- 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 -32
- package/cjs/global.spec.js.map +0 -1
- package/esm/global.d.ts +0 -13
- package/esm/global.d.ts.map +0 -1
- package/esm/global.js +0 -28
- 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 -30
- package/esm/global.spec.js.map +0 -1
- package/ts/global.ts +0 -34
package/esm/global.spec.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { configGlobal, ctx } from './global.js';
|
|
2
|
-
import { createMemoryLogReporter, getLogger, logLevels } from './index.js';
|
|
3
|
-
describe('getLogger()', () => {
|
|
4
|
-
it('gets a logger that logs to console by default', () => {
|
|
5
|
-
const log = getLogger(['default']);
|
|
6
|
-
log.info('from global log, expected to be printed');
|
|
7
|
-
log.debug('from global log, this should not be printed');
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
|
-
describe('configGlobal()', () => {
|
|
11
|
-
beforeEach(() => ctx.gsl = undefined);
|
|
12
|
-
it('configure the global instance', () => {
|
|
13
|
-
const mem = createMemoryLogReporter();
|
|
14
|
-
configGlobal({ logLevel: logLevels.error, reporters: [mem] });
|
|
15
|
-
const log = getLogger(['default']);
|
|
16
|
-
log.error('error message');
|
|
17
|
-
log.info('info message');
|
|
18
|
-
expect(mem.logs.length).toBe(1);
|
|
19
|
-
});
|
|
20
|
-
it('can call after getLogger', () => {
|
|
21
|
-
const log = getLogger(['default']);
|
|
22
|
-
log.info('from global log, expected to be printed');
|
|
23
|
-
const mem = createMemoryLogReporter();
|
|
24
|
-
configGlobal({ logLevel: logLevels.error, reporters: [mem] });
|
|
25
|
-
log.error('from global log, expected to be printed');
|
|
26
|
-
log.info('from global log, this should not be printed');
|
|
27
|
-
expect(mem.logs.length).toBe(1);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
//# 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,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,CAAC,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC,CAAA;IACrC,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,GAAG,GAAG,uBAAuB,EAAE,CAAA;QACrC,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAE7D,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;QAClC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;QAC1B,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QACxB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;IACF,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;QAClC,GAAG,CAAC,IAAI,CAAC,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;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { 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(() => ctx.gsl = undefined)\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})\n"]}
|
package/ts/global.ts
DELETED
|
@@ -1,34 +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: { gsl?: { store: LogStore, standardLog: StandardLogInstance<any> } } = record()
|
|
13
|
-
|
|
14
|
-
function getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {
|
|
15
|
-
if (!ctx.gsl) configGlobal({})
|
|
16
|
-
|
|
17
|
-
return ctx.gsl!.standardLog
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function configGlobal<N extends string = LogMethodNames>(options: Omit<StandardLogOptions, 'customLevels'>) {
|
|
21
|
-
if (ctx.gsl) {
|
|
22
|
-
if (options.logLevel) {
|
|
23
|
-
ctx.gsl.store.logLevel = options.logLevel
|
|
24
|
-
}
|
|
25
|
-
if (options.reporters) {
|
|
26
|
-
const reporters = ctx.gsl.store.reporters
|
|
27
|
-
while (reporters.length > 0) reporters.pop()
|
|
28
|
-
reporters.push(...options.reporters)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
ctx.gsl = createStandardLogClosure<N>(options)
|
|
33
|
-
}
|
|
34
|
-
}
|