@likec4/log 1.22.0 → 1.23.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 +21 -0
- package/dist/index.cjs +18 -8
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +18 -8
- package/package.json +8 -9
- package/src/formatters.ts +19 -12
- package/src/index.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-2025 Denis Davydkov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -1332,7 +1332,7 @@ function loggable(error) {
|
|
|
1332
1332
|
return safeStringify(error);
|
|
1333
1333
|
}
|
|
1334
1334
|
|
|
1335
|
-
function
|
|
1335
|
+
function gerErrorFromLogRecord(record) {
|
|
1336
1336
|
const errors = Object.values(record.properties).filter((v) => v instanceof Error).map((err) => {
|
|
1337
1337
|
const mergedErr = mergeErrorCause(err);
|
|
1338
1338
|
if (mergedErr.stack) {
|
|
@@ -1345,15 +1345,22 @@ function errorFromLogRecord(record) {
|
|
|
1345
1345
|
}
|
|
1346
1346
|
return errors.length === 1 ? errors[0] : new AggregateError(errors);
|
|
1347
1347
|
}
|
|
1348
|
-
function
|
|
1349
|
-
const error =
|
|
1348
|
+
function errorFromLogRecord(record) {
|
|
1349
|
+
const error = gerErrorFromLogRecord(record);
|
|
1350
|
+
if (error && typeof record.rawMessage === "string") {
|
|
1351
|
+
return wrapErrorMessage(error, record.rawMessage + "\n");
|
|
1352
|
+
}
|
|
1353
|
+
return error;
|
|
1354
|
+
}
|
|
1355
|
+
function appendErrorToMessage(values, color) {
|
|
1356
|
+
const error = gerErrorFromLogRecord(values.record);
|
|
1350
1357
|
if (error) {
|
|
1351
1358
|
let errorMessge = error.message;
|
|
1352
1359
|
if (error.stack) {
|
|
1353
1360
|
errorMessge = errorMessge + "\n" + ident(error.stack.split("\n").slice(1));
|
|
1354
1361
|
}
|
|
1355
1362
|
if (color) {
|
|
1356
|
-
errorMessge =
|
|
1363
|
+
errorMessge = `${ansiColors.red}${errorMessge}${RESET}`;
|
|
1357
1364
|
}
|
|
1358
1365
|
return {
|
|
1359
1366
|
...values,
|
|
@@ -1378,7 +1385,7 @@ function getMessageOnlyFormatter() {
|
|
|
1378
1385
|
}
|
|
1379
1386
|
const level = (l) => levelAbbreviations[l];
|
|
1380
1387
|
function getTextFormatter(options) {
|
|
1381
|
-
const
|
|
1388
|
+
const _format = options?.format ?? (({ timestamp, level: level2, category, message }) => {
|
|
1382
1389
|
return `${timestamp} ${level2} ${category} ${message}`;
|
|
1383
1390
|
});
|
|
1384
1391
|
return logtape.getTextFormatter({
|
|
@@ -1386,7 +1393,9 @@ function getTextFormatter(options) {
|
|
|
1386
1393
|
level,
|
|
1387
1394
|
category: ".",
|
|
1388
1395
|
...options,
|
|
1389
|
-
format: (values) =>
|
|
1396
|
+
format: (values) => {
|
|
1397
|
+
return _format(appendErrorToMessage(values));
|
|
1398
|
+
}
|
|
1390
1399
|
});
|
|
1391
1400
|
}
|
|
1392
1401
|
const RESET = "\x1B[0m";
|
|
@@ -1401,7 +1410,7 @@ const ansiColors = {
|
|
|
1401
1410
|
// white: "\x1b[37m",
|
|
1402
1411
|
};
|
|
1403
1412
|
function getAnsiColorFormatter(options) {
|
|
1404
|
-
const
|
|
1413
|
+
const _format = options?.format ?? (({ timestamp, level: level2, category, message }) => {
|
|
1405
1414
|
return `${timestamp} ${level2} ${category} ${message}`;
|
|
1406
1415
|
});
|
|
1407
1416
|
return logtape.getAnsiColorFormatter({
|
|
@@ -1412,7 +1421,7 @@ function getAnsiColorFormatter(options) {
|
|
|
1412
1421
|
category: ".",
|
|
1413
1422
|
...options,
|
|
1414
1423
|
format: (values) => {
|
|
1415
|
-
return
|
|
1424
|
+
return _format(appendErrorToMessage(values, true));
|
|
1416
1425
|
}
|
|
1417
1426
|
});
|
|
1418
1427
|
}
|
|
@@ -1461,6 +1470,7 @@ function ensureLoggerIsConfigured() {
|
|
|
1461
1470
|
}
|
|
1462
1471
|
}
|
|
1463
1472
|
|
|
1473
|
+
exports.withFilter = logtape.withFilter;
|
|
1464
1474
|
exports.configureLogger = configureLogger;
|
|
1465
1475
|
exports.consola = logger;
|
|
1466
1476
|
exports.createLogger = createLogger;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _logtape_logtape from '@logtape/logtape';
|
|
2
2
|
import { LogRecord, AnsiColorFormatterOptions, TextFormatter, ConsoleSinkOptions, Sink, TextFormatterOptions, Config } from '@logtape/logtape';
|
|
3
|
-
export { Filter, LogLevel, LogRecord, Logger, Sink, TextFormatter } from '@logtape/logtape';
|
|
3
|
+
export { Filter, LogLevel, LogRecord, Logger, Sink, TextFormatter, withFilter } from '@logtape/logtape';
|
|
4
4
|
|
|
5
5
|
declare function errorFromLogRecord(record: LogRecord): Error | null;
|
|
6
6
|
declare function getMessageOnlyFormatter(): TextFormatter;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _logtape_logtape from '@logtape/logtape';
|
|
2
2
|
import { LogRecord, AnsiColorFormatterOptions, TextFormatter, ConsoleSinkOptions, Sink, TextFormatterOptions, Config } from '@logtape/logtape';
|
|
3
|
-
export { Filter, LogLevel, LogRecord, Logger, Sink, TextFormatter } from '@logtape/logtape';
|
|
3
|
+
export { Filter, LogLevel, LogRecord, Logger, Sink, TextFormatter, withFilter } from '@logtape/logtape';
|
|
4
4
|
|
|
5
5
|
declare function errorFromLogRecord(record: LogRecord): Error | null;
|
|
6
6
|
declare function getMessageOnlyFormatter(): TextFormatter;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _logtape_logtape from '@logtape/logtape';
|
|
2
2
|
import { LogRecord, AnsiColorFormatterOptions, TextFormatter, ConsoleSinkOptions, Sink, TextFormatterOptions, Config } from '@logtape/logtape';
|
|
3
|
-
export { Filter, LogLevel, LogRecord, Logger, Sink, TextFormatter } from '@logtape/logtape';
|
|
3
|
+
export { Filter, LogLevel, LogRecord, Logger, Sink, TextFormatter, withFilter } from '@logtape/logtape';
|
|
4
4
|
|
|
5
5
|
declare function errorFromLogRecord(record: LogRecord): Error | null;
|
|
6
6
|
declare function getMessageOnlyFormatter(): TextFormatter;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getAnsiColorFormatter as getAnsiColorFormatter$1, getConsoleSink as getConsoleSink$1, getTextFormatter as getTextFormatter$1, getLogger, configure } from '@logtape/logtape';
|
|
2
|
+
export { withFilter } from '@logtape/logtape';
|
|
2
3
|
|
|
3
4
|
const normalizeDescriptors=(error)=>{
|
|
4
5
|
CORE_ERROR_PROPS.forEach((propName)=>{
|
|
@@ -1330,7 +1331,7 @@ function loggable(error) {
|
|
|
1330
1331
|
return safeStringify(error);
|
|
1331
1332
|
}
|
|
1332
1333
|
|
|
1333
|
-
function
|
|
1334
|
+
function gerErrorFromLogRecord(record) {
|
|
1334
1335
|
const errors = Object.values(record.properties).filter((v) => v instanceof Error).map((err) => {
|
|
1335
1336
|
const mergedErr = mergeErrorCause(err);
|
|
1336
1337
|
if (mergedErr.stack) {
|
|
@@ -1343,15 +1344,22 @@ function errorFromLogRecord(record) {
|
|
|
1343
1344
|
}
|
|
1344
1345
|
return errors.length === 1 ? errors[0] : new AggregateError(errors);
|
|
1345
1346
|
}
|
|
1346
|
-
function
|
|
1347
|
-
const error =
|
|
1347
|
+
function errorFromLogRecord(record) {
|
|
1348
|
+
const error = gerErrorFromLogRecord(record);
|
|
1349
|
+
if (error && typeof record.rawMessage === "string") {
|
|
1350
|
+
return wrapErrorMessage(error, record.rawMessage + "\n");
|
|
1351
|
+
}
|
|
1352
|
+
return error;
|
|
1353
|
+
}
|
|
1354
|
+
function appendErrorToMessage(values, color) {
|
|
1355
|
+
const error = gerErrorFromLogRecord(values.record);
|
|
1348
1356
|
if (error) {
|
|
1349
1357
|
let errorMessge = error.message;
|
|
1350
1358
|
if (error.stack) {
|
|
1351
1359
|
errorMessge = errorMessge + "\n" + ident(error.stack.split("\n").slice(1));
|
|
1352
1360
|
}
|
|
1353
1361
|
if (color) {
|
|
1354
|
-
errorMessge =
|
|
1362
|
+
errorMessge = `${ansiColors.red}${errorMessge}${RESET}`;
|
|
1355
1363
|
}
|
|
1356
1364
|
return {
|
|
1357
1365
|
...values,
|
|
@@ -1376,7 +1384,7 @@ function getMessageOnlyFormatter() {
|
|
|
1376
1384
|
}
|
|
1377
1385
|
const level = (l) => levelAbbreviations[l];
|
|
1378
1386
|
function getTextFormatter(options) {
|
|
1379
|
-
const
|
|
1387
|
+
const _format = options?.format ?? (({ timestamp, level: level2, category, message }) => {
|
|
1380
1388
|
return `${timestamp} ${level2} ${category} ${message}`;
|
|
1381
1389
|
});
|
|
1382
1390
|
return getTextFormatter$1({
|
|
@@ -1384,7 +1392,9 @@ function getTextFormatter(options) {
|
|
|
1384
1392
|
level,
|
|
1385
1393
|
category: ".",
|
|
1386
1394
|
...options,
|
|
1387
|
-
format: (values) =>
|
|
1395
|
+
format: (values) => {
|
|
1396
|
+
return _format(appendErrorToMessage(values));
|
|
1397
|
+
}
|
|
1388
1398
|
});
|
|
1389
1399
|
}
|
|
1390
1400
|
const RESET = "\x1B[0m";
|
|
@@ -1399,7 +1409,7 @@ const ansiColors = {
|
|
|
1399
1409
|
// white: "\x1b[37m",
|
|
1400
1410
|
};
|
|
1401
1411
|
function getAnsiColorFormatter(options) {
|
|
1402
|
-
const
|
|
1412
|
+
const _format = options?.format ?? (({ timestamp, level: level2, category, message }) => {
|
|
1403
1413
|
return `${timestamp} ${level2} ${category} ${message}`;
|
|
1404
1414
|
});
|
|
1405
1415
|
return getAnsiColorFormatter$1({
|
|
@@ -1410,7 +1420,7 @@ function getAnsiColorFormatter(options) {
|
|
|
1410
1420
|
category: ".",
|
|
1411
1421
|
...options,
|
|
1412
1422
|
format: (values) => {
|
|
1413
|
-
return
|
|
1423
|
+
return _format(appendErrorToMessage(values, true));
|
|
1414
1424
|
}
|
|
1415
1425
|
});
|
|
1416
1426
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/log",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.23.0",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
7
7
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -29,23 +29,22 @@
|
|
|
29
29
|
"registry": "https://registry.npmjs.org",
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"typecheck": "tsc --noEmit",
|
|
34
|
-
"build": "unbuild"
|
|
35
|
-
},
|
|
36
32
|
"dependencies": {
|
|
37
33
|
"@logtape/logtape": "^0.8.2"
|
|
38
34
|
},
|
|
39
35
|
"devDependencies": {
|
|
40
|
-
"@likec4/tsconfig": "1.22.0",
|
|
41
36
|
"@types/node": "^20.17.17",
|
|
42
37
|
"consola": "^3.4.0",
|
|
43
38
|
"merge-error-cause": "^5.0.0",
|
|
44
39
|
"safe-stringify": "^1.1.1",
|
|
45
40
|
"std-env": "^3.8.0",
|
|
46
|
-
"typescript": "
|
|
41
|
+
"typescript": "5.7.3",
|
|
47
42
|
"unbuild": "^3.3.1",
|
|
48
|
-
"wrap-error-message": "^3.0.0"
|
|
43
|
+
"wrap-error-message": "^3.0.0",
|
|
44
|
+
"@likec4/tsconfig": "1.23.0"
|
|
49
45
|
},
|
|
50
|
-
"
|
|
46
|
+
"scripts": {
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"build": "unbuild"
|
|
49
|
+
}
|
|
51
50
|
}
|
package/src/formatters.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
getTextFormatter as getLogtapeTextFormatter,
|
|
13
13
|
} from '@logtape/logtape'
|
|
14
14
|
import mergeErrorCause from 'merge-error-cause'
|
|
15
|
+
import wrapErrorMessage from 'wrap-error-message'
|
|
15
16
|
import { ident, parseStack } from './utils'
|
|
16
17
|
|
|
17
18
|
// export function formatProperties(properties: Record<string, unknown>): {
|
|
@@ -69,7 +70,7 @@ import { ident, parseStack } from './utils'
|
|
|
69
70
|
// }
|
|
70
71
|
// }
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
function gerErrorFromLogRecord(record: LogRecord): Error | null {
|
|
73
74
|
const errors = Object
|
|
74
75
|
.values(record.properties)
|
|
75
76
|
.filter((v) => v instanceof Error)
|
|
@@ -84,21 +85,25 @@ export function errorFromLogRecord(record: LogRecord): Error | null {
|
|
|
84
85
|
return null
|
|
85
86
|
}
|
|
86
87
|
return errors.length === 1 ? errors[0]! : new AggregateError(errors)
|
|
87
|
-
// if (typeof record.rawMessage === 'string') {
|
|
88
|
-
// return wrapErrorMessage(error, record.rawMessage + Z'\n')
|
|
89
|
-
// }
|
|
90
|
-
// return error
|
|
91
88
|
}
|
|
92
89
|
|
|
93
|
-
export function
|
|
94
|
-
const error =
|
|
90
|
+
export function errorFromLogRecord(record: LogRecord): Error | null {
|
|
91
|
+
const error = gerErrorFromLogRecord(record)
|
|
92
|
+
if (error && typeof record.rawMessage === 'string') {
|
|
93
|
+
return wrapErrorMessage(error, record.rawMessage + '\n')
|
|
94
|
+
}
|
|
95
|
+
return error
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function appendErrorToMessage(values: FormattedValues, color?: boolean): FormattedValues {
|
|
99
|
+
const error = gerErrorFromLogRecord(values.record)
|
|
95
100
|
if (error) {
|
|
96
101
|
let errorMessge = error.message
|
|
97
102
|
if (error.stack) {
|
|
98
103
|
errorMessge = errorMessge + '\n' + ident(error.stack.split('\n').slice(1))
|
|
99
104
|
}
|
|
100
105
|
if (color) {
|
|
101
|
-
errorMessge =
|
|
106
|
+
errorMessge = `${ansiColors.red}${errorMessge}${RESET}`
|
|
102
107
|
}
|
|
103
108
|
return {
|
|
104
109
|
...values,
|
|
@@ -143,7 +148,7 @@ export function getMessageOnlyFormatter(): TextFormatter {
|
|
|
143
148
|
const level = (l: LogLevel): string => levelAbbreviations[l]
|
|
144
149
|
|
|
145
150
|
export function getTextFormatter(options?: TextFormatterOptions): TextFormatter {
|
|
146
|
-
const
|
|
151
|
+
const _format = options?.format ?? (({ timestamp, level, category, message }: FormattedValues): string => {
|
|
147
152
|
return `${timestamp} ${level} ${category} ${message}`
|
|
148
153
|
})
|
|
149
154
|
// const format = options?.format
|
|
@@ -152,7 +157,9 @@ export function getTextFormatter(options?: TextFormatterOptions): TextFormatter
|
|
|
152
157
|
level,
|
|
153
158
|
category: '.',
|
|
154
159
|
...options,
|
|
155
|
-
format: (values) =>
|
|
160
|
+
format: (values) => {
|
|
161
|
+
return _format(appendErrorToMessage(values))
|
|
162
|
+
},
|
|
156
163
|
})
|
|
157
164
|
}
|
|
158
165
|
|
|
@@ -170,7 +177,7 @@ const ansiColors = {
|
|
|
170
177
|
} as const
|
|
171
178
|
|
|
172
179
|
export function getAnsiColorFormatter(options?: AnsiColorFormatterOptions): TextFormatter {
|
|
173
|
-
const
|
|
180
|
+
const _format = options?.format ?? (({ timestamp, level, category, message }: FormattedValues): string => {
|
|
174
181
|
return `${timestamp} ${level} ${category} ${message}`
|
|
175
182
|
})
|
|
176
183
|
return getLogtapeAnsiColorFormatter({
|
|
@@ -181,7 +188,7 @@ export function getAnsiColorFormatter(options?: AnsiColorFormatterOptions): Text
|
|
|
181
188
|
category: '.',
|
|
182
189
|
...options,
|
|
183
190
|
format: (values) => {
|
|
184
|
-
return
|
|
191
|
+
return _format(appendErrorToMessage(values, true))
|
|
185
192
|
},
|
|
186
193
|
})
|
|
187
194
|
}
|