@meadown/logger 1.8.11 → 1.9.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 +149 -51
- package/dist/cjs/{config.js → config/index.js} +1 -1
- package/dist/cjs/{constants.d.ts → const/index.d.ts} +0 -5
- package/dist/cjs/{constants.js → const/index.js} +2 -8
- package/dist/cjs/{caller → domain/caller}/getCaller.js +1 -1
- package/dist/cjs/{colors → domain/colors}/color.js +1 -1
- package/dist/cjs/{decorations → domain/decorations}/link.js +1 -1
- package/dist/cjs/{terminal → domain/terminal}/isTTY.js +1 -1
- package/dist/cjs/{time → domain/time}/getTimeStamp.js +1 -1
- package/dist/cjs/domain/write/helpers/buildContext.d.ts +16 -0
- package/dist/cjs/domain/write/helpers/buildContext.js +40 -0
- package/dist/{core/writeLog → cjs/domain/write}/helpers/formatLocation.d.ts +1 -1
- package/dist/cjs/{core/writeLog → domain/write}/helpers/formatLocation.js +2 -2
- package/dist/cjs/{core/writeLog → domain/write}/helpers/index.d.ts +1 -0
- package/dist/cjs/{core/writeLog → domain/write}/helpers/index.js +5 -2
- package/dist/cjs/{core/writeLog → domain/write}/helpers/renderMessage.js +6 -5
- package/dist/cjs/{core/writeLog → domain/write}/helpers/visibleLines.js +3 -3
- package/dist/cjs/{core/writeLog → domain/write}/index.js +1 -1
- package/dist/{core/writeLog → cjs/domain/write}/writeLog.d.ts +2 -2
- package/dist/cjs/domain/write/writeLog.js +24 -0
- package/dist/cjs/features/logger/index.d.ts +1 -0
- package/dist/cjs/features/logger/index.js +21 -0
- package/dist/cjs/features/logger-error/index.d.ts +1 -0
- package/dist/cjs/features/logger-error/index.js +21 -0
- package/dist/cjs/features/logger-group/createGroup.d.ts +11 -0
- package/dist/cjs/features/logger-group/createGroup.js +21 -0
- package/dist/cjs/features/logger-group/index.d.ts +1 -0
- package/dist/cjs/features/logger-group/index.js +14 -0
- package/dist/cjs/features/logger-group/writeGroup.d.ts +8 -0
- package/dist/cjs/features/logger-group/writeGroup.js +20 -0
- package/dist/cjs/features/logger-max-lines/index.d.ts +1 -0
- package/dist/cjs/features/logger-max-lines/index.js +12 -0
- package/dist/cjs/features/logger-tap/createTap.d.ts +5 -0
- package/dist/cjs/features/logger-tap/createTap.js +33 -0
- package/dist/cjs/features/logger-tap/index.d.ts +1 -0
- package/dist/cjs/features/logger-tap/index.js +14 -0
- package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/buildBlock.js +2 -2
- package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/format.js +2 -2
- package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/index.js +1 -1
- package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/isThenable.js +1 -1
- package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/response.js +2 -2
- package/dist/cjs/{tap → features/logger-tap}/tapAsync/index.js +1 -1
- package/dist/cjs/{tap → features/logger-tap}/tapAsync/tapAsync.d.ts +1 -1
- package/dist/cjs/{tap → features/logger-tap}/tapAsync/tapAsync.js +6 -3
- package/dist/cjs/features/logger-warn/index.d.ts +1 -0
- package/dist/cjs/features/logger-warn/index.js +21 -0
- package/dist/cjs/index.d.ts +17 -1
- package/dist/cjs/index.js +12 -8
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/cjs/types/index.js +8 -0
- package/dist/{config.js → config/index.js} +1 -1
- package/dist/{constants.d.ts → const/index.d.ts} +0 -5
- package/dist/{constants.js → const/index.js} +1 -7
- package/dist/{caller → domain/caller}/getCaller.js +1 -1
- package/dist/{colors → domain/colors}/color.js +1 -1
- package/dist/{decorations → domain/decorations}/link.js +1 -1
- package/dist/{terminal → domain/terminal}/isTTY.js +1 -1
- package/dist/{time → domain/time}/getTimeStamp.js +1 -1
- package/dist/domain/write/helpers/buildContext.d.ts +16 -0
- package/dist/domain/write/helpers/buildContext.js +33 -0
- package/dist/{cjs/core/writeLog → domain/write}/helpers/formatLocation.d.ts +1 -1
- package/dist/{core/writeLog → domain/write}/helpers/formatLocation.js +2 -2
- package/dist/{core/writeLog → domain/write}/helpers/index.d.ts +1 -0
- package/dist/{core/writeLog → domain/write}/helpers/index.js +2 -1
- package/dist/{core/writeLog → domain/write}/helpers/renderMessage.js +5 -4
- package/dist/{core/writeLog → domain/write}/helpers/visibleLines.js +2 -2
- package/dist/{core/writeLog → domain/write}/index.js +1 -1
- package/dist/{cjs/core/writeLog → domain/write}/writeLog.d.ts +2 -2
- package/dist/domain/write/writeLog.js +21 -0
- package/dist/features/logger/index.d.ts +1 -0
- package/dist/features/logger/index.js +15 -0
- package/dist/features/logger-error/index.d.ts +1 -0
- package/dist/features/logger-error/index.js +15 -0
- package/dist/features/logger-group/createGroup.d.ts +11 -0
- package/dist/features/logger-group/createGroup.js +15 -0
- package/dist/features/logger-group/index.d.ts +1 -0
- package/dist/features/logger-group/index.js +7 -0
- package/dist/features/logger-group/writeGroup.d.ts +8 -0
- package/dist/features/logger-group/writeGroup.js +17 -0
- package/dist/features/logger-max-lines/index.d.ts +1 -0
- package/dist/features/logger-max-lines/index.js +7 -0
- package/dist/features/logger-tap/createTap.d.ts +5 -0
- package/dist/features/logger-tap/createTap.js +27 -0
- package/dist/features/logger-tap/index.d.ts +1 -0
- package/dist/features/logger-tap/index.js +7 -0
- package/dist/{tap → features/logger-tap}/tapAsync/helpers/buildBlock.js +2 -2
- package/dist/{tap → features/logger-tap}/tapAsync/helpers/format.js +2 -2
- package/dist/{tap → features/logger-tap}/tapAsync/helpers/index.js +1 -1
- package/dist/{tap → features/logger-tap}/tapAsync/helpers/isThenable.js +1 -1
- package/dist/{tap → features/logger-tap}/tapAsync/helpers/response.js +2 -2
- package/dist/{tap → features/logger-tap}/tapAsync/index.js +1 -1
- package/dist/{tap → features/logger-tap}/tapAsync/tapAsync.d.ts +1 -1
- package/dist/{tap → features/logger-tap}/tapAsync/tapAsync.js +6 -3
- package/dist/features/logger-warn/index.d.ts +1 -0
- package/dist/features/logger-warn/index.js +15 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +12 -8
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +7 -0
- package/package.json +1 -1
- package/dist/cjs/core/createLog.d.ts +0 -8
- package/dist/cjs/core/createLog.js +0 -29
- package/dist/cjs/core/writeLog/writeLog.js +0 -43
- package/dist/cjs/tap/createTap.d.ts +0 -18
- package/dist/cjs/tap/createTap.js +0 -51
- package/dist/core/createLog.d.ts +0 -8
- package/dist/core/createLog.js +0 -23
- package/dist/core/writeLog/writeLog.js +0 -37
- package/dist/tap/createTap.d.ts +0 -18
- package/dist/tap/createTap.js +0 -45
- /package/dist/cjs/{config.d.ts → config/index.d.ts} +0 -0
- /package/dist/{caller → cjs/domain/caller}/getCaller.d.ts +0 -0
- /package/dist/cjs/{colors → domain/colors}/color.d.ts +0 -0
- /package/dist/cjs/{decorations → domain/decorations}/link.d.ts +0 -0
- /package/dist/cjs/{terminal → domain/terminal}/isTTY.d.ts +0 -0
- /package/dist/cjs/{time → domain/time}/getTimeStamp.d.ts +0 -0
- /package/dist/cjs/{core/writeLog → domain/write}/helpers/renderMessage.d.ts +0 -0
- /package/dist/cjs/{core/writeLog → domain/write}/helpers/visibleLines.d.ts +0 -0
- /package/dist/cjs/{core/writeLog → domain/write}/index.d.ts +0 -0
- /package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/buildBlock.d.ts +0 -0
- /package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/format.d.ts +0 -0
- /package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/index.d.ts +0 -0
- /package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/isThenable.d.ts +0 -0
- /package/dist/cjs/{tap → features/logger-tap}/tapAsync/helpers/response.d.ts +0 -0
- /package/dist/cjs/{tap → features/logger-tap}/tapAsync/index.d.ts +0 -0
- /package/dist/{config.d.ts → config/index.d.ts} +0 -0
- /package/dist/{cjs → domain}/caller/getCaller.d.ts +0 -0
- /package/dist/{colors → domain/colors}/color.d.ts +0 -0
- /package/dist/{decorations → domain/decorations}/link.d.ts +0 -0
- /package/dist/{terminal → domain/terminal}/isTTY.d.ts +0 -0
- /package/dist/{time → domain/time}/getTimeStamp.d.ts +0 -0
- /package/dist/{core/writeLog → domain/write}/helpers/renderMessage.d.ts +0 -0
- /package/dist/{core/writeLog → domain/write}/helpers/visibleLines.d.ts +0 -0
- /package/dist/{core/writeLog → domain/write}/index.d.ts +0 -0
- /package/dist/{tap → features/logger-tap}/tapAsync/helpers/buildBlock.d.ts +0 -0
- /package/dist/{tap → features/logger-tap}/tapAsync/helpers/format.d.ts +0 -0
- /package/dist/{tap → features/logger-tap}/tapAsync/helpers/index.d.ts +0 -0
- /package/dist/{tap → features/logger-tap}/tapAsync/helpers/isThenable.d.ts +0 -0
- /package/dist/{tap → features/logger-tap}/tapAsync/helpers/response.d.ts +0 -0
- /package/dist/{tap → features/logger-tap}/tapAsync/index.d.ts +0 -0
package/README.md
CHANGED
|
@@ -30,11 +30,11 @@ tells you where things came from and disappears when you ship.
|
|
|
30
30
|
|
|
31
31
|
- **Zero dependencies**
|
|
32
32
|
- **Development-focused** — built for the dev experience, not production ops
|
|
33
|
-
- **Clickable source link** — every log
|
|
34
|
-
- **Tap logging** — log any value or promise inline
|
|
33
|
+
- **Clickable source link** — every log jumps straight to the file and line it came from
|
|
34
|
+
- **Tap logging** — log any value or promise inline without breaking the expression
|
|
35
35
|
- **Color-coded levels** — `[INFO]` cyan, `[WARN]` yellow, `[ERROR]` red
|
|
36
|
-
- **Tree layout
|
|
37
|
-
- **Collapsible
|
|
36
|
+
- **Tree layout** — clean, scannable structure in your terminal
|
|
37
|
+
- **Collapsible output** — cap long dumps with `logger.maxLines`
|
|
38
38
|
|
|
39
39
|
## Install
|
|
40
40
|
|
|
@@ -46,33 +46,27 @@ npm install @meadown/logger
|
|
|
46
46
|
yarn add @meadown/logger
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
##
|
|
50
|
-
|
|
51
|
-
Set `NODE_ENV=production` and all output is suppressed. Anything else and
|
|
52
|
-
logging is on. No config files, no init call, no options object.
|
|
49
|
+
## Quick start
|
|
53
50
|
|
|
54
51
|
```ts
|
|
55
52
|
import logger from "@meadown/logger"
|
|
56
53
|
|
|
57
|
-
logger("
|
|
58
|
-
logger("Auth", "user logged in")
|
|
59
|
-
|
|
60
|
-
logger.warn("This is deprecated")
|
|
61
|
-
logger.error("Something went wrong")
|
|
54
|
+
logger("server started", { port: 3000 })
|
|
62
55
|
```
|
|
63
56
|
|
|
64
57
|
```text
|
|
65
58
|
[INFO]
|
|
66
|
-
├──
|
|
67
|
-
└── 05-30 04:00:00 PM - (server.ts:
|
|
59
|
+
├── server started { port: 3000 }
|
|
60
|
+
└── 05-30 04:00:00 PM - (server.ts:5)
|
|
68
61
|
```
|
|
69
62
|
|
|
70
|
-
|
|
63
|
+
Works out of the box. Set `NODE_ENV=production` when you ship and the logs
|
|
64
|
+
disappear — no wrappers, no cleanup, nothing to remember.
|
|
65
|
+
|
|
66
|
+
### Single shared import
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
one
|
|
74
|
-
single place to set options like `maxLines` and keeps any future changes to
|
|
75
|
-
one file.
|
|
68
|
+
Create one module in your project and re-export from there. One place to set
|
|
69
|
+
options, one place to change if you ever need to.
|
|
76
70
|
|
|
77
71
|
```ts
|
|
78
72
|
// lib/logger.ts
|
|
@@ -88,8 +82,8 @@ export default logger
|
|
|
88
82
|
import logger from "@/lib/logger"
|
|
89
83
|
```
|
|
90
84
|
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
Use a direct re-export — not a wrapper function. A wrapper breaks the
|
|
86
|
+
`(file:line)` link on every log.
|
|
93
87
|
|
|
94
88
|
```ts
|
|
95
89
|
// GOOD — location stays honest
|
|
@@ -99,10 +93,62 @@ export { default as logger } from "@meadown/logger"
|
|
|
99
93
|
export const logger = (...args) => log(...args)
|
|
100
94
|
```
|
|
101
95
|
|
|
102
|
-
## API
|
|
96
|
+
## API
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
┌─────────────────┬─────────────┬──────────────────────────┬───────────────────────────┐
|
|
100
|
+
│ Method │ Tag │ Params │ Purpose │
|
|
101
|
+
├─────────────────┼─────────────┼──────────────────────────┼───────────────────────────┤
|
|
102
|
+
│ logger() │ [INFO] │ ...args: unknown[] │ general info │
|
|
103
|
+
├─────────────────┼─────────────┼──────────────────────────┼───────────────────────────┤
|
|
104
|
+
│ logger.warn() │ [WARN] │ ...args: unknown[] │ something needs attention │
|
|
105
|
+
├─────────────────┼─────────────┼──────────────────────────┼───────────────────────────┤
|
|
106
|
+
│ logger.error() │ [ERROR] │ ...args: unknown[] │ something broke │
|
|
107
|
+
├─────────────────┼─────────────┼──────────────────────────┼───────────────────────────┤
|
|
108
|
+
│ logger.tap() │ [TAP] │ value: T, label?: string │ log value, returns as-is │
|
|
109
|
+
├─────────────────┼─────────────┼──────────────────────────┼───────────────────────────┤
|
|
110
|
+
│ logger.group() │ [name] │ { name: string, │ consolidate related │
|
|
111
|
+
│ │ │ type?: LogChannel, │ items under a label │
|
|
112
|
+
│ │ │ logs: unknown[] } │ │
|
|
113
|
+
├─────────────────┼─────────────┼──────────────────────────┼───────────────────────────┤
|
|
114
|
+
│ logger.maxLines │ — │ number │ cap output at N lines │
|
|
115
|
+
└─────────────────┴─────────────┴──────────────────────────┴───────────────────────────┘
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Every tag is self-describing. You scan the logs and immediately know what each
|
|
119
|
+
entry is without reading the message. That's the design principle holding the
|
|
120
|
+
whole API together.
|
|
121
|
+
|
|
122
|
+
### `logger()`
|
|
123
|
+
|
|
124
|
+
Your everyday log. Pass it anything — strings, objects, errors, whatever.
|
|
125
|
+
Works exactly like `console.log`, just prettier.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
logger("server started")
|
|
129
|
+
logger("user logged in", { userId: 42, role: "admin" })
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
[INFO]
|
|
134
|
+
├── user logged in { userId: 42, role: 'admin' }
|
|
135
|
+
└── 05-30 04:00:00 PM - (server.ts:12)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `logger.tap()`
|
|
139
|
+
|
|
140
|
+
The one you reach for when you want to see what's inside something without
|
|
141
|
+
stopping to assign it to a variable first. Logs it and gives it straight back.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const port = logger.tap(5000, "port")
|
|
145
|
+
server.listen(logger.tap(port, "port"))
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### API response logging
|
|
103
149
|
|
|
104
|
-
Drop
|
|
105
|
-
|
|
150
|
+
Drop it into any `await` and you get timing, status, size, and the response
|
|
151
|
+
body — without touching your code at all.
|
|
106
152
|
|
|
107
153
|
```ts
|
|
108
154
|
const user = await logger.tap(
|
|
@@ -129,15 +175,14 @@ const user = await logger.tap(
|
|
|
129
175
|
└── 05-30 07:54:26 PM - (api.ts:12)
|
|
130
176
|
```
|
|
131
177
|
|
|
132
|
-
|
|
133
|
-
|
|
178
|
+
Was it successful? How long did it take? What came back? All there, without
|
|
179
|
+
opening DevTools.
|
|
134
180
|
|
|
135
181
|

|
|
136
182
|
|
|
137
|
-
|
|
183
|
+
#### Tap any value
|
|
138
184
|
|
|
139
|
-
|
|
140
|
-
get it back exactly as it was. The only thing that happens is a log.
|
|
185
|
+
Not just fetch. Any value, any expression. Logged and returned as-is.
|
|
141
186
|
|
|
142
187
|
```ts
|
|
143
188
|
// numbers, strings, objects — logged and returned as-is
|
|
@@ -147,7 +192,7 @@ logger.tap(config, "loaded config")
|
|
|
147
192
|
```
|
|
148
193
|
|
|
149
194
|
```ts
|
|
150
|
-
//
|
|
195
|
+
// promises — flows through, timing logged when it settles
|
|
151
196
|
const user = await logger.tap(getUser(), "getUser")
|
|
152
197
|
const config = await logger.tap(loadConfig(), "loadConfig")
|
|
153
198
|
```
|
|
@@ -157,43 +202,96 @@ const config = await logger.tap(loadConfig(), "loadConfig")
|
|
|
157
202
|
server.listen(logger.tap(port, "port"))
|
|
158
203
|
```
|
|
159
204
|
|
|
160
|
-
If it's a promise,
|
|
161
|
-
|
|
162
|
-
as the fetch example above.
|
|
205
|
+
If it's a promise, timing is logged once it settles. If it resolves to a
|
|
206
|
+
`Response`, you also get status and size.
|
|
163
207
|
|
|
164
|
-
|
|
208
|
+
### `logger.group()`
|
|
165
209
|
|
|
166
|
-
|
|
210
|
+
Got a handful of related things to log at once? Group them. One block, one
|
|
211
|
+
timestamp, one place to look.
|
|
167
212
|
|
|
168
|
-
|
|
213
|
+
```ts
|
|
214
|
+
logger.group({
|
|
215
|
+
name: "Server setup",
|
|
216
|
+
logs: [
|
|
217
|
+
`Running on port ${port}`,
|
|
218
|
+
`Environment: ${env}`,
|
|
219
|
+
`API: http://localhost:${port}/api`,
|
|
220
|
+
],
|
|
221
|
+
})
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
[SERVER SETUP]
|
|
226
|
+
├── Running on port 5000
|
|
227
|
+
├── Environment: development
|
|
228
|
+
├── API: http://localhost:5000/api
|
|
229
|
+
└── 05-30 04:00:00 PM - (server.ts:23)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Use `type` to set the channel and tag color. Defaults to `"log"` (cyan, stdout).
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
logger.group({
|
|
236
|
+
name: "Validation failed",
|
|
237
|
+
type: "error", // red, stderr
|
|
238
|
+
logs: ["email invalid", "password too short"],
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
logger.group({
|
|
242
|
+
name: "Config warnings",
|
|
243
|
+
type: "warn", // yellow, stderr
|
|
244
|
+
logs: ["deprecated key found", "missing optional field"],
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
`logs` takes anything — strings, objects, arrays, errors. Each renders exactly
|
|
249
|
+
as `console.log` would.
|
|
250
|
+
|
|
251
|
+
### `logger.error()`
|
|
169
252
|
|
|
170
|
-
|
|
171
|
-
Auto-disabled when output is piped no escape codes in your log files.
|
|
253
|
+
Red tag, goes to `stderr`. Pass an `Error` and you get the stack too.
|
|
172
254
|
|
|
173
|
-
|
|
255
|
+
```ts
|
|
256
|
+
logger.error("database connection failed", new Error("ECONNREFUSED"))
|
|
257
|
+
```
|
|
174
258
|
|
|
175
259
|
```text
|
|
176
|
-
[
|
|
177
|
-
├──
|
|
178
|
-
|
|
260
|
+
[ERROR]
|
|
261
|
+
├── database connection failed Error: ECONNREFUSED
|
|
262
|
+
│ at Object.<anonymous> (server.ts:14:18)
|
|
263
|
+
└── 05-30 04:00:00 PM - (server.ts:14)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### `logger.warn()`
|
|
267
|
+
|
|
268
|
+
Yellow tag, `stderr`. For the things that aren't broken yet.
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
logger.warn("disk usage above 80%")
|
|
272
|
+
logger.warn("deprecated config key", { key: "timeout", use: "timeoutMs" })
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
```text
|
|
276
|
+
[WARN]
|
|
277
|
+
├── disk usage above 80%
|
|
278
|
+
└── 05-30 04:00:00 PM - (monitor.ts:8)
|
|
179
279
|
```
|
|
180
280
|
|
|
181
|
-
|
|
182
|
-
even in a busy terminal.
|
|
281
|
+
### `logger.maxLines`
|
|
183
282
|
|
|
184
|
-
|
|
283
|
+
Got a massive object dumping 200 lines? Set this and it cuts off after N lines
|
|
284
|
+
with a count of what's hidden. Set back to `0` to show everything again.
|
|
185
285
|
|
|
186
286
|
```ts
|
|
187
287
|
logger.maxLines = 5 // show 5 lines, then "... N more lines"
|
|
188
288
|
logger.maxLines = 0 // default — show everything
|
|
189
289
|
```
|
|
190
290
|
|
|
191
|
-
##
|
|
291
|
+
## Production
|
|
192
292
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
and all output is handled for you. You never have to remember to wrap a log call,
|
|
196
|
-
remove a debug line, or grep the codebase before a release.
|
|
293
|
+
Set `NODE_ENV=production` and everything goes silent. No wrapper calls, no
|
|
294
|
+
grep before release, no accidental logs in prod.
|
|
197
295
|
|
|
198
296
|
| `NODE_ENV` | Logs? |
|
|
199
297
|
| ---------------------------------------- | ---------- |
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { type Color } from "./colors/color.js";
|
|
2
|
-
/** The console channels the logger writes to. */
|
|
3
|
-
export type LogChannel = "log" | "error" | "warn";
|
|
4
|
-
/** The tag color per channel: info/tap → cyan, warn → yellow, error → red. */
|
|
5
|
-
export declare const TAG_COLOR: Record<LogChannel, Color>;
|
|
6
1
|
/** Glyphs that draw each entry's little tree. */
|
|
7
2
|
export declare const BRANCH = "\u251C\u2500\u2500";
|
|
8
3
|
export declare const BRANCH_END = "\u2514\u2500\u2500";
|
|
@@ -2,20 +2,14 @@
|
|
|
2
2
|
/*
|
|
3
3
|
* constants.ts
|
|
4
4
|
* Created by Dewan Mobashirul
|
|
5
|
-
* Copyright (c) 2026
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
6
|
* All rights reserved
|
|
7
7
|
*
|
|
8
8
|
* Single home for the logger's layout/behavior constants, so the values that
|
|
9
9
|
* shape an entry live in one place instead of as magic literals across modules.
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.DEFAULT_MAX_LINES = exports.MESSAGE_INDENT = exports.SEPARATOR = exports.BRANCH_END = exports.BRANCH =
|
|
13
|
-
/** The tag color per channel: info/tap → cyan, warn → yellow, error → red. */
|
|
14
|
-
exports.TAG_COLOR = {
|
|
15
|
-
log: "cyan",
|
|
16
|
-
warn: "yellow",
|
|
17
|
-
error: "red",
|
|
18
|
-
};
|
|
12
|
+
exports.DEFAULT_MAX_LINES = exports.MESSAGE_INDENT = exports.SEPARATOR = exports.BRANCH_END = exports.BRANCH = void 0;
|
|
19
13
|
/** Glyphs that draw each entry's little tree. */
|
|
20
14
|
exports.BRANCH = "├──"; // the message branch
|
|
21
15
|
exports.BRANCH_END = "└──"; // the last (metadata) branch
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type LogChannel } from "../../../types/index.js";
|
|
2
|
+
import { type Caller } from "../../caller/getCaller.js";
|
|
3
|
+
import { type Color } from "../../colors/color.js";
|
|
4
|
+
/** Tag color per channel — cyan for log/tap, yellow for warn, red for error. */
|
|
5
|
+
export declare const TAG_COLOR: Record<LogChannel, Color>;
|
|
6
|
+
export interface RenderContext {
|
|
7
|
+
useColor: boolean;
|
|
8
|
+
paint: (s: string, c: Color) => string;
|
|
9
|
+
timeStamp: string;
|
|
10
|
+
locOut: string;
|
|
11
|
+
connector: string;
|
|
12
|
+
connectorEnd: string;
|
|
13
|
+
separator: string;
|
|
14
|
+
}
|
|
15
|
+
/** Builds the shared paint/layout values used by both writeLog and writeGroup. */
|
|
16
|
+
export declare function buildContext(channel: LogChannel, caller: Caller): RenderContext;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* buildContext.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TAG_COLOR = void 0;
|
|
13
|
+
exports.buildContext = buildContext;
|
|
14
|
+
const index_js_1 = require("../../../const/index.js");
|
|
15
|
+
const color_js_1 = require("../../colors/color.js");
|
|
16
|
+
/** Tag color per channel — cyan for log/tap, yellow for warn, red for error. */
|
|
17
|
+
exports.TAG_COLOR = {
|
|
18
|
+
log: "cyan",
|
|
19
|
+
warn: "yellow",
|
|
20
|
+
error: "red",
|
|
21
|
+
};
|
|
22
|
+
const isTTY_js_1 = require("../../terminal/isTTY.js");
|
|
23
|
+
const getTimeStamp_js_1 = __importDefault(require("../../time/getTimeStamp.js"));
|
|
24
|
+
const formatLocation_js_1 = require("./formatLocation.js");
|
|
25
|
+
/** Builds the shared paint/layout values used by both writeLog and writeGroup. */
|
|
26
|
+
function buildContext(channel, caller) {
|
|
27
|
+
const streamName = channel === "log" ? "stdout" : "stderr";
|
|
28
|
+
const useColor = (0, isTTY_js_1.isTTY)(streamName);
|
|
29
|
+
const paint = (s, c) => (useColor ? (0, color_js_1.colorize)(s, c) : s);
|
|
30
|
+
const location = (0, formatLocation_js_1.formatLocation)(caller, useColor);
|
|
31
|
+
return {
|
|
32
|
+
useColor,
|
|
33
|
+
paint,
|
|
34
|
+
timeStamp: paint((0, getTimeStamp_js_1.default)(), "teal"),
|
|
35
|
+
locOut: paint(`(${location})`, "dimTeal"),
|
|
36
|
+
connector: paint(index_js_1.BRANCH, "gray"),
|
|
37
|
+
connectorEnd: paint(index_js_1.BRANCH_END, "gray"),
|
|
38
|
+
separator: paint(index_js_1.SEPARATOR, "gray"),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Caller } from "
|
|
1
|
+
import { type Caller } from "../../caller/getCaller.js";
|
|
2
2
|
/**
|
|
3
3
|
* Renders a caller as a `(file:line)` location — a clickable OSC-8 link on a
|
|
4
4
|
* supporting terminal, plain text otherwise. Pure (no stack access).
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/*
|
|
3
3
|
* formatLocation.ts
|
|
4
4
|
* Created by Dewan Mobashirul
|
|
5
|
-
* Copyright (c) 2026
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
6
|
* All rights reserved
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.formatLocation = formatLocation;
|
|
10
|
-
const link_js_1 = require("
|
|
10
|
+
const link_js_1 = require("../../decorations/link.js");
|
|
11
11
|
/**
|
|
12
12
|
* Renders a caller as a `(file:line)` location — a clickable OSC-8 link on a
|
|
13
13
|
* supporting terminal, plain text otherwise. Pure (no stack access).
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
/*
|
|
3
3
|
* index.ts
|
|
4
4
|
* Created by Dewan Mobashirul
|
|
5
|
-
* Copyright (c) 2026
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
6
|
* All rights reserved
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.formatLocation = exports.renderMessage = exports.setVisibleLines = exports.getVisibleLines = exports.visibleLines = void 0;
|
|
9
|
+
exports.TAG_COLOR = exports.buildContext = exports.formatLocation = exports.renderMessage = exports.setVisibleLines = exports.getVisibleLines = exports.visibleLines = void 0;
|
|
10
10
|
var visibleLines_js_1 = require("./visibleLines.js");
|
|
11
11
|
Object.defineProperty(exports, "visibleLines", { enumerable: true, get: function () { return visibleLines_js_1.visibleLines; } });
|
|
12
12
|
Object.defineProperty(exports, "getVisibleLines", { enumerable: true, get: function () { return visibleLines_js_1.getVisibleLines; } });
|
|
@@ -15,3 +15,6 @@ var renderMessage_js_1 = require("./renderMessage.js");
|
|
|
15
15
|
Object.defineProperty(exports, "renderMessage", { enumerable: true, get: function () { return renderMessage_js_1.renderMessage; } });
|
|
16
16
|
var formatLocation_js_1 = require("./formatLocation.js");
|
|
17
17
|
Object.defineProperty(exports, "formatLocation", { enumerable: true, get: function () { return formatLocation_js_1.formatLocation; } });
|
|
18
|
+
var buildContext_js_1 = require("./buildContext.js");
|
|
19
|
+
Object.defineProperty(exports, "buildContext", { enumerable: true, get: function () { return buildContext_js_1.buildContext; } });
|
|
20
|
+
Object.defineProperty(exports, "TAG_COLOR", { enumerable: true, get: function () { return buildContext_js_1.TAG_COLOR; } });
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
/*
|
|
3
3
|
* renderMessage.ts
|
|
4
4
|
* Created by Dewan Mobashirul
|
|
5
|
-
* Copyright (c) 2026
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
6
|
* All rights reserved
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.renderMessage = renderMessage;
|
|
10
10
|
const node_util_1 = require("node:util");
|
|
11
11
|
const visibleLines_js_1 = require("./visibleLines.js");
|
|
12
|
-
const color_js_1 = require("
|
|
13
|
-
const
|
|
12
|
+
const color_js_1 = require("../../colors/color.js");
|
|
13
|
+
const index_js_1 = require("../../../const/index.js");
|
|
14
14
|
/**
|
|
15
15
|
* Collapses a long multi-line message to {@link visibleLines} lines, replacing
|
|
16
16
|
* the rest with a dimmed `… N more lines` summary. When `visibleLines` is 0
|
|
@@ -23,7 +23,7 @@ function collapse(text, useColor) {
|
|
|
23
23
|
if (lines.length <= visibleLines_js_1.visibleLines)
|
|
24
24
|
return text;
|
|
25
25
|
const hidden = lines.length - visibleLines_js_1.visibleLines;
|
|
26
|
-
const summary = `${
|
|
26
|
+
const summary = `${index_js_1.MESSAGE_INDENT}... ${hidden} more line${hidden === 1 ? "" : "s"}`;
|
|
27
27
|
const visible = lines.slice(0, visibleLines_js_1.visibleLines);
|
|
28
28
|
visible.push(useColor ? (0, color_js_1.colorize)(summary, "gray") : summary);
|
|
29
29
|
return visible.join("\n");
|
|
@@ -36,5 +36,6 @@ function collapse(text, useColor) {
|
|
|
36
36
|
*/
|
|
37
37
|
function renderMessage(args, useColor) {
|
|
38
38
|
const text = (0, node_util_1.formatWithOptions)({ colors: useColor }, ...args);
|
|
39
|
-
|
|
39
|
+
const indent = useColor ? (0, color_js_1.colorize)(index_js_1.MESSAGE_INDENT, "gray") : index_js_1.MESSAGE_INDENT;
|
|
40
|
+
return collapse(text.replace(/\n/g, `\n${indent}`), useColor);
|
|
40
41
|
}
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
/*
|
|
3
3
|
* visibleLines.ts
|
|
4
4
|
* Created by Dewan Mobashirul
|
|
5
|
-
* Copyright (c) 2026
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
6
|
* All rights reserved
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.visibleLines = void 0;
|
|
10
10
|
exports.getVisibleLines = getVisibleLines;
|
|
11
11
|
exports.setVisibleLines = setVisibleLines;
|
|
12
|
-
const
|
|
12
|
+
const index_js_1 = require("../../../const/index.js");
|
|
13
13
|
/** Max message lines to show before collapsing the rest; 0 (default) shows all. */
|
|
14
|
-
exports.visibleLines =
|
|
14
|
+
exports.visibleLines = index_js_1.DEFAULT_MAX_LINES;
|
|
15
15
|
/** How many lines a long message shows before collapsing (0 = all). */
|
|
16
16
|
function getVisibleLines() {
|
|
17
17
|
return exports.visibleLines;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type LogChannel } from "../../
|
|
2
|
-
import { type Caller } from "
|
|
1
|
+
import { type LogChannel } from "../../types/index.js";
|
|
2
|
+
import { type Caller } from "../caller/getCaller.js";
|
|
3
3
|
/**
|
|
4
4
|
* Renders and writes one log entry. The `caller` is resolved by the *caller* of
|
|
5
5
|
* this function (the log closure or `tap`) and passed in, so this helper never
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* writeLog.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.writeLog = writeLog;
|
|
10
|
+
const index_js_1 = require("./helpers/index.js");
|
|
11
|
+
/**
|
|
12
|
+
* Renders and writes one log entry. The `caller` is resolved by the *caller* of
|
|
13
|
+
* this function (the log closure or `tap`) and passed in, so this helper never
|
|
14
|
+
* touches the stack — keeping {@link getCaller}'s frame depth correct no matter
|
|
15
|
+
* which user-facing function delegates here.
|
|
16
|
+
*/
|
|
17
|
+
function writeLog(opts) {
|
|
18
|
+
const { channel, tag, args, caller } = opts;
|
|
19
|
+
const { useColor, paint, timeStamp, locOut, connector, connectorEnd, separator, } = (0, index_js_1.buildContext)(channel, caller);
|
|
20
|
+
const tagOut = paint(tag, index_js_1.TAG_COLOR[channel]);
|
|
21
|
+
const message = (0, index_js_1.renderMessage)(args, useColor);
|
|
22
|
+
const meta = `\n${connectorEnd} ${timeStamp} ${separator} ${locOut}`;
|
|
23
|
+
console[channel](`\n${tagOut} \n${connector} ${message}${meta}`);
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function log(...args: unknown[]): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* index.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.default = log;
|
|
13
|
+
const index_js_1 = require("../../config/index.js");
|
|
14
|
+
const getCaller_js_1 = __importDefault(require("../../domain/caller/getCaller.js"));
|
|
15
|
+
const writeLog_js_1 = require("../../domain/write/writeLog.js");
|
|
16
|
+
function log(...args) {
|
|
17
|
+
if (!(0, index_js_1.isLogAllowed)())
|
|
18
|
+
return;
|
|
19
|
+
const caller = (0, getCaller_js_1.default)();
|
|
20
|
+
(0, writeLog_js_1.writeLog)({ channel: "log", tag: "[INFO]", args, caller });
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function logError(...args: unknown[]): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* index.ts
|
|
4
|
+
* Created by Dewan Mobashirul
|
|
5
|
+
* Copyright (c) 2026 meadown
|
|
6
|
+
* All rights reserved
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.default = logError;
|
|
13
|
+
const index_js_1 = require("../../config/index.js");
|
|
14
|
+
const getCaller_js_1 = __importDefault(require("../../domain/caller/getCaller.js"));
|
|
15
|
+
const writeLog_js_1 = require("../../domain/write/writeLog.js");
|
|
16
|
+
function logError(...args) {
|
|
17
|
+
if (!(0, index_js_1.isLogAllowed)())
|
|
18
|
+
return;
|
|
19
|
+
const caller = (0, getCaller_js_1.default)();
|
|
20
|
+
(0, writeLog_js_1.writeLog)({ channel: "error", tag: "[ERROR]", args, caller });
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type LogChannel } from "../../types/index.js";
|
|
2
|
+
export interface GroupOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
type?: LogChannel;
|
|
5
|
+
logs: unknown[];
|
|
6
|
+
}
|
|
7
|
+
/** Type of `logger.group` — use this to annotate variables or parameters that accept it. */
|
|
8
|
+
export interface Group {
|
|
9
|
+
(opts: GroupOptions): void;
|
|
10
|
+
}
|
|
11
|
+
export default function group({ name, type, logs, }: GroupOptions): void;
|