@dxos/log 0.8.4-main.b97322e → 0.8.4-main.dedc0f3

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.4-main.b97322e",
3
+ "version": "0.8.4-main.dedc0f3",
4
4
  "description": "Logger",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -10,12 +10,12 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
+ "types": "./dist/types/src/index.d.ts",
13
14
  "browser": "./dist/lib/browser/index.mjs",
14
15
  "node": {
15
16
  "require": "./dist/lib/node/index.cjs",
16
17
  "default": "./dist/lib/node-esm/index.mjs"
17
- },
18
- "types": "./dist/types/src/index.d.ts"
18
+ }
19
19
  }
20
20
  },
21
21
  "browser": {
@@ -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.4-main.b97322e",
39
- "@dxos/util": "0.8.4-main.b97322e"
38
+ "@dxos/node-std": "0.8.4-main.dedc0f3",
39
+ "@dxos/util": "0.8.4-main.dedc0f3"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/js-yaml": "^4.0.5",
package/src/config.ts CHANGED
@@ -6,8 +6,8 @@ import { type LogProcessor } from './context';
6
6
 
7
7
  /**
8
8
  * Standard levels.
9
+ * NOTE: Keep aligned with LogLevel in @dxos/protocols.
9
10
  */
10
- // NOTE: Keep aligned with LogLevel in @dxos/protocols.
11
11
  // TODO(burdon): Update numbers?
12
12
  export enum LogLevel {
13
13
  TRACE = 5,
@@ -18,7 +18,7 @@ export enum LogLevel {
18
18
  ERROR = 14,
19
19
  }
20
20
 
21
- export const levels: { [index: string]: LogLevel } = {
21
+ export const levels: Record<string, LogLevel> = {
22
22
  trace: LogLevel.TRACE,
23
23
  debug: LogLevel.DEBUG,
24
24
  verbose: LogLevel.VERBOSE,
package/src/decorators.ts CHANGED
@@ -2,9 +2,10 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import chalk from 'chalk';
6
5
  import { inspect } from 'node:util';
7
6
 
7
+ import chalk from 'chalk';
8
+
8
9
  import type { LogMethods } from './log';
9
10
  import { type CallMetadata } from './meta';
10
11
 
@@ -4,9 +4,10 @@
4
4
 
5
5
  import { describe, test } from 'vitest';
6
6
 
7
- import { debugInfo, ownershipClass } from './ownership';
8
7
  import { log } from '../log';
9
8
 
9
+ import { debugInfo, ownershipClass } from './ownership';
10
+
10
11
  describe('classes', function () {
11
12
  test('field instance', function () {
12
13
  @ownershipClass
package/src/log.test.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import path from 'node:path';
6
+
6
7
  import { describe, test } from 'vitest';
7
8
 
8
9
  import { LogLevel } from './config';
package/src/log.ts CHANGED
@@ -6,7 +6,7 @@ import { type LogConfig, LogLevel, type LogOptions } from './config';
6
6
  import { type LogContext, type LogProcessor } from './context';
7
7
  import { createFunctionLogDecorator, createMethodLogDecorator } from './decorators';
8
8
  import { type CallMetadata } from './meta';
9
- import { getConfig, DEFAULT_PROCESSORS } from './options';
9
+ import { DEFAULT_PROCESSORS, getConfig } from './options';
10
10
 
11
11
  /**
12
12
  * Logging function.
package/src/options.ts CHANGED
@@ -7,7 +7,7 @@ import defaultsDeep from 'lodash.defaultsdeep';
7
7
  import { type LogConfig, type LogFilter, LogLevel, type LogOptions, LogProcessorType, levels } from './config';
8
8
  import { type LogProcessor } from './context';
9
9
  import { loadOptions } from './platform';
10
- import { CONSOLE_PROCESSOR, DEBUG_PROCESSOR, BROWSER_PROCESSOR } from './processors';
10
+ import { BROWSER_PROCESSOR, CONSOLE_PROCESSOR, DEBUG_PROCESSOR } from './processors';
11
11
 
12
12
  /**
13
13
  * Processor variants.
@@ -2,9 +2,10 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import yaml from 'js-yaml';
6
5
  import fs from 'node:fs';
7
6
 
7
+ import yaml from 'js-yaml';
8
+
8
9
  import { type LogOptions } from '../../config';
9
10
 
10
11
  /**
@@ -5,7 +5,7 @@
5
5
  import { getDebugName, safariCheck } from '@dxos/util';
6
6
 
7
7
  import { LogLevel } from '../config';
8
- import { getContextFromEntry, type LogProcessor, shouldLog } from '../context';
8
+ import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
9
9
 
10
10
  const getRelativeFilename = (filename: string) => {
11
11
  // TODO(burdon): Hack uses "packages" as an anchor (pre-parse NX?)
@@ -2,14 +2,16 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import chalk from 'chalk';
6
5
  import { inspect } from 'node:util';
7
6
 
7
+ import chalk from 'chalk';
8
+
8
9
  import { getPrototypeSpecificInstanceId, pickBy } from '@dxos/util';
9
10
 
10
- import { getRelativeFilename } from './common';
11
11
  import { type LogConfig, LogLevel, shortLevelName } from '../config';
12
- import { getContextFromEntry, type LogProcessor, shouldLog } from '../context';
12
+ import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
13
+
14
+ import { getRelativeFilename } from './common';
13
15
 
14
16
  const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {
15
17
  [LogLevel.TRACE]: 'gray',
@@ -50,8 +52,10 @@ export const DEFAULT_FORMATTER: Formatter = (
50
52
  let instance;
51
53
  if (scope) {
52
54
  const prototype = Object.getPrototypeOf(scope);
53
- const id = getPrototypeSpecificInstanceId(scope);
54
- instance = chalk.magentaBright(`${prototype.constructor.name}#${id}`);
55
+ if (prototype !== null) {
56
+ const id = getPrototypeSpecificInstanceId(scope);
57
+ instance = chalk.magentaBright(`${prototype.constructor.name}#${id}`);
58
+ }
55
59
  }
56
60
 
57
61
  const formattedTimestamp = config.options?.formatter?.timestamp ? new Date().toISOString() : undefined;
@@ -7,10 +7,11 @@ import { dirname } from 'node:path';
7
7
 
8
8
  import { jsonlogify } from '@dxos/util';
9
9
 
10
- import { getRelativeFilename } from './common';
11
10
  import { type LogFilter, LogLevel } from '../config';
12
11
  import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
13
12
 
13
+ import { getRelativeFilename } from './common';
14
+
14
15
  // Amount of time to retry writing after encountering EAGAIN before giving up.
15
16
  const EAGAIN_MAX_DURATION = 1000;
16
17
  /**
package/src/scope.ts CHANGED
@@ -33,7 +33,7 @@ export const gatherLogInfoFromScope = (scope: any): Record<string, any> => {
33
33
  const res: Record<string, any> = {};
34
34
 
35
35
  const prototype = Object.getPrototypeOf(scope);
36
- const infoProps = prototype[logInfoProperties] ?? [];
36
+ const infoProps = (typeof prototype === 'object' && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
37
37
  for (const prop of infoProps) {
38
38
  try {
39
39
  res[prop] = typeof scope[prop] === 'function' ? scope[prop]() : scope[prop];