jsonl-logger 0.2.2 → 0.2.3

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 (2) hide show
  1. package/README.md +37 -15
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # jsonl-logger
1
+ # JSONL Logger
2
2
 
3
- Lightweight JSON Lines (JSONL) logger with pluggable formatters. Modern ESM-only, zero dependencies, Bun-first, works on Node.js and Deno.
3
+ Lightweight JSON Lines logger with pluggable formatters (**Google Cloud Logging**, **VictoriaLogs**). Modern **ESM**-only, zero dependencies, Bun-first, works on Node.js and Deno.
4
+
5
+ Next.js (and other hardcoded plain text logs) become JSON-only logging for systems where it is required.
4
6
 
5
7
  ## Install
6
8
 
@@ -29,20 +31,14 @@ Set `LOG_FORMAT` to enable JSON output with a specific formatter:
29
31
 
30
32
  ```bash
31
33
  LOG_FORMAT=google-cloud-logging bun run server.ts
32
- ```
33
-
34
- ```typescript
35
- // Output: {"message":"...","timestamp":"...","severity":"INFO",...}
34
+ # Output: {"message":"...","timestamp":"...","severity":"INFO",...}
36
35
  ```
37
36
 
38
37
  ### VictoriaLogs
39
38
 
40
39
  ```bash
41
40
  LOG_FORMAT=victoria-logs bun run server.ts
42
- ```
43
-
44
- ```typescript
45
- // Output: {"_msg":"...","_time":"...","level":"info",...}
41
+ # Output: {"_msg":"...","_time":"...","level":"info",...}
46
42
  ```
47
43
 
48
44
  ### Custom Formatter
@@ -82,15 +78,41 @@ console.log('plain text') // → structured JSON
82
78
  originalConsole.log('bypass interception')
83
79
  ```
84
80
 
85
- ## Preload (Next.js Standalone)
81
+ ## Next.js Integration
86
82
 
87
- Auto-intercept from first line using `--preload`:
83
+ The preload module reads `LOG_FORMAT` and only activates when it's set. Safe to include unconditionally — it's a no-op without `LOG_FORMAT`.
88
84
 
89
- ```bash
90
- LOG_FORMAT=victoria-logs bun --preload jsonl-logger/preload server.js
85
+ ### Instrumentation
86
+
87
+ Next.js auto-detects `instrumentation.ts` at the project root. Use it to load the preload module on the server:
88
+
89
+ ```ts
90
+ export async function register() {
91
+ if (process.env.NEXT_RUNTIME === 'nodejs' || typeof Bun !== 'undefined') {
92
+ await import('jsonl-logger/preload')
93
+ }
94
+ }
91
95
  ```
92
96
 
93
- The preload module reads `LOG_FORMAT` and only activates when it's set. Safe to include unconditionally — it's a no-op without `LOG_FORMAT`.
97
+ ### Dockerfile (Standalone with Bun)
98
+
99
+ Next.js standalone output doesn't include all `node_modules`. Copy `jsonl-logger` explicitly from the build stage:
100
+
101
+ ```dockerfile
102
+ COPY --from=build /app/node_modules/jsonl-logger ./node_modules/jsonl-logger
103
+
104
+ ENV LOG_FORMAT=victoria-logs
105
+
106
+ CMD ["bun", "--preload", "jsonl-logger/preload", "server.js"]
107
+ ```
108
+
109
+ ### Node.js
110
+
111
+ For non-Bun deployments, use `--import` to preload:
112
+
113
+ ```bash
114
+ LOG_FORMAT=google-cloud-logging node --import jsonl-logger/preload server.js
115
+ ```
94
116
 
95
117
  ## Child Loggers
96
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsonl-logger",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Lightweight ESM-only JSON Lines logger with pluggable formatters for Google Cloud Logging, VictoriaLogs, and more",
5
5
  "license": "MIT",
6
6
  "type": "module",