@dxos/log 0.8.4-main.f9ba587 → 0.8.4-main.fffef41

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.
Files changed (38) hide show
  1. package/dist/lib/browser/index.mjs +95 -48
  2. package/dist/lib/browser/index.mjs.map +3 -3
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +101 -52
  5. package/dist/lib/node-esm/index.mjs.map +3 -3
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/config.d.ts +2 -3
  8. package/dist/types/src/config.d.ts.map +1 -1
  9. package/dist/types/src/context.d.ts +1 -1
  10. package/dist/types/src/context.d.ts.map +1 -1
  11. package/dist/types/src/decorators.d.ts +1 -1
  12. package/dist/types/src/decorators.d.ts.map +1 -1
  13. package/dist/types/src/index.d.ts +1 -1
  14. package/dist/types/src/index.d.ts.map +1 -1
  15. package/dist/types/src/log.d.ts +12 -18
  16. package/dist/types/src/log.d.ts.map +1 -1
  17. package/dist/types/src/options.d.ts +1 -6
  18. package/dist/types/src/options.d.ts.map +1 -1
  19. package/dist/types/src/platform/node/index.d.ts.map +1 -1
  20. package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
  21. package/dist/types/src/processors/console-processor.d.ts +1 -1
  22. package/dist/types/src/processors/console-processor.d.ts.map +1 -1
  23. package/dist/types/src/processors/file-processor.d.ts.map +1 -1
  24. package/dist/types/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +5 -5
  26. package/src/config.ts +3 -2
  27. package/src/context.ts +38 -8
  28. package/src/decorators.ts +5 -4
  29. package/src/experimental/classes.test.ts +2 -1
  30. package/src/index.ts +1 -1
  31. package/src/log.test.ts +59 -23
  32. package/src/log.ts +102 -59
  33. package/src/options.ts +25 -11
  34. package/src/platform/node/index.ts +2 -1
  35. package/src/processors/browser-processor.ts +6 -2
  36. package/src/processors/console-processor.ts +11 -7
  37. package/src/processors/file-processor.ts +4 -1
  38. package/src/scope.ts +1 -1
@@ -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',
@@ -21,7 +23,7 @@ const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {
21
23
  };
22
24
 
23
25
  export const truncate = (text?: string, length = 0, right = false) => {
24
- const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : text ?? '';
26
+ const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : (text ?? '');
25
27
  return right ? str.padStart(length, ' ') : str.padEnd(length, ' ');
26
28
  };
27
29
 
@@ -32,7 +34,7 @@ export type FormatParts = {
32
34
  line?: number;
33
35
  timestamp?: string;
34
36
  level: LogLevel;
35
- message: string;
37
+ message?: string;
36
38
  context?: any;
37
39
  error?: Error;
38
40
  scope?: any;
@@ -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,12 +7,14 @@ 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;
17
+
16
18
  /**
17
19
  * Create a file processor.
18
20
  * @param path - Path to log file to create or append to, or existing open file descriptor e.g. stdout.
@@ -37,6 +39,7 @@ export const createFileProcessor = ({
37
39
  if (!shouldLog(entry, filters)) {
38
40
  return;
39
41
  }
42
+
40
43
  if (typeof pathOrFd === 'number') {
41
44
  fd = pathOrFd;
42
45
  } else {
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];