@likec4/log 1.22.0 → 1.22.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/index.cjs CHANGED
@@ -1332,7 +1332,7 @@ function loggable(error) {
1332
1332
  return safeStringify(error);
1333
1333
  }
1334
1334
 
1335
- function errorFromLogRecord(record) {
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 appendErrorToMessage(values, color = false) {
1349
- const error = errorFromLogRecord(values.record);
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 = `RED: ${ansiColors.red}${errorMessge}${RESET}`;
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 format = options?.format ?? (({ timestamp, level: level2, category, message }) => {
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) => format(appendErrorToMessage(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 format = options?.format ?? (({ timestamp, level: level2, category, message }) => {
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 format(appendErrorToMessage(values, true));
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 errorFromLogRecord(record) {
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 appendErrorToMessage(values, color = false) {
1347
- const error = errorFromLogRecord(values.record);
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 = `RED: ${ansiColors.red}${errorMessge}${RESET}`;
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 format = options?.format ?? (({ timestamp, level: level2, category, message }) => {
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) => format(appendErrorToMessage(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 format = options?.format ?? (({ timestamp, level: level2, category, message }) => {
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 format(appendErrorToMessage(values, true));
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.22.0",
4
+ "version": "1.22.1",
5
5
  "bugs": "https://github.com/likec4/likec4/issues",
6
6
  "homepage": "https://likec4.dev",
7
7
  "author": "Denis Davydkov <denis@davydkov.com>",
@@ -37,7 +37,7 @@
37
37
  "@logtape/logtape": "^0.8.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@likec4/tsconfig": "1.22.0",
40
+ "@likec4/tsconfig": "1.22.1",
41
41
  "@types/node": "^20.17.17",
42
42
  "consola": "^3.4.0",
43
43
  "merge-error-cause": "^5.0.0",
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
- export function errorFromLogRecord(record: LogRecord): Error | null {
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 appendErrorToMessage(values: FormattedValues, color = false): FormattedValues {
94
- const error = errorFromLogRecord(values.record)
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 = `RED: ${ansiColors.red}${errorMessge}${RESET}`
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 format = options?.format ?? (({ timestamp, level, category, message }: FormattedValues): string => {
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) => format(appendErrorToMessage(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 format = options?.format ?? (({ timestamp, level, category, message }: FormattedValues): string => {
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 format(appendErrorToMessage(values, true))
191
+ return _format(appendErrorToMessage(values, true))
185
192
  },
186
193
  })
187
194
  }
package/src/index.ts CHANGED
@@ -24,6 +24,10 @@ export {
24
24
  getTextFormatter,
25
25
  } from './formatters'
26
26
 
27
+ export {
28
+ withFilter,
29
+ } from '@logtape/logtape'
30
+
27
31
  export {
28
32
  logger as consola,
29
33
  logger as rootLogger,