@logickernel/logger 0.2.0 → 0.2.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/README.md +47 -40
- 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 it
|
|
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
|
|
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.
|
|
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 (as a Library)
|
|
66
36
|
|
|
67
37
|
### Install from npm
|
|
68
38
|
|
|
@@ -75,11 +45,17 @@ npm install @logickernel/logger
|
|
|
75
45
|
```ts
|
|
76
46
|
import logger from "@logickernel/logger";
|
|
77
47
|
|
|
78
|
-
|
|
79
|
-
logger.
|
|
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(
|
|
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:
|
|
@@ -111,12 +87,13 @@ logger.info("request complete", { method: "GET", path: "/api/users", status: 200
|
|
|
111
87
|
```
|
|
112
88
|
|
|
113
89
|
- **GCP backend**: written as `jsonPayload` — fields are indexed and queryable in Cloud Logging.
|
|
114
|
-
- **Console backend**: inlined as
|
|
90
|
+
- **Console backend**: inlined as spaced JSON on the same line.
|
|
115
91
|
|
|
116
92
|
### Console format
|
|
117
93
|
|
|
118
94
|
```
|
|
119
|
-
|
|
95
|
+
ℹ️ 2026-02-26 13:04:22.120 server started
|
|
96
|
+
🐞 2026-02-26 13:04:22.341 cache miss { "key": "user:42", "ttl": 300 }
|
|
120
97
|
⚠️ 2026-02-26 13:04:22.512 disk space low { "used": "92%", "mount": "/data" }
|
|
121
98
|
```
|
|
122
99
|
|
|
@@ -142,8 +119,38 @@ const message = formatMessage(["hello", { id: 1 }]); // "hello {"id":1}"
|
|
|
142
119
|
|
|
143
120
|
---
|
|
144
121
|
|
|
122
|
+
## 3. Local Setup (Development)
|
|
123
|
+
|
|
124
|
+
### Prerequisites
|
|
125
|
+
|
|
126
|
+
- **Node.js**: v18+ recommended (any actively supported LTS should work).
|
|
127
|
+
- **npm** (or compatible package manager).
|
|
128
|
+
|
|
129
|
+
### Clone and install
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
git clone https://github.com/logickernel/logger.git
|
|
133
|
+
cd logger
|
|
134
|
+
npm install
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Useful scripts
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Run tests
|
|
141
|
+
npm test
|
|
142
|
+
|
|
143
|
+
# Type-check
|
|
144
|
+
npm run typecheck
|
|
145
|
+
|
|
146
|
+
# Build the library
|
|
147
|
+
npm run build
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
145
152
|
## 4. Additional Resources
|
|
146
153
|
|
|
147
154
|
- **Package**: `@logickernel/logger` on npm.
|
|
148
155
|
- **License**: MIT (see `LICENSE` in this repository).
|
|
149
|
-
- **Contributions**: Feel free to open issues or pull requests if you
|
|
156
|
+
- **Contributions**: Feel free to open issues or pull requests if you'd like improvements (extra transports, richer metadata, etc.).
|