@logickernel/logger 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +50 -48
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -11,7 +11,7 @@ logger.error(new Error("something went wrong"));
11
11
  logger.warning("disk space low", { used: "92%", mount: "/data" });
12
12
  ```
13
13
 
14
- > Your code never has to care whether its running on Cloud Run / GCP or locally – the logger picks the right backend at startup.
14
+ > Your code never has to care whether it's running on Cloud Run / GCP or locally – the logger picks the right backend at startup.
15
15
 
16
16
  ---
17
17
 
@@ -27,42 +27,12 @@ logger.warning("disk space low", { used: "92%", mount: "/data" });
27
27
  - **Zero config in GCP**: Uses `K_SERVICE` and `GCP_PROJECT` from the environment.
28
28
  - **Auto backend selection**: GCP vs console decided once at module load.
29
29
  - **Full severity ladder**: `debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert`, `emergency`.
30
- - **Structured context**: Pass a plain object as the last argument — it becomes a `jsonPayload` in GCP (queryable by field) and compact inline JSON in the console.
30
+ - **Structured context**: Pass a plain object as the last argument — it becomes a `jsonPayload` in GCP (queryable by field) and inline JSON in the console.
31
31
  - **Tiny API**: One default export (`logger`) plus a `formatMessage` helper if you need it.
32
32
 
33
33
  ---
34
34
 
35
- ## 2. Local Setup (Development)
36
-
37
- ### Prerequisites
38
-
39
- - **Node.js**: v18+ recommended (any actively supported LTS should work).
40
- - **npm** (or compatible package manager).
41
-
42
- ### Clone and install
43
-
44
- ```bash
45
- git clone https://github.com/logickernel/logger.git
46
- cd logger
47
- npm install
48
- ```
49
-
50
- ### Useful scripts
51
-
52
- ```bash
53
- # Run tests
54
- npm test
55
-
56
- # Type-check
57
- npm run typecheck
58
-
59
- # Build the library
60
- npm run build
61
- ```
62
-
63
- ---
64
-
65
- ## 3. Installation & Usage (as a Library)
35
+ ## 2. Installation & Usage
66
36
 
67
37
  ### Install from npm
68
38
 
@@ -75,18 +45,22 @@ npm install @logickernel/logger
75
45
  ```ts
76
46
  import logger from "@logickernel/logger";
77
47
 
78
- logger.info("server started", { port: 3000 });
79
- logger.debug("user action", { userId: "123", action: "login" });
48
+ // Message only
49
+ logger.info("server started");
50
+ logger.debug("cache miss");
51
+ logger.error(new Error("connection refused"));
52
+
53
+ // Message with structured context
54
+ logger.info("server started", { port: 3000, env: "production" });
55
+ logger.debug("cache miss", { key: "user:42", ttl: 300 });
80
56
  logger.warning("disk space low", { used: "92%", mount: "/data" });
81
- logger.error(new Error("oops"));
82
- logger.critical("primary db unreachable", { host: "db-1" });
57
+ logger.error("request failed", { method: "POST", path: "/api/orders", status: 503 });
58
+ logger.critical("primary db unreachable", { host: "db-1", retries: 3 });
83
59
  ```
84
60
 
85
61
  The default export is a **singleton** whose backend is chosen at module load:
86
62
 
87
- - **GCP backend** is used when:
88
- - `SYSTEM_LOGS=gcp`, or
89
- - `K_SERVICE` is set (e.g. Cloud Run)
63
+ - **GCP backend** is used when `GCP_PROJECT` is set.
90
64
  - Otherwise, the **console backend** is used.
91
65
 
92
66
  ### Severity methods
@@ -111,26 +85,24 @@ logger.info("request complete", { method: "GET", path: "/api/users", status: 200
111
85
  ```
112
86
 
113
87
  - **GCP backend**: written as `jsonPayload` — fields are indexed and queryable in Cloud Logging.
114
- - **Console backend**: inlined as compact JSON on the same line.
88
+ - **Console backend**: inlined as spaced JSON on the same line.
115
89
 
116
90
  ### Console format
117
91
 
118
92
  ```
119
- 🐞 2026-02-26 13:04:22.341 user action { "userId": "123", "action": "login" }
93
+ ℹ️ 2026-02-26 13:04:22.120 server started
94
+ 🐞 2026-02-26 13:04:22.341 cache miss { "key": "user:42", "ttl": 300 }
120
95
  ⚠️ 2026-02-26 13:04:22.512 disk space low { "used": "92%", "mount": "/data" }
121
96
  ```
122
97
 
123
98
  ### Environment variables
124
99
 
125
- - `SYSTEM_LOGS=gcp`
126
- Force GCP logging even if `K_SERVICE` is not set.
100
+ - `GCP_PROJECT`
101
+ Project ID for Google Cloud Logging. When set, the GCP backend is used.
127
102
 
128
103
  - `K_SERVICE`
129
104
  Used as the log name in Google Cloud Logging. If not set, `"app"` is used.
130
105
 
131
- - `GCP_PROJECT`
132
- Project ID for Google Cloud Logging. Required when using the GCP backend.
133
-
134
106
  ### Named exports
135
107
 
136
108
  ```ts
@@ -142,8 +114,38 @@ const message = formatMessage(["hello", { id: 1 }]); // "hello {"id":1}"
142
114
 
143
115
  ---
144
116
 
117
+ ## 3. Local Setup (Development)
118
+
119
+ ### Prerequisites
120
+
121
+ - **Node.js**: v18+ recommended (any actively supported LTS should work).
122
+ - **npm** (or compatible package manager).
123
+
124
+ ### Clone and install
125
+
126
+ ```bash
127
+ git clone https://github.com/logickernel/logger.git
128
+ cd logger
129
+ npm install
130
+ ```
131
+
132
+ ### Useful scripts
133
+
134
+ ```bash
135
+ # Run tests
136
+ npm test
137
+
138
+ # Type-check
139
+ npm run typecheck
140
+
141
+ # Build the library
142
+ npm run build
143
+ ```
144
+
145
+ ---
146
+
145
147
  ## 4. Additional Resources
146
148
 
147
149
  - **Package**: `@logickernel/logger` on npm.
148
150
  - **License**: MIT (see `LICENSE` in this repository).
149
- - **Contributions**: Feel free to open issues or pull requests if youd like improvements (extra transports, richer metadata, etc.).
151
+ - **Contributions**: Feel free to open issues or pull requests if you'd like improvements (extra transports, richer metadata, etc.).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logickernel/logger",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",