@dxos/log 0.8.3 → 0.8.4-main.3f58842

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/log",
3
- "version": "0.8.3",
3
+ "version": "0.8.4-main.3f58842",
4
4
  "description": "Logger",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -35,8 +35,8 @@
35
35
  "js-yaml": "^4.1.0",
36
36
  "lodash.defaultsdeep": "^4.6.1",
37
37
  "lodash.omit": "^4.5.0",
38
- "@dxos/node-std": "0.8.3",
39
- "@dxos/util": "0.8.3"
38
+ "@dxos/node-std": "0.8.4-main.3f58842",
39
+ "@dxos/util": "0.8.4-main.3f58842"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/js-yaml": "^4.0.5",
package/src/context.ts CHANGED
@@ -16,7 +16,7 @@ export type LogContext = Record<string, any> | Error | any;
16
16
  */
17
17
  export interface LogEntry {
18
18
  level: LogLevel;
19
- message: string;
19
+ message?: string;
20
20
  context?: LogContext;
21
21
  meta?: CallMetadata;
22
22
  error?: Error;
@@ -64,8 +64,7 @@ export const getContextFromEntry = (entry: LogEntry): Record<string, any> | unde
64
64
  }
65
65
 
66
66
  if (entry.error) {
67
- const errorContext = (entry.error as any).context;
68
- context = Object.assign(context ?? {}, { error: entry.error, ...errorContext });
67
+ context = Object.assign(context ?? {}, { error: entry.error });
69
68
  }
70
69
 
71
70
  return context && Object.keys(context).length > 0 ? context : undefined;
package/src/index.ts CHANGED
@@ -14,6 +14,6 @@ export * from './log';
14
14
  export { parseFilter } from './options';
15
15
  export * from './processors';
16
16
  export * from './scope';
17
- export * from './meta';
17
+ export type * from './meta';
18
18
 
19
19
  export { getCurrentOwnershipScope } from './experimental/ownership';
package/src/log.test.ts CHANGED
@@ -28,10 +28,10 @@ log.config({
28
28
  filter: LogLevel.DEBUG,
29
29
  });
30
30
 
31
- /* eslint-disable @stayradiated/prefer-arrow-functions/prefer-arrow-functions */
31
+ /* eslint-disable prefer-arrow-functions/prefer-arrow-functions */
32
32
 
33
- describe('log', function () {
34
- test('throws an error', function () {
33
+ describe('log', () => {
34
+ test('throws an error', () => {
35
35
  try {
36
36
  throw new LogError('Test failed', { value: 1 });
37
37
  } catch (err: any) {
@@ -39,7 +39,7 @@ describe('log', function () {
39
39
  }
40
40
  });
41
41
 
42
- test('throws an error showing stacktrace', function () {
42
+ test('throws an error showing stacktrace', () => {
43
43
  try {
44
44
  throw new LogError('Test failed', { value: 2 });
45
45
  } catch (err: any) {
@@ -47,7 +47,7 @@ describe('log', function () {
47
47
  }
48
48
  });
49
49
 
50
- test('catches an error', function () {
50
+ test('catches an error', () => {
51
51
  try {
52
52
  throw new LogError('ERROR ON LINE 21', { value: 3 });
53
53
  } catch (err: any) {
@@ -55,7 +55,7 @@ describe('log', function () {
55
55
  }
56
56
  });
57
57
 
58
- test('config', function () {
58
+ test('config', () => {
59
59
  log.config({
60
60
  filter: LogLevel.INFO,
61
61
  });
@@ -65,7 +65,7 @@ describe('log', function () {
65
65
  log.warn('Warn level log message');
66
66
  });
67
67
 
68
- test('config file', function () {
68
+ test('config file', () => {
69
69
  log.config({
70
70
  file: path.join('packages/common/log/test-config.yml'),
71
71
  });
@@ -75,7 +75,7 @@ describe('log', function () {
75
75
  log.warn('Warn level log message');
76
76
  });
77
77
 
78
- test('levels', function () {
78
+ test('levels', () => {
79
79
  log('Default level log message');
80
80
  log.debug('Debug level log message');
81
81
  log.info('Info level log message');
@@ -83,10 +83,15 @@ describe('log', function () {
83
83
  log.error('Error level log message');
84
84
  });
85
85
 
86
- test('context', function () {
86
+ test('context', () => {
87
87
  log.info('Message with context', {
88
88
  title: 'test',
89
89
  context: 123,
90
90
  });
91
91
  });
92
+
93
+ test('error', function () {
94
+ const myError = new Error('Test error', { cause: new Error('Cause') });
95
+ log.catch(myError);
96
+ });
92
97
  });
package/src/log.ts CHANGED
@@ -78,8 +78,7 @@ const createLog = (): LogImp => {
78
78
  log.error = (...params) => processLog(LogLevel.ERROR, ...params);
79
79
 
80
80
  // Catch only shows error message, not stacktrace.
81
- log.catch = (error: Error | any, context, meta) =>
82
- processLog(LogLevel.ERROR, error?.message ?? String(error), context, meta, error);
81
+ log.catch = (error: Error | any, context, meta) => processLog(LogLevel.ERROR, undefined, context, meta, error);
83
82
 
84
83
  // Show break.
85
84
  log.break = () => log.info('——————————————————————————————————————————————————');
@@ -95,7 +94,7 @@ const createLog = (): LogImp => {
95
94
  */
96
95
  const processLog = (
97
96
  level: LogLevel,
98
- message: string,
97
+ message: string | undefined,
99
98
  context: LogContext = {},
100
99
  meta?: CallMetadata,
101
100
  error?: Error,
@@ -66,7 +66,9 @@ const APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {
66
66
  args.push(`%c${processPrefix}${scopeName}`, 'color:#C026D3;font-weight:bold');
67
67
  }
68
68
 
69
- args.push(entry.message);
69
+ if (entry.message) {
70
+ args.push(entry.message);
71
+ }
70
72
 
71
73
  const context = getContextFromEntry(entry);
72
74
  if (context) {
@@ -21,7 +21,7 @@ const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {
21
21
  };
22
22
 
23
23
  export const truncate = (text?: string, length = 0, right = false) => {
24
- const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : text ?? '';
24
+ const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : (text ?? '');
25
25
  return right ? str.padStart(length, ' ') : str.padEnd(length, ' ');
26
26
  };
27
27
 
@@ -32,7 +32,7 @@ export type FormatParts = {
32
32
  line?: number;
33
33
  timestamp?: string;
34
34
  level: LogLevel;
35
- message: string;
35
+ message?: string;
36
36
  context?: any;
37
37
  error?: Error;
38
38
  scope?: any;