@ontrails/logging 1.0.0-beta.0 → 1.0.0-beta.1
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/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +10 -0
- package/README.md +31 -96
- package/package.json +2 -2
package/.turbo/turbo-lint.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @ontrails/logging
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix two blocking bugs from real-world migration:
|
|
8
|
+
- Published packages now resolve correctly (workspace:^ instead of workspace:\*)
|
|
9
|
+
- Error forwarding works across different success types (Err no longer carries phantom T)
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- @ontrails/core@1.0.0-beta.1
|
|
12
|
+
|
|
3
13
|
## 1.0.0-beta.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
# @ontrails/logging
|
|
2
2
|
|
|
3
|
-
Structured logging for Trails. One
|
|
3
|
+
Structured logging for Trails. One entry point: `createLogger`. Built-in sinks and formatters, hierarchical category filtering, automatic redaction, and an optional LogTape adapter.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
bun add @ontrails/logging @ontrails/core
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
For LogTape integration:
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
bun add @logtape/logtape
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Quick Start
|
|
5
|
+
## Usage
|
|
18
6
|
|
|
19
7
|
```typescript
|
|
20
8
|
import { createLogger } from '@ontrails/logging';
|
|
@@ -28,112 +16,65 @@ logger.info('Entity created', { entityId: 'e1', name: 'Alpha' });
|
|
|
28
16
|
// 10:00:00 INFO [app.entity] Entity created entityId=e1 name=Alpha
|
|
29
17
|
```
|
|
30
18
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
### `createLogger(config)`
|
|
34
|
-
|
|
35
|
-
The single entry point. Returns a `Logger` (from `@ontrails/core`) that plugs directly into `TrailContext.logger`.
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
const logger = createLogger({
|
|
39
|
-
name: 'app.db.queries',
|
|
40
|
-
level: 'info',
|
|
41
|
-
levels: {
|
|
42
|
-
app: 'info',
|
|
43
|
-
'app.db': 'debug',
|
|
44
|
-
'app.http': 'warn',
|
|
45
|
-
},
|
|
46
|
-
sinks: [createConsoleSink(), createFileSink({ path: './app.log' })],
|
|
47
|
-
redaction: { sensitiveKeys: ['password', 'token'] },
|
|
48
|
-
});
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Sinks
|
|
52
|
-
|
|
53
|
-
A `LogSink` receives formatted log records and writes them somewhere.
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
import { createConsoleSink, createFileSink } from '@ontrails/logging';
|
|
57
|
-
|
|
58
|
-
// Console output (default sink)
|
|
59
|
-
createConsoleSink({ formatter: createPrettyFormatter() });
|
|
60
|
-
|
|
61
|
-
// File output
|
|
62
|
-
createFileSink({ path: './logs/app.log', formatter: createJsonFormatter() });
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Formatters
|
|
19
|
+
The returned `Logger` plugs directly into `TrailContext.logger`.
|
|
66
20
|
|
|
67
|
-
|
|
68
|
-
import { createJsonFormatter, createPrettyFormatter } from '@ontrails/logging';
|
|
21
|
+
## API
|
|
69
22
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
23
|
+
| Export | What it does |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `createLogger(config)` | Create a logger with sinks, formatters, and level config |
|
|
26
|
+
| `createConsoleSink(options?)` | Sink that writes to the console |
|
|
27
|
+
| `createFileSink(options)` | Sink that writes to a file |
|
|
28
|
+
| `createJsonFormatter()` | One JSON object per line, ISO timestamps |
|
|
29
|
+
| `createPrettyFormatter()` | Human-readable with optional ANSI colors |
|
|
73
30
|
|
|
74
|
-
|
|
75
|
-
createPrettyFormatter();
|
|
76
|
-
// 10:00:00 INFO [app.entity] Entity created entityId=e1
|
|
77
|
-
```
|
|
31
|
+
See the [API Reference](../../docs/api-reference.md) for the full list.
|
|
78
32
|
|
|
79
|
-
|
|
33
|
+
## Hierarchical filtering
|
|
80
34
|
|
|
81
|
-
Categories are dot-separated. Level resolution walks up the hierarchy
|
|
35
|
+
Categories are dot-separated. Level resolution walks up the hierarchy:
|
|
82
36
|
|
|
83
37
|
```typescript
|
|
84
38
|
const logger = createLogger({
|
|
85
39
|
name: 'app.db.queries',
|
|
86
|
-
level: 'info',
|
|
40
|
+
level: 'info',
|
|
87
41
|
levels: {
|
|
88
42
|
app: 'info',
|
|
89
|
-
'app.db': 'debug',
|
|
43
|
+
'app.db': 'debug', // matches "app.db.queries"
|
|
90
44
|
'app.http': 'warn',
|
|
91
45
|
},
|
|
92
46
|
});
|
|
93
47
|
```
|
|
94
48
|
|
|
95
|
-
Resolution for `"app.db.queries"`:
|
|
49
|
+
Resolution for `"app.db.queries"`: exact match, then `"app.db"` (debug), then `"app"`, then `config.level`, then `TRAILS_LOG_LEVEL`, then `"info"`.
|
|
96
50
|
|
|
97
|
-
|
|
51
|
+
## Child loggers
|
|
98
52
|
|
|
99
53
|
```typescript
|
|
100
54
|
const child = logger.child({ requestId: 'abc-123', trail: 'entity.show' });
|
|
101
55
|
child.info('Processing');
|
|
102
|
-
// Every
|
|
56
|
+
// Every record from this child includes requestId and trail metadata
|
|
103
57
|
```
|
|
104
58
|
|
|
105
|
-
Children inherit
|
|
59
|
+
Children inherit sinks, level config, and redaction from the parent.
|
|
106
60
|
|
|
107
|
-
|
|
61
|
+
## Redaction
|
|
108
62
|
|
|
109
|
-
Sensitive data is
|
|
63
|
+
Sensitive data is stripped before sink dispatch, using `@ontrails/core/redaction`:
|
|
110
64
|
|
|
111
65
|
```typescript
|
|
112
66
|
const logger = createLogger({
|
|
113
67
|
name: 'app',
|
|
114
|
-
redaction: {
|
|
115
|
-
patterns: [/custom-secret-\w+/g],
|
|
116
|
-
sensitiveKeys: ['password', 'internalToken'],
|
|
117
|
-
},
|
|
68
|
+
redaction: { sensitiveKeys: ['password', 'token'] },
|
|
118
69
|
});
|
|
119
70
|
|
|
120
71
|
logger.info('Auth', { user: 'admin', password: 'hunter2' });
|
|
121
|
-
// password
|
|
72
|
+
// password → "[REDACTED]"
|
|
122
73
|
```
|
|
123
74
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
Log level can be set via environment:
|
|
75
|
+
## LogTape adapter
|
|
127
76
|
|
|
128
|
-
|
|
129
|
-
2. `config.levels` hierarchy
|
|
130
|
-
3. `TRAILS_LOG_LEVEL` env var
|
|
131
|
-
4. `TRAILS_ENV` profile defaults (`development` = `"debug"`, `test` = silent)
|
|
132
|
-
5. Fallback: `"info"`
|
|
133
|
-
|
|
134
|
-
### LogTape Adapter (`@ontrails/logging/logtape`)
|
|
135
|
-
|
|
136
|
-
Bridge Trails logging to an existing LogTape infrastructure:
|
|
77
|
+
Bridge to an existing LogTape setup via the `/logtape` subpath:
|
|
137
78
|
|
|
138
79
|
```typescript
|
|
139
80
|
import { logtapeSink } from '@ontrails/logging/logtape';
|
|
@@ -145,16 +86,10 @@ const logger = createLogger({
|
|
|
145
86
|
});
|
|
146
87
|
```
|
|
147
88
|
|
|
148
|
-
`@logtape/logtape` is an optional peer dependency.
|
|
149
|
-
|
|
150
|
-
## Subpath Exports
|
|
89
|
+
`@logtape/logtape` is an optional peer dependency.
|
|
151
90
|
|
|
152
|
-
|
|
153
|
-
| --- | --- |
|
|
154
|
-
| `@ontrails/logging` | `createLogger`, `createConsoleSink`, `createFileSink`, `createJsonFormatter`, `createPrettyFormatter`, level resolution |
|
|
155
|
-
| `@ontrails/logging/logtape` | `logtapeSink` adapter (requires `@logtape/logtape` peer) |
|
|
156
|
-
|
|
157
|
-
## Further Reading
|
|
91
|
+
## Installation
|
|
158
92
|
|
|
159
|
-
|
|
160
|
-
|
|
93
|
+
```bash
|
|
94
|
+
bun add @ontrails/logging @ontrails/core
|
|
95
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontrails/logging",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@ontrails/core": "workspace
|
|
18
|
+
"@ontrails/core": "workspace:^"
|
|
19
19
|
},
|
|
20
20
|
"peerDependenciesMeta": {
|
|
21
21
|
"@logtape/logtape": {
|