@evdy-consumer/dailyom-suite-logging 0.0.3-bpegg.1 → 0.0.4-beta.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/README.md +97 -97
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
# DailyOM Logging Library
|
|
2
|
-
|
|
3
|
-
This library was generated with Nx.
|
|
4
|
-
|
|
5
|
-
The logging library provides a unified logging solution for Next.js and backend systems in the DailyOM Suite monorepo. It implements distributed tracing through trace and span IDs, allowing for correlation of logs across service boundaries.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
- **Trace Context Management**: Automatic generation and propagation of trace and span IDs
|
|
9
|
-
- **Hierarchical Spans**: Create child spans for tracking operations within a request
|
|
10
|
-
- **Configurable Output**: Log to console, files, or both
|
|
11
|
-
- **Daily Log Rotation**: Automated log file rotation with size thresholds
|
|
12
|
-
- **Context Preservation**: Maintains trace context across asynchronous operations using AsyncLocalStorage
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
Basic Logging
|
|
17
|
-
```typescript
|
|
18
|
-
import { TracedLogger } from '@dailyom-suite/logging';
|
|
19
|
-
|
|
20
|
-
// Create a logger instance
|
|
21
|
-
const logger = new TracedLogger({
|
|
22
|
-
name: 'my-service',
|
|
23
|
-
level: 'info', // Optional: default is 'info'
|
|
24
|
-
logToConsole: true, // Optional: default is true
|
|
25
|
-
logToFile: true, // Optional: default is true
|
|
26
|
-
fileName: 'app-name.log' // Optional: default uses name + timestamp
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// Log messages with context
|
|
30
|
-
logger.info({ userId: '123' }, 'User logged in');
|
|
31
|
-
logger.error({ orderId: '456' }, 'Failed to process order');
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Trace Context and Spans
|
|
35
|
-
```typescript
|
|
36
|
-
// Create a traced operation
|
|
37
|
-
logger.withSpan('database-query', () => {
|
|
38
|
-
// All logs in this function will share the same trace context
|
|
39
|
-
logger.debug({ query: 'SELECT * FROM users' }, 'Executing query');
|
|
40
|
-
// ...
|
|
41
|
-
return result;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// For async operations
|
|
45
|
-
await logger.withSpanAsync('api-request', async () => {
|
|
46
|
-
logger.info({ url: '/api/data' }, 'Making API request');
|
|
47
|
-
const response = await fetch('/api/data');
|
|
48
|
-
logger.info({ status: response.status }, 'Received API response');
|
|
49
|
-
return response.json();
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Manual Trace Context Manipulation
|
|
54
|
-
```typescript
|
|
55
|
-
import {
|
|
56
|
-
createTraceContext,
|
|
57
|
-
createChildSpan,
|
|
58
|
-
traceContextStorage
|
|
59
|
-
} from '@dailyom-suite/logging';
|
|
60
|
-
|
|
61
|
-
// Create a new trace context
|
|
62
|
-
const context = createTraceContext();
|
|
63
|
-
|
|
64
|
-
// Create a child span from parent context
|
|
65
|
-
const childContext = createChildSpan(context);
|
|
66
|
-
|
|
67
|
-
// Run code with a specific trace context
|
|
68
|
-
traceContextStorage.run(context, () => {
|
|
69
|
-
// All logs in this scope will use this context
|
|
70
|
-
});
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Configuration
|
|
74
|
-
The library looks for the following environment variables:
|
|
75
|
-
|
|
76
|
-
- [LOG_DIR](src/lib/logging.ts): Directory where log files will be stored (defaults to ./logs)
|
|
77
|
-
|
|
78
|
-
## Log File Management
|
|
79
|
-
Log files follow this naming pattern:
|
|
80
|
-
```
|
|
81
|
-
{app-name}.{YYYY-MM-DD}.{HH-MM-SS}.log
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Files rotate:
|
|
85
|
-
|
|
86
|
-
- Every day (24 hours)
|
|
87
|
-
- When they exceed 10MB in size
|
|
88
|
-
|
|
89
|
-
## Building
|
|
90
|
-
Run `nx build logging` to build the library.
|
|
91
|
-
|
|
92
|
-
## Running unit tests
|
|
93
|
-
Run `nx test logging` to execute the unit tests via Jest.
|
|
94
|
-
|
|
95
|
-
## CI
|
|
96
|
-
|
|
97
|
-
PRs that contain changes to logging will run tests and builds to ensure project structure is adhered to
|
|
1
|
+
# DailyOM Logging Library
|
|
2
|
+
|
|
3
|
+
This library was generated with Nx.
|
|
4
|
+
|
|
5
|
+
The logging library provides a unified logging solution for Next.js and backend systems in the DailyOM Suite monorepo. It implements distributed tracing through trace and span IDs, allowing for correlation of logs across service boundaries.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
- **Trace Context Management**: Automatic generation and propagation of trace and span IDs
|
|
9
|
+
- **Hierarchical Spans**: Create child spans for tracking operations within a request
|
|
10
|
+
- **Configurable Output**: Log to console, files, or both
|
|
11
|
+
- **Daily Log Rotation**: Automated log file rotation with size thresholds
|
|
12
|
+
- **Context Preservation**: Maintains trace context across asynchronous operations using AsyncLocalStorage
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
Basic Logging
|
|
17
|
+
```typescript
|
|
18
|
+
import { TracedLogger } from '@dailyom-suite/logging';
|
|
19
|
+
|
|
20
|
+
// Create a logger instance
|
|
21
|
+
const logger = new TracedLogger({
|
|
22
|
+
name: 'my-service',
|
|
23
|
+
level: 'info', // Optional: default is 'info'
|
|
24
|
+
logToConsole: true, // Optional: default is true
|
|
25
|
+
logToFile: true, // Optional: default is true
|
|
26
|
+
fileName: 'app-name.log' // Optional: default uses name + timestamp
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Log messages with context
|
|
30
|
+
logger.info({ userId: '123' }, 'User logged in');
|
|
31
|
+
logger.error({ orderId: '456' }, 'Failed to process order');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Trace Context and Spans
|
|
35
|
+
```typescript
|
|
36
|
+
// Create a traced operation
|
|
37
|
+
logger.withSpan('database-query', () => {
|
|
38
|
+
// All logs in this function will share the same trace context
|
|
39
|
+
logger.debug({ query: 'SELECT * FROM users' }, 'Executing query');
|
|
40
|
+
// ...
|
|
41
|
+
return result;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// For async operations
|
|
45
|
+
await logger.withSpanAsync('api-request', async () => {
|
|
46
|
+
logger.info({ url: '/api/data' }, 'Making API request');
|
|
47
|
+
const response = await fetch('/api/data');
|
|
48
|
+
logger.info({ status: response.status }, 'Received API response');
|
|
49
|
+
return response.json();
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Manual Trace Context Manipulation
|
|
54
|
+
```typescript
|
|
55
|
+
import {
|
|
56
|
+
createTraceContext,
|
|
57
|
+
createChildSpan,
|
|
58
|
+
traceContextStorage
|
|
59
|
+
} from '@dailyom-suite/logging';
|
|
60
|
+
|
|
61
|
+
// Create a new trace context
|
|
62
|
+
const context = createTraceContext();
|
|
63
|
+
|
|
64
|
+
// Create a child span from parent context
|
|
65
|
+
const childContext = createChildSpan(context);
|
|
66
|
+
|
|
67
|
+
// Run code with a specific trace context
|
|
68
|
+
traceContextStorage.run(context, () => {
|
|
69
|
+
// All logs in this scope will use this context
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
The library looks for the following environment variables:
|
|
75
|
+
|
|
76
|
+
- [LOG_DIR](src/lib/logging.ts): Directory where log files will be stored (defaults to ./logs)
|
|
77
|
+
|
|
78
|
+
## Log File Management
|
|
79
|
+
Log files follow this naming pattern:
|
|
80
|
+
```
|
|
81
|
+
{app-name}.{YYYY-MM-DD}.{HH-MM-SS}.log
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Files rotate:
|
|
85
|
+
|
|
86
|
+
- Every day (24 hours)
|
|
87
|
+
- When they exceed 10MB in size
|
|
88
|
+
|
|
89
|
+
## Building
|
|
90
|
+
Run `nx build logging` to build the library.
|
|
91
|
+
|
|
92
|
+
## Running unit tests
|
|
93
|
+
Run `nx test logging` to execute the unit tests via Jest.
|
|
94
|
+
|
|
95
|
+
## CI
|
|
96
|
+
|
|
97
|
+
PRs that contain changes to logging will run tests and builds to ensure project structure is adhered to
|