@travetto/log 4.1.1 → 5.0.0-rc.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 ArcSine Technologies
3
+ Copyright (c) 2023 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -16,7 +16,7 @@ yarn add @travetto/log
16
16
  This module provides logging functionality, building upon [ConsoleManager](https://github.com/travetto/travetto/tree/main/module/base/src/console.ts) in the [Base](https://github.com/travetto/travetto/tree/main/module/base#readme "Environment config and common utilities for travetto applications.") module. This is all ultimately built upon [console](https://nodejs.org/api/console.html) operations. The logging infrastructure is built upon the [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.") system, and so new loggers can be created that rely upon dependency injected services and sources.
17
17
 
18
18
  ## Extending the Common Logger
19
- By default, the system ships with the [CommonLogger](https://github.com/travetto/travetto/tree/main/module/log/src/common.ts#L12), and by default will leverage the [LineLogFormatter](https://github.com/travetto/travetto/tree/main/module/log/src/formatter/line.ts#L37) and the [ConsoleLogAppender](https://github.com/travetto/travetto/tree/main/module/log/src/appender/console.ts#L7). The configuration [CommonLoggerConfig](https://github.com/travetto/travetto/tree/main/module/log/src/common.ts#L12) provides two configuration variables that allows for switching out [LineLogFormatter](https://github.com/travetto/travetto/tree/main/module/log/src/formatter/line.ts#L37) for the [JsonLogFormatter](https://github.com/travetto/travetto/tree/main/module/log/src/formatter/json.ts#L16), depending on the value of `CommonLoggerConfig.format`. Additionally the [ConsoleLogAppender](https://github.com/travetto/travetto/tree/main/module/log/src/appender/console.ts#L7) can be swapped out for the [FileLogAppender](https://github.com/travetto/travetto/tree/main/module/log/src/appender/file.ts#L11) depending on the value of `CommonLoggerConfig.output`.
19
+ By default, the system ships with the [CommonLogger](https://github.com/travetto/travetto/tree/main/module/log/src/common.ts#L12), and by default will leverage the [LineLogFormatter](https://github.com/travetto/travetto/tree/main/module/log/src/formatter/line.ts#L37) and the [ConsoleLogAppender](https://github.com/travetto/travetto/tree/main/module/log/src/appender/console.ts#L7). The configuration [CommonLoggerConfig](https://github.com/travetto/travetto/tree/main/module/log/src/common.ts#L12) provides two configuration variables that allows for switching out [LineLogFormatter](https://github.com/travetto/travetto/tree/main/module/log/src/formatter/line.ts#L37) for the [JsonLogFormatter](https://github.com/travetto/travetto/tree/main/module/log/src/formatter/json.ts#L16), depending on the value of `CommonLoggerConfig.format`. Additionally the [ConsoleLogAppender](https://github.com/travetto/travetto/tree/main/module/log/src/appender/console.ts#L7) can be swapped out for the [FileLogAppender](https://github.com/travetto/travetto/tree/main/module/log/src/appender/file.ts#L12) depending on the value of `CommonLoggerConfig.output`.
20
20
 
21
21
  **Code: Standard Logging Config**
22
22
  ```typescript
@@ -53,7 +53,7 @@ The default pattern for logging is to create a [Logger](https://github.com/trave
53
53
  **Code: Logger Shape**
54
54
  ```typescript
55
55
  export interface Logger {
56
- onLog(ev: LogEvent): unknown;
56
+ log(ev: LogEvent): unknown;
57
57
  }
58
58
  ```
59
59
 
@@ -73,7 +73,7 @@ export type ConsoleEvent = {
73
73
  /** Time of event */
74
74
  timestamp: Date;
75
75
  /** The level of the console event */
76
- level: LogLevel;
76
+ level: 'info' | 'warn' | 'debug' | 'error';
77
77
  /** The source file of the event */
78
78
  source: string;
79
79
  /** The line number the console event was triggered from */
@@ -89,7 +89,7 @@ export type ConsoleEvent = {
89
89
  };
90
90
  ```
91
91
 
92
- The [LogEvent](https://github.com/travetto/travetto/tree/main/module/log/src/types.ts#L8) is an extension of the [ConsoleEvent](https://github.com/travetto/travetto/tree/main/module/base/src/types.ts#L12) with the addition of two fields:
92
+ The [LogEvent](https://github.com/travetto/travetto/tree/main/module/log/src/types.ts#L8) is an extension of the [ConsoleEvent](https://github.com/travetto/travetto/tree/main/module/base/src/console.ts#L6) with the addition of two fields:
93
93
  * `message` - This is the primary argument passed to the console statement, if it happens to be a string, otherwise the field is left empty
94
94
  * `context` - This is the final argument passed to the console statement, if it happens to be a simple object. This is useful for external loggers that allow for searching/querying by complex data
95
95
 
@@ -100,7 +100,7 @@ import { LogEvent, Logger } from '@travetto/log';
100
100
 
101
101
  @Injectable()
102
102
  export class CustomLogger implements Logger {
103
- onLog(ev: LogEvent): void {
103
+ log(ev: LogEvent): void {
104
104
  const headers = new Headers();
105
105
  headers.set('Content-Type', 'application/json');
106
106
  const body = JSON.stringify(ev);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/log",
3
- "version": "4.1.1",
3
+ "version": "5.0.0-rc.0",
4
4
  "description": "Logging framework that integrates at the console.log level.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -23,9 +23,9 @@
23
23
  "directory": "module/log"
24
24
  },
25
25
  "dependencies": {
26
- "@travetto/config": "^4.1.1",
27
- "@travetto/di": "^4.1.1",
28
- "@travetto/terminal": "^4.1.1"
26
+ "@travetto/config": "^5.0.0-rc.0",
27
+ "@travetto/di": "^5.0.0-rc.0",
28
+ "@travetto/terminal": "^5.0.0-rc.0"
29
29
  },
30
30
  "travetto": {
31
31
  "displayName": "Logging"
@@ -1,9 +1,10 @@
1
1
  import { createWriteStream, WriteStream, mkdirSync, openSync, appendFileSync } from 'node:fs';
2
+ import path from 'node:path';
2
3
 
3
4
  import { Env } from '@travetto/base';
4
5
  import { Injectable } from '@travetto/di';
5
6
  import { Config, EnvVar } from '@travetto/config';
6
- import { path, RuntimeContext } from '@travetto/manifest';
7
+ import { RuntimeContext } from '@travetto/manifest';
7
8
 
8
9
  import { LogAppender, LogEvent } from '../types';
9
10
 
package/src/common.ts CHANGED
@@ -34,7 +34,7 @@ export class CommonLogger implements Logger {
34
34
  this.appender ??= await DependencyRegistry.getInstance(this.config.output !== 'console' ? FileLogAppender : ConsoleLogAppender);
35
35
  }
36
36
 
37
- onLog(ev: LogEvent): void {
37
+ log(ev: LogEvent): void {
38
38
  this.appender.append(ev, this.formatter.format(ev));
39
39
  }
40
40
  }
@@ -1,5 +1,5 @@
1
1
  import { inspect, type InspectOptions } from 'node:util';
2
- import { ObjectUtil } from '@travetto/base';
2
+ import { DataUtil } from '@travetto/schema';
3
3
  import { LogEvent } from '../types';
4
4
 
5
5
  export class LogFormatUtil {
@@ -9,7 +9,7 @@ export class LogFormatUtil {
9
9
  static getContext(ev: LogEvent): Record<string, unknown> | undefined {
10
10
  const out: Record<string, unknown> = {};
11
11
  for (const o of ev.args ?? []) {
12
- if (ObjectUtil.isPlainObject(o)) {
12
+ if (DataUtil.isPlainObject(o)) {
13
13
  Object.assign(out, o);
14
14
  }
15
15
  }
package/src/service.ts CHANGED
@@ -29,14 +29,13 @@ export class LogService implements ConsoleListener, AutoCreate {
29
29
 
30
30
  this.#decorators = await DependencyRegistry.getCandidateInstances<LogDecorator>(LogDecoratorTarget);
31
31
 
32
- // Take over
33
- ConsoleManager.set(this, true);
32
+ ConsoleManager.set(this);
34
33
  }
35
34
 
36
35
  /**
37
36
  * Endpoint for listening, endpoint registered with ConsoleManager
38
37
  */
39
- onLog(ev: ConsoleEvent): void {
38
+ log(ev: ConsoleEvent): void {
40
39
  const args = [...ev.args];
41
40
  let message: string | undefined;
42
41
  if (typeof args[0] === 'string') {
@@ -53,7 +52,7 @@ export class LogService implements ConsoleListener, AutoCreate {
53
52
  }
54
53
 
55
54
  for (const l of this.#listeners) {
56
- l.onLog(outEvent);
55
+ l.log(outEvent);
57
56
  }
58
57
  }
59
58
  }
package/src/types.ts CHANGED
@@ -39,5 +39,5 @@ export interface LogFormatter {
39
39
  * @concrete ./internal/types#LoggerTarget
40
40
  */
41
41
  export interface Logger {
42
- onLog(ev: LogEvent): unknown;
42
+ log(ev: LogEvent): unknown;
43
43
  }