@likec4/log 1.46.0 → 1.48.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/LICENSE +1 -1
- package/dist/_chunks/libs/is-error-instance.mjs +26 -0
- package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
- package/dist/_chunks/libs/merge-error-cause.mjs +746 -0
- package/dist/_chunks/libs/safe-stringify.mjs +21 -0
- package/dist/index.d.mts +27 -16
- package/dist/index.mjs +189 -1423
- package/package.json +7 -7
- package/src/formatters.ts +28 -20
- package/src/index.ts +7 -3
- package/src/sink.ts +31 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@likec4/log",
|
|
3
3
|
"description": "Shared interface for logging",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.48.0",
|
|
6
6
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
7
7
|
"homepage": "https://likec4.dev",
|
|
8
8
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -32,22 +32,22 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@logtape/logtape": "^
|
|
35
|
+
"@logtape/logtape": "^1.3.5",
|
|
36
|
+
"std-env": "^3.10.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@types/node": "~22.19.
|
|
39
|
+
"@types/node": "~22.19.7",
|
|
39
40
|
"merge-error-cause": "^5.0.2",
|
|
40
41
|
"safe-stringify": "^1.2.0",
|
|
41
|
-
"std-env": "^3.10.0",
|
|
42
42
|
"typescript": "5.9.3",
|
|
43
|
-
"
|
|
43
|
+
"obuild": "^0.4.20",
|
|
44
44
|
"wrap-error-message": "^3.0.1",
|
|
45
|
-
"@likec4/tsconfig": "1.
|
|
45
|
+
"@likec4/tsconfig": "1.48.0",
|
|
46
46
|
"@likec4/devops": "1.42.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"typecheck": "tsc -b --verbose",
|
|
50
|
-
"build": "
|
|
50
|
+
"build": "obuild",
|
|
51
51
|
"pack": "pnpm pack",
|
|
52
52
|
"lint:package": "pnpx publint ./package.tgz",
|
|
53
53
|
"clean": "likec4ops clean"
|
package/src/formatters.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AnsiColorFormatterOptions,
|
|
3
|
-
type
|
|
3
|
+
type ConsoleFormatter,
|
|
4
4
|
type FormattedValues,
|
|
5
5
|
type LogLevel,
|
|
6
6
|
type LogRecord,
|
|
7
|
-
type Sink,
|
|
8
7
|
type TextFormatter,
|
|
9
8
|
type TextFormatterOptions,
|
|
10
9
|
getAnsiColorFormatter as getLogtapeAnsiColorFormatter,
|
|
11
|
-
getConsoleSink as getLogtapeConsoleSink,
|
|
12
10
|
getTextFormatter as getLogtapeTextFormatter,
|
|
13
11
|
} from '@logtape/logtape'
|
|
14
12
|
import mergeErrorCause from 'merge-error-cause'
|
|
@@ -128,26 +126,36 @@ export function getAnsiColorFormatter(options?: AnsiColorFormatterOptions): Text
|
|
|
128
126
|
})
|
|
129
127
|
}
|
|
130
128
|
|
|
131
|
-
export function getConsoleSink(options?: ConsoleSinkOptions): Sink {
|
|
132
|
-
return getLogtapeConsoleSink({
|
|
133
|
-
formatter: getAnsiColorFormatter(),
|
|
134
|
-
...options,
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
129
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
130
|
+
* The formatter returns an array where:
|
|
131
|
+
* - First element is the formatted message string
|
|
132
|
+
* - Second element is the record properties object
|
|
141
133
|
*/
|
|
142
|
-
export function
|
|
143
|
-
|
|
134
|
+
export function getConsoleFormatter(options?: {
|
|
135
|
+
messageFormatter?: TextFormatter
|
|
136
|
+
}): ConsoleFormatter {
|
|
137
|
+
const formatter = options?.messageFormatter
|
|
138
|
+
if (formatter) {
|
|
139
|
+
return (record: LogRecord) => {
|
|
140
|
+
const { properties } = record
|
|
141
|
+
if (properties && Object.keys(properties).length > 0) {
|
|
142
|
+
return [
|
|
143
|
+
formatter(record),
|
|
144
|
+
properties,
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
return [formatter(record)]
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
144
151
|
return (record: LogRecord) => {
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
const { message, properties } = record
|
|
153
|
+
if (properties && Object.keys(properties).length > 0) {
|
|
154
|
+
return [
|
|
155
|
+
...message,
|
|
156
|
+
properties,
|
|
157
|
+
]
|
|
151
158
|
}
|
|
159
|
+
return message
|
|
152
160
|
}
|
|
153
161
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
configureSync as configureLogtape,
|
|
4
4
|
getLogger,
|
|
5
5
|
} from '@logtape/logtape'
|
|
6
|
-
import { getConsoleSink } from './
|
|
6
|
+
import { getConsoleSink } from './sink'
|
|
7
7
|
|
|
8
8
|
export type {
|
|
9
9
|
Filter,
|
|
@@ -19,12 +19,16 @@ export {
|
|
|
19
19
|
// formatProperties,
|
|
20
20
|
// formatRecord,
|
|
21
21
|
getAnsiColorFormatter,
|
|
22
|
-
|
|
23
|
-
getConsoleStderrSink,
|
|
22
|
+
getConsoleFormatter,
|
|
24
23
|
getMessageOnlyFormatter,
|
|
25
24
|
getTextFormatter,
|
|
26
25
|
} from './formatters'
|
|
27
26
|
|
|
27
|
+
export {
|
|
28
|
+
getConsoleSink,
|
|
29
|
+
getConsoleStderrSink,
|
|
30
|
+
} from './sink'
|
|
31
|
+
|
|
28
32
|
export { withFilter } from '@logtape/logtape'
|
|
29
33
|
|
|
30
34
|
export const logger = getLogger('likec4')
|
package/src/sink.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ConsoleSinkOptions,
|
|
3
|
+
type LogRecord,
|
|
4
|
+
type Sink,
|
|
5
|
+
getConsoleSink as getLogtapeConsoleSink,
|
|
6
|
+
} from '@logtape/logtape'
|
|
7
|
+
import { getConsoleFormatter } from './formatters'
|
|
8
|
+
|
|
9
|
+
export function getConsoleSink(options?: ConsoleSinkOptions): Sink {
|
|
10
|
+
return getLogtapeConsoleSink({
|
|
11
|
+
formatter: getConsoleFormatter(),
|
|
12
|
+
...options,
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a console sink that writes to stderr.
|
|
18
|
+
* (MCP protocol requires stderr to be used for logging)
|
|
19
|
+
*/
|
|
20
|
+
export function getConsoleStderrSink(options?: ConsoleSinkOptions): Sink {
|
|
21
|
+
const formatter = options?.formatter ?? getConsoleFormatter()
|
|
22
|
+
return (record: LogRecord) => {
|
|
23
|
+
const args = formatter(record)
|
|
24
|
+
if (typeof args === 'string') {
|
|
25
|
+
const msg = args.replace(/\r?\n$/, '')
|
|
26
|
+
console.error(msg)
|
|
27
|
+
} else {
|
|
28
|
+
console.error(...args)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|