standard-log 9.1.6 → 10.0.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/cjs/console.js +1 -1
- package/cjs/console.js.map +1 -1
- package/cjs/console.spec.js +8 -0
- package/cjs/console.spec.js.map +1 -1
- package/cjs/formatter.d.ts +11 -1
- package/cjs/formatter.d.ts.map +1 -1
- package/cjs/formatter.js +15 -1
- package/cjs/formatter.js.map +1 -1
- package/cjs/logger.d.ts +1 -1
- package/cjs/logger.d.ts.map +1 -1
- package/cjs/logger.js.map +1 -1
- package/cjs/standardLog.d.ts +2 -2
- package/cjs/standardLog.d.ts.map +1 -1
- package/cjs/standardLog.js.map +1 -1
- package/cjs/standardLog.spec.js +2 -2
- package/cjs/standardLog.spec.js.map +1 -1
- package/cjs/types.d.ts +3 -3
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +181 -51
- 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 +59 -3
- 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.js +3 -3
- package/esm/console.js.map +1 -1
- package/esm/console.spec.js +8 -0
- package/esm/console.spec.js.map +1 -1
- package/esm/formatter.d.ts +11 -1
- package/esm/formatter.d.ts.map +1 -1
- package/esm/formatter.js +12 -0
- package/esm/formatter.js.map +1 -1
- package/esm/logger.d.ts +1 -1
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js.map +1 -1
- package/esm/standardLog.d.ts +2 -2
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js.map +1 -1
- package/esm/standardLog.spec.js +2 -2
- package/esm/standardLog.spec.js.map +1 -1
- package/esm/types.d.ts +3 -3
- package/esm/types.js.map +1 -1
- package/package.json +6 -6
- package/ts/console.ts +3 -3
- package/ts/formatter.ts +14 -1
- package/ts/logger.ts +3 -3
- package/ts/standardLog.ts +1 -1
- package/ts/types.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "standard-log",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "The standard log library",
|
|
5
5
|
"homepage": "https://github.com/unional/standard-log/tree/master/packages/log",
|
|
6
6
|
"bugs": {
|
|
@@ -58,25 +58,25 @@
|
|
|
58
58
|
"@just-func/types": "^0.2.0",
|
|
59
59
|
"iso-error": "^4.3.5",
|
|
60
60
|
"ms": "^2.1.3",
|
|
61
|
-
"type-plus": "^4.
|
|
61
|
+
"type-plus": "^4.11.2",
|
|
62
62
|
"upper-case": "^2.0.2"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@size-limit/preset-small-lib": "^
|
|
65
|
+
"@size-limit/preset-small-lib": "^8.0.0",
|
|
66
66
|
"@types/ms": "^0.7.31",
|
|
67
67
|
"@types/ramda": "^0.28.13",
|
|
68
|
-
"assertron": "^
|
|
68
|
+
"assertron": "^10.0.0",
|
|
69
69
|
"compression-webpack-plugin": "^10.0.0",
|
|
70
70
|
"cross-env": "^7.0.3",
|
|
71
71
|
"depcheck": "^1.4.3",
|
|
72
72
|
"eslint": "^8.17.0",
|
|
73
|
-
"jest": "^
|
|
73
|
+
"jest": "^29.0.0",
|
|
74
74
|
"npm-run-all": "^4.1.5",
|
|
75
75
|
"param-case": "^3.0.4",
|
|
76
76
|
"pascal-case": "^3.1.2",
|
|
77
77
|
"ramda": "^0.28.0",
|
|
78
78
|
"rimraf": "^3.0.2",
|
|
79
|
-
"size-limit": "^
|
|
79
|
+
"size-limit": "^8.0.0",
|
|
80
80
|
"ts-jest": "^28.0.5",
|
|
81
81
|
"ts-loader": "^9.3.0",
|
|
82
82
|
"tslib": "^2.4.0",
|
package/ts/console.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { unpartial } from 'type-plus'
|
|
2
|
+
import { consoleFormatter } from './formatter.js'
|
|
3
3
|
import { logLevels } from './logLevels.js'
|
|
4
4
|
import { polyfill } from './platform.js'
|
|
5
5
|
import type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'
|
|
@@ -51,7 +51,7 @@ export type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }
|
|
|
51
51
|
export type ConsoleLogReporterOptions = LogReporterOptions<any[]>
|
|
52
52
|
|
|
53
53
|
export function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {
|
|
54
|
-
const { id, formatter, filter } =
|
|
54
|
+
const { id, formatter, filter } = unpartial({ id: 'console', formatter: consoleFormatter }, options)
|
|
55
55
|
if (!polyfill.console) polyfill.console = buildPolyfillConsole()
|
|
56
56
|
|
|
57
57
|
return Object.freeze({
|
package/ts/formatter.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { LogEntry } from './types.js'
|
|
|
5
5
|
|
|
6
6
|
export type TimestampFormat = 'none' | 'iso' | 'elapsed'
|
|
7
7
|
|
|
8
|
-
export function createTimestampFormatter(format: TimestampFormat) {
|
|
8
|
+
export function createTimestampFormatter(format: TimestampFormat): (timestamp: Date) => string | undefined {
|
|
9
9
|
switch (format) {
|
|
10
10
|
case 'none':
|
|
11
11
|
return (_timestamp: Date) => undefined
|
|
@@ -27,6 +27,19 @@ export function formatLogLevel(level: number) {
|
|
|
27
27
|
return `(${upperCase(toLogLevelName(level))})`
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Formats log entry as plain text with the following format:
|
|
32
|
+
* `timestamp id level ...args`
|
|
33
|
+
*
|
|
34
|
+
* This is typically useful for writing logs to file
|
|
35
|
+
*/
|
|
30
36
|
export function plainLogFormatter({ id, level, args, timestamp }: LogEntry) {
|
|
31
37
|
return [timestamp.toISOString(), id, formatLogLevel(level), ...args]
|
|
32
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Formats log entry like default console log.
|
|
42
|
+
*/
|
|
43
|
+
export function consoleFormatter({ args }: LogEntry) {
|
|
44
|
+
return args
|
|
45
|
+
}
|
package/ts/logger.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { LogStore } from './logStore.js'
|
|
|
5
5
|
import type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'
|
|
6
6
|
import { LogLevel } from './types.js'
|
|
7
7
|
|
|
8
|
-
export function createLogger<
|
|
8
|
+
export function createLogger<N extends string = LogMethodNames>(
|
|
9
9
|
store: LogStore, id: string, options?: LoggerOptions
|
|
10
|
-
): Logger {
|
|
10
|
+
): Logger<N | LogMethodNames> {
|
|
11
11
|
validateId(id, options)
|
|
12
12
|
const writeTo = options?.writeTo ?? (() => true)
|
|
13
13
|
const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'
|
|
@@ -44,7 +44,7 @@ export function createLogger<T extends string = LogMethodNames>(
|
|
|
44
44
|
},
|
|
45
45
|
on: {
|
|
46
46
|
writable: false,
|
|
47
|
-
value: (level: number |
|
|
47
|
+
value: (level: number | N | LogMethodNames, logFn: LogFunction) => {
|
|
48
48
|
const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level
|
|
49
49
|
if (shouldLog(store, logLevel, logger.level)) {
|
|
50
50
|
const methodName = store.logLevelStore.getName(logLevel)
|
package/ts/standardLog.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
|
9
9
|
logLevel: number,
|
|
10
10
|
toLogLevelName(level: number): string,
|
|
11
11
|
toLogLevel(name: N): number,
|
|
12
|
-
getLogger(id: string, options?: LoggerOptions): Logger<N>
|
|
12
|
+
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
|
package/ts/types.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface LoggerOptions extends StackTraceMeta {
|
|
|
11
11
|
writeTo?: LogReporter | ReporterFilter
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export type Logger<
|
|
14
|
+
export type Logger<N extends string = LogMethodNames> = {
|
|
15
15
|
readonly id: string,
|
|
16
16
|
/**
|
|
17
17
|
* Logger local log level.
|
|
@@ -22,12 +22,12 @@ export type Logger<T extends string = LogMethodNames> = {
|
|
|
22
22
|
* This is useful during debugging to check for steps executed.
|
|
23
23
|
*/
|
|
24
24
|
count(...args: any[]): void,
|
|
25
|
-
on(level: number |
|
|
25
|
+
on(level: number | N, logFunction: LogFunction): void,
|
|
26
26
|
/**
|
|
27
27
|
* Write custom log entries.
|
|
28
28
|
*/
|
|
29
29
|
write(entry: LogEntry): void
|
|
30
|
-
} & { [k in
|
|
30
|
+
} & { [k in N]: LogMethod }
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Names of the standard log methods.
|