@travetto/log 5.0.0-rc.0 → 5.0.0-rc.2
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/README.md +3 -5
- package/package.json +4 -4
- package/src/appender/file.ts +2 -3
- package/src/common.ts +1 -1
- package/src/formatter/line.ts +2 -2
- package/src/service.ts +1 -1
- package/src/trv.d.ts +1 -1
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -13,10 +13,10 @@ npm install @travetto/log
|
|
|
13
13
|
yarn add @travetto/log
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
This module provides logging functionality, building upon [ConsoleManager](https://github.com/travetto/travetto/tree/main/module/
|
|
16
|
+
This module provides logging functionality, building upon [ConsoleManager](https://github.com/travetto/travetto/tree/main/module/runtime/src/console.ts) in the [Base](https://github.com/travetto/travetto/tree/main/module/runtime#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#
|
|
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`.
|
|
20
20
|
|
|
21
21
|
**Code: Standard Logging Config**
|
|
22
22
|
```typescript
|
|
@@ -74,8 +74,6 @@ export type ConsoleEvent = {
|
|
|
74
74
|
timestamp: Date;
|
|
75
75
|
/** The level of the console event */
|
|
76
76
|
level: 'info' | 'warn' | 'debug' | 'error';
|
|
77
|
-
/** The source file of the event */
|
|
78
|
-
source: string;
|
|
79
77
|
/** The line number the console event was triggered from */
|
|
80
78
|
line: number;
|
|
81
79
|
/** The module name for the source file */
|
|
@@ -89,7 +87,7 @@ export type ConsoleEvent = {
|
|
|
89
87
|
};
|
|
90
88
|
```
|
|
91
89
|
|
|
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/
|
|
90
|
+
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/runtime/src/console.ts#L6) with the addition of two fields:
|
|
93
91
|
* `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
92
|
* `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
93
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/log",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.2",
|
|
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": "^5.0.0-rc.
|
|
27
|
-
"@travetto/di": "^5.0.0-rc.
|
|
28
|
-
"@travetto/terminal": "^5.0.0-rc.
|
|
26
|
+
"@travetto/config": "^5.0.0-rc.2",
|
|
27
|
+
"@travetto/di": "^5.0.0-rc.2",
|
|
28
|
+
"@travetto/terminal": "^5.0.0-rc.2"
|
|
29
29
|
},
|
|
30
30
|
"travetto": {
|
|
31
31
|
"displayName": "Logging"
|
package/src/appender/file.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createWriteStream, WriteStream, mkdirSync, openSync, appendFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
import { Env } from '@travetto/
|
|
4
|
+
import { Env, Runtime } from '@travetto/runtime';
|
|
5
5
|
import { Injectable } from '@travetto/di';
|
|
6
6
|
import { Config, EnvVar } from '@travetto/config';
|
|
7
|
-
import { RuntimeContext } from '@travetto/manifest';
|
|
8
7
|
|
|
9
8
|
import { LogAppender, LogEvent } from '../types';
|
|
10
9
|
|
|
@@ -17,7 +16,7 @@ export class FileLogAppenderConfig {
|
|
|
17
16
|
|
|
18
17
|
postConstruct(): void {
|
|
19
18
|
if (!this.output || this.output === 'file' || this.output === 'console') {
|
|
20
|
-
this.output =
|
|
19
|
+
this.output = Runtime.toolPath('@', 'output.log');
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
}
|
package/src/common.ts
CHANGED
package/src/formatter/line.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import util from 'node:util';
|
|
2
2
|
|
|
3
|
-
import { Env } from '@travetto/
|
|
3
|
+
import { Env } from '@travetto/runtime';
|
|
4
4
|
import { Injectable } from '@travetto/di';
|
|
5
5
|
import { Config, EnvVar } from '@travetto/config';
|
|
6
6
|
import { Ignore } from '@travetto/schema';
|
|
@@ -114,7 +114,7 @@ export class LineLogFormatter implements LogFormatter {
|
|
|
114
114
|
out.push(level);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
if (ev.
|
|
117
|
+
if (ev.modulePath && this.opts.location) {
|
|
118
118
|
const ns = `${ev.module}:${ev.modulePath}`;
|
|
119
119
|
let loc = ev.line ? `${ns}:${ev.line}` : ns;
|
|
120
120
|
if (this.opts.colorize) {
|
package/src/service.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConsoleListener, ConsoleManager, ConsoleEvent } from '@travetto/
|
|
1
|
+
import { ConsoleListener, ConsoleManager, ConsoleEvent } from '@travetto/runtime';
|
|
2
2
|
import { AutoCreate, DependencyRegistry, Injectable } from '@travetto/di';
|
|
3
3
|
|
|
4
4
|
import { LogDecorator, LogEvent, Logger } from './types';
|
package/src/trv.d.ts
CHANGED
package/src/types.ts
CHANGED