@meadown/logger 1.8.7 → 1.8.9

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # @meadown/logger
4
4
 
5
- A **development-focused logger** for Node.js and TypeScript built to make your
5
+ A **development-focused logger** for Node.js and TypeScript. Built to make your
6
6
  development loop faster and your terminal actually readable.
7
7
 
8
8
  No dependencies. No config. Import it and you're done.
@@ -10,7 +10,7 @@ No dependencies. No config. Import it and you're done.
10
10
  ## Why this exists
11
11
 
12
12
  I kept writing the same `console.log` wrapper in every project. Every time.
13
- Copy, paste, rename. And I still shipped it to production by accident. And I
13
+ Copy, paste, rename. And I still shipped it to production by accident. Unconsciously I
14
14
  still spent ten minutes staring at logs trying to figure out which file they
15
15
  came from.
16
16
 
@@ -19,6 +19,10 @@ At some point I just built the thing I always wanted.
19
19
  One import. No config. No dependencies. It shows you exactly where every log
20
20
  came from, and it gets out of the way when you ship.
21
21
 
22
+ It's not trying to be Winston or Pino. No transports, no log levels, no config files.
23
+ Just a better `console.log` for the hours you spend in development. One that
24
+ tells you where things came from and disappears when you ship.
25
+
22
26
  > The full story — the problem, the research, every design decision, and
23
27
  > everything that got cut — is in [`docs/STORY.md`](docs/STORY.md).
24
28
 
@@ -26,8 +30,8 @@ came from, and it gets out of the way when you ship.
26
30
 
27
31
  - **Zero dependencies**
28
32
  - **Development-focused** — built for the dev experience, not production ops
29
- - **Clickable source link** — every log is a clickable link to the exact file it came from
30
- - **API response logging** — `tap` a fetch and get timing, status, size, and body automatically
33
+ - **Clickable source link** — every log is a clickable link that jumps to the exact file and line it came from
34
+ - **Tap logging** — log any value or promise inline; fetch calls also get timing, status, size, and body
31
35
  - **Color-coded levels** — `[INFO]` cyan, `[WARN]` yellow, `[ERROR]` red
32
36
  - **Tree layout output** — clean, scannable structure in your terminal
33
37
  - **Collapsible messages** — cap long output with `logger.maxLines`
@@ -44,6 +48,9 @@ yarn add @meadown/logger
44
48
 
45
49
  ## Using it
46
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.
53
+
47
54
  ```ts
48
55
  import logger from "@meadown/logger"
49
56
 
@@ -60,9 +67,41 @@ logger.error("Something went wrong")
60
67
  └── 05-30 04:00:00 PM - (server.ts:42)
61
68
  ```
62
69
 
70
+ ### Recommended: single shared import
71
+
72
+ Rather than importing directly from `@meadown/logger` in every file, create
73
+ one shared module in your project and re-export from there. This gives you a
74
+ single place to set options like `maxLines` and keeps any future changes to
75
+ one file.
76
+
77
+ ```ts
78
+ // lib/logger.ts
79
+ import logger from "@meadown/logger"
80
+
81
+ logger.maxLines = 10 // configure once, applies everywhere
82
+
83
+ export default logger
84
+ ```
85
+
86
+ ```ts
87
+ // anywhere else in your project
88
+ import logger from "@/lib/logger"
89
+ ```
90
+
91
+ When re-exporting, use a direct re-export, Not a wrapper function. A wrapper
92
+ breaks the caller location shown in every log line.
93
+
94
+ ```ts
95
+ // GOOD — location stays honest
96
+ export { default as logger } from "@meadown/logger"
97
+
98
+ // BAD — every log points at this file, not the real caller
99
+ export const logger = (...args) => log(...args)
100
+ ```
101
+
63
102
  ## API response logging
64
103
 
65
- Drop `tap` into any `await` chain you get timing, status, size, and the
104
+ Drop `tap` into any `await` chain. You get timing, status, size, and the
66
105
  actual response body. The promise flows through untouched. One line of code.
67
106
 
68
107
  ```ts
@@ -93,25 +132,43 @@ const user = await logger.tap(
93
132
  You can immediately see: was it successful? How long did it take? What came
94
133
  back? Without opening DevTools.
95
134
 
96
- ![API response logging tap a fetch and see timing, status, size, and body](media/tap-api-demo.png)
135
+ ![API response logging: tap a fetch and see timing, status, size, and body](media/tap-api-demo.png)
136
+
137
+ ### Tap any value
138
+
139
+ `tap` works on anything, not just fetch. Pass in any value or expression and
140
+ get it back exactly as it was. The only thing that happens is a log.
141
+
142
+ ```ts
143
+ // numbers, strings, objects — logged and returned as-is
144
+ logger.tap(port, "port")
145
+ logger.tap(process.env.NODE_ENV, "env")
146
+ logger.tap(config, "loaded config")
147
+ ```
97
148
 
98
- Works with plain values too — logs it, returns it, nothing changes:
149
+ ```ts
150
+ // async functions — promise flows through, timing logged when it settles
151
+ const user = await logger.tap(getUser(), "getUser")
152
+ const config = await logger.tap(loadConfig(), "loadConfig")
153
+ ```
99
154
 
100
155
  ```ts
101
- const port = logger.tap(5000, "port") // port is still 5000
102
- const user = logger.tap(await getUser(), "user") // same as without tap
156
+ // inline no temp variable needed
157
+ server.listen(logger.tap(port, "port"))
103
158
  ```
104
159
 
160
+ If it's a promise, `tap` logs elapsed time once it settles. If it resolves
161
+ to a `Response` (any fetch like call), you also get status and size, same
162
+ as the fetch example above.
163
+
105
164
  ## Clickable source link
106
165
 
107
- That `(server.ts:42)` is a **clickable link** open it and you land on the exact
108
- line that wrote the log. Works in VS Code, iTerm2, WezTerm, Kitty, and Windows
109
- Terminal. Degrades to plain text everywhere else.
166
+ That `(server.ts:42)` is a **clickable link**. Click it and your editor opens the file and jumps straight to that line. Works in VS Code, iTerm2, WezTerm, Kitty, and Windows Terminal. Degrades to plain text everywhere else.
110
167
 
111
168
  ## Color-coded levels
112
169
 
113
- `[INFO]` cyan · `[WARN]` yellow · `[ERROR]` red. Timestamp and location tinted teal.
114
- Auto-disabled when output is piped no escape codes in your log files.
170
+ `[INFO]` , `[TAP]` cyan · `[WARN]` yellow · `[ERROR]` red. Timestamp and location tinted teal.
171
+ Auto-disabled when output is piped no escape codes in your log files.
115
172
 
116
173
  ## Tree layout output
117
174
 
@@ -121,7 +178,7 @@ Auto-disabled when output is piped — no escape codes in your log files.
121
178
  └── 05-30 04:00:00 PM - (server.ts:42)
122
179
  ```
123
180
 
124
- Level tag, message, timestamp, and location all in a clean tree. Easy to scan,
181
+ Level tag, message, timestamp, and location all in a clean tree. Easy to scan,
125
182
  even in a busy terminal.
126
183
 
127
184
  ## Collapsible messages
@@ -131,34 +188,25 @@ logger.maxLines = 5 // show 5 lines, then "... N more lines"
131
188
  logger.maxLines = 0 // default — show everything
132
189
  ```
133
190
 
134
- ### One thing if you re-export it
135
-
136
- ```ts
137
- // GOOD — location stays honest
138
- export { default as logger } from "@meadown/logger"
139
-
140
- // BAD — every log points at this file, not the real caller
141
- export const logger = (...args) => log(...args)
142
- ```
143
-
144
191
  ## NODE_ENV
145
192
 
146
- This logger reads `NODE_ENV` to decide when to log. By default it logs everywhere
147
- except `production`. This is a deliberate dev-focused default a production-grade
148
- logger with transport, persistence, and log levels is a separate concern and a
149
- future direction.
193
+ You shouldn't have to think about whether your logs will leak into production.
194
+ This package reads `NODE_ENV` and handles it for you. Set it to `production`
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.
150
197
 
151
- | `NODE_ENV` | Logs? |
152
- | ---------------------------------------- | ------ |
153
- | not set, `development`, or anything else | shown |
154
- | `production` | silent |
198
+ | `NODE_ENV` | Logs? |
199
+ | ---------------------------------------- | ---------- |
200
+ | not set, `development`, or anything else | shown |
201
+ | `production` | suppressed |
155
202
 
156
203
  ## Security
157
204
 
158
205
  Zero dependencies, no file or network access, nothing persisted.
159
- See [SECURITY.md](https://github.com/meadown/meadown-logger/blob/main/SECURITY.md)
160
- for the full security model.
206
+ See [SECURITY.md](https://github.com/meadown/meadown-logger/blob/main/SECURITY.md) for the full security model.
161
207
 
162
208
  ## License
163
209
 
164
- MIT © meadown
210
+ Architected and developed by [Dewan Mobashirul](https://linkedin.com/in/dewan-meadown)
211
+
212
+ MIT © [meadown](https://github.com/meadown)
@@ -61,7 +61,7 @@ function renderMessage(args, useColor) {
61
61
  */
62
62
  function formatLocation(caller, interactive) {
63
63
  if (caller.file !== null && caller.line !== null && interactive)
64
- return (0, link_js_1.hyperlink)(caller.label, (0, link_js_1.fileUrl)(caller.file));
64
+ return (0, link_js_1.hyperlink)(caller.label, (0, link_js_1.fileUrl)(caller.file, caller.line));
65
65
  return caller.label;
66
66
  }
67
67
  /**
@@ -1,11 +1,9 @@
1
1
  /**
2
- * Builds a valid `file://` URL for a path so terminals can open it on click.
3
- * Paths already in `file://` form are used as-is. We intentionally do NOT append
4
- * `:line` that isn't a valid URI and breaks file openers (e.g. GNOME/`gio`,
5
- * which would look for a file literally named `foo.ts:42`). The line number
6
- * stays visible in the link's display text instead.
2
+ * Builds a `file://` URL for a path so terminals can open it on click.
3
+ * When `line` is provided, appends `:line` so supporting terminals (VS Code,
4
+ * iTerm2, WezTerm) jump straight to that line.
7
5
  */
8
- export declare function fileUrl(file: string): string;
6
+ export declare function fileUrl(file: string, line?: number): string;
9
7
  /**
10
8
  * Wraps `text` in an OSC-8 terminal hyperlink pointing at `url`. Terminals that
11
9
  * support OSC-8 render `text` as a clickable link; others ignore the escape and
@@ -10,14 +10,13 @@ exports.fileUrl = fileUrl;
10
10
  exports.hyperlink = hyperlink;
11
11
  const node_url_1 = require("node:url");
12
12
  /**
13
- * Builds a valid `file://` URL for a path so terminals can open it on click.
14
- * Paths already in `file://` form are used as-is. We intentionally do NOT append
15
- * `:line` that isn't a valid URI and breaks file openers (e.g. GNOME/`gio`,
16
- * which would look for a file literally named `foo.ts:42`). The line number
17
- * stays visible in the link's display text instead.
13
+ * Builds a `file://` URL for a path so terminals can open it on click.
14
+ * When `line` is provided, appends `:line` so supporting terminals (VS Code,
15
+ * iTerm2, WezTerm) jump straight to that line.
18
16
  */
19
- function fileUrl(file) {
20
- return file.startsWith("file://") ? file : (0, node_url_1.pathToFileURL)(file).href;
17
+ function fileUrl(file, line) {
18
+ const base = file.startsWith("file://") ? file : (0, node_url_1.pathToFileURL)(file).href;
19
+ return line != null ? `${base}:${line}` : base;
21
20
  }
22
21
  /**
23
22
  * Wraps `text` in an OSC-8 terminal hyperlink pointing at `url`. Terminals that
@@ -53,7 +53,7 @@ function renderMessage(args, useColor) {
53
53
  */
54
54
  function formatLocation(caller, interactive) {
55
55
  if (caller.file !== null && caller.line !== null && interactive)
56
- return hyperlink(caller.label, fileUrl(caller.file));
56
+ return hyperlink(caller.label, fileUrl(caller.file, caller.line));
57
57
  return caller.label;
58
58
  }
59
59
  /**
@@ -1,11 +1,9 @@
1
1
  /**
2
- * Builds a valid `file://` URL for a path so terminals can open it on click.
3
- * Paths already in `file://` form are used as-is. We intentionally do NOT append
4
- * `:line` that isn't a valid URI and breaks file openers (e.g. GNOME/`gio`,
5
- * which would look for a file literally named `foo.ts:42`). The line number
6
- * stays visible in the link's display text instead.
2
+ * Builds a `file://` URL for a path so terminals can open it on click.
3
+ * When `line` is provided, appends `:line` so supporting terminals (VS Code,
4
+ * iTerm2, WezTerm) jump straight to that line.
7
5
  */
8
- export declare function fileUrl(file: string): string;
6
+ export declare function fileUrl(file: string, line?: number): string;
9
7
  /**
10
8
  * Wraps `text` in an OSC-8 terminal hyperlink pointing at `url`. Terminals that
11
9
  * support OSC-8 render `text` as a clickable link; others ignore the escape and
@@ -6,14 +6,13 @@
6
6
  */
7
7
  import { pathToFileURL } from "node:url";
8
8
  /**
9
- * Builds a valid `file://` URL for a path so terminals can open it on click.
10
- * Paths already in `file://` form are used as-is. We intentionally do NOT append
11
- * `:line` that isn't a valid URI and breaks file openers (e.g. GNOME/`gio`,
12
- * which would look for a file literally named `foo.ts:42`). The line number
13
- * stays visible in the link's display text instead.
9
+ * Builds a `file://` URL for a path so terminals can open it on click.
10
+ * When `line` is provided, appends `:line` so supporting terminals (VS Code,
11
+ * iTerm2, WezTerm) jump straight to that line.
14
12
  */
15
- export function fileUrl(file) {
16
- return file.startsWith("file://") ? file : pathToFileURL(file).href;
13
+ export function fileUrl(file, line) {
14
+ const base = file.startsWith("file://") ? file : pathToFileURL(file).href;
15
+ return line != null ? `${base}:${line}` : base;
17
16
  }
18
17
  /**
19
18
  * Wraps `text` in an OSC-8 terminal hyperlink pointing at `url`. Terminals that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meadown/logger",
3
- "version": "1.8.7",
3
+ "version": "1.8.9",
4
4
  "description": "A development-focused logger for Node.js and TypeScript — zero dependencies, clickable source links, and API response logging built in.",
5
5
  "keywords": [
6
6
  "logger",