@likec4/log 1.18.0 → 1.19.1
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/dist/browser.cjs +1465 -9
- package/dist/browser.mjs +1465 -10
- package/dist/chunks/prompt.cjs +201 -132
- package/dist/chunks/prompt.mjs +199 -130
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +357 -12
- package/dist/index.d.mts +357 -12
- package/dist/index.d.ts +357 -12
- package/dist/index.mjs +1 -1
- package/dist/shared/log.BjyNw23f.mjs +2823 -0
- package/dist/shared/log.DQnPBfHC.cjs +2846 -0
- package/package.json +10 -11
- package/src/browser.ts +16 -0
- package/src/format.ts +60 -0
- package/src/index.ts +36 -0
- package/dist/shared/log.BEan6jB3.cjs +0 -1366
- package/dist/shared/log.BMY8Anc1.mjs +0 -1343
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/log",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.19.1",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
7
7
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
|
-
"
|
|
10
|
+
"src"
|
|
11
11
|
],
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -15,12 +15,9 @@
|
|
|
15
15
|
"directory": "packages/log"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
|
-
"main": "./dist/index.cjs",
|
|
19
|
-
"module": "./dist/index.mjs",
|
|
20
|
-
"browser": "./dist/browser.mjs",
|
|
21
|
-
"types": "./dist/index.d.ts",
|
|
22
18
|
"exports": {
|
|
23
19
|
".": {
|
|
20
|
+
"sources": "./src/index.ts",
|
|
24
21
|
"node": {
|
|
25
22
|
"types": "./dist/index.d.ts",
|
|
26
23
|
"import": "./dist/index.mjs",
|
|
@@ -44,16 +41,18 @@
|
|
|
44
41
|
},
|
|
45
42
|
"scripts": {
|
|
46
43
|
"typecheck": "tsc --noEmit",
|
|
47
|
-
"
|
|
48
|
-
"generate": "unbuild"
|
|
44
|
+
"build": "unbuild"
|
|
49
45
|
},
|
|
50
46
|
"devDependencies": {
|
|
51
|
-
"@likec4/tsconfig": "1.
|
|
47
|
+
"@likec4/tsconfig": "1.19.1",
|
|
52
48
|
"@types/node": "^20.17.7",
|
|
53
|
-
"consola": "^3.
|
|
49
|
+
"consola": "^3.3.3",
|
|
50
|
+
"merge-error-cause": "^5.0.0",
|
|
51
|
+
"safe-stringify": "^1.1.1",
|
|
54
52
|
"std-env": "^3.8.0",
|
|
55
53
|
"typescript": "^5.7.2",
|
|
56
|
-
"unbuild": "^3.
|
|
54
|
+
"unbuild": "^3.1.0",
|
|
55
|
+
"wrap-error-message": "^3.0.0"
|
|
57
56
|
},
|
|
58
57
|
"packageManager": "yarn@4.5.3"
|
|
59
58
|
}
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createConsola } from 'consola/browser'
|
|
2
|
+
import { type LogObject, LogLevels } from 'consola/core'
|
|
3
|
+
import { type FormattedLogObject, formattedLogObj } from './format'
|
|
4
|
+
|
|
5
|
+
export type * from 'consola/core'
|
|
6
|
+
export type { FormattedLogObject }
|
|
7
|
+
|
|
8
|
+
const consola = createConsola({
|
|
9
|
+
level: LogLevels.debug,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export function formatLogObj(logObj: LogObject): FormattedLogObject {
|
|
13
|
+
return formattedLogObj(logObj)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { consola, consola as logger, consola as rootLogger, LogLevels }
|
package/src/format.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { LogObject } from 'consola/core'
|
|
2
|
+
import mergeErrorCause from 'merge-error-cause'
|
|
3
|
+
import safeStringify from 'safe-stringify'
|
|
4
|
+
import wrapErrorMessage from 'wrap-error-message'
|
|
5
|
+
|
|
6
|
+
export type FormattedLogObject = {
|
|
7
|
+
message: string
|
|
8
|
+
error?: {
|
|
9
|
+
message: string
|
|
10
|
+
name: string
|
|
11
|
+
stack?: string
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const defaultParseStack = (stack: string): string[] => {
|
|
16
|
+
const lines = stack.split('\n').map((l) => l.trim().replace('file://', ''))
|
|
17
|
+
return lines
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function formattedLogObj(
|
|
21
|
+
logObj: LogObject,
|
|
22
|
+
parseStack = defaultParseStack,
|
|
23
|
+
): FormattedLogObject {
|
|
24
|
+
const result: FormattedLogObject = {
|
|
25
|
+
message: '',
|
|
26
|
+
}
|
|
27
|
+
const error = logObj.args.find(a => a instanceof Error)
|
|
28
|
+
if (!error) {
|
|
29
|
+
result.message = logObj.args.map(arg => typeof arg === 'string' ? arg : safeStringify(arg)).join('; ')
|
|
30
|
+
if (typeof logObj.tag === 'string' && logObj.tag.length > 0) {
|
|
31
|
+
result.message = `[${logObj.tag}] ${result.message}`
|
|
32
|
+
}
|
|
33
|
+
return result
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const mergedErr = logObj.args.reduce(
|
|
37
|
+
(acc: Error, arg) => {
|
|
38
|
+
if (arg === error) {
|
|
39
|
+
return acc
|
|
40
|
+
}
|
|
41
|
+
const msg = typeof arg === 'string' ? arg : safeStringify(arg)
|
|
42
|
+
return wrapErrorMessage(acc, msg)
|
|
43
|
+
},
|
|
44
|
+
mergeErrorCause(error),
|
|
45
|
+
)
|
|
46
|
+
result.message = mergedErr.message
|
|
47
|
+
result.error = {
|
|
48
|
+
message: mergedErr.message,
|
|
49
|
+
name: mergedErr.name,
|
|
50
|
+
}
|
|
51
|
+
if (mergedErr.stack) {
|
|
52
|
+
const stack = parseStack(mergedErr.stack)
|
|
53
|
+
result.error.stack = stack.join('\n')
|
|
54
|
+
result.message += '\n' + stack.slice(1).map(l => ' ' + l).join('\n')
|
|
55
|
+
}
|
|
56
|
+
if (typeof logObj.tag === 'string' && logObj.tag.length > 0) {
|
|
57
|
+
result.message = `[${logObj.tag}] ${result.message}`
|
|
58
|
+
}
|
|
59
|
+
return result
|
|
60
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createConsola } from 'consola'
|
|
2
|
+
import { type LogObject, LogLevels } from 'consola/core'
|
|
3
|
+
import { sep } from 'node:path'
|
|
4
|
+
import { cwd } from 'node:process'
|
|
5
|
+
import { type FormattedLogObject, formattedLogObj } from './format'
|
|
6
|
+
|
|
7
|
+
export type * from 'consola/core'
|
|
8
|
+
export type { FormattedLogObject }
|
|
9
|
+
|
|
10
|
+
function parseStack(stack: string): string[] {
|
|
11
|
+
const currentDir = cwd() + sep
|
|
12
|
+
const lines = stack.split('\n').map((l) => l.trim().replace('file://', '').replace(currentDir, ''))
|
|
13
|
+
return lines
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function formatLogObj(logObj: LogObject): FormattedLogObject {
|
|
17
|
+
return formattedLogObj(logObj, parseStack)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const level = LogLevels.debug
|
|
21
|
+
|
|
22
|
+
const consola = createConsola({
|
|
23
|
+
level,
|
|
24
|
+
defaults: {
|
|
25
|
+
level,
|
|
26
|
+
},
|
|
27
|
+
throttle: 2,
|
|
28
|
+
throttleMin: 500,
|
|
29
|
+
formatOptions: {
|
|
30
|
+
colors: true,
|
|
31
|
+
compact: false,
|
|
32
|
+
date: false,
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export { consola, consola as logger, consola as rootLogger, LogLevels }
|