@meadown/logger 1.2.0 → 1.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 +12 -16
- package/dist/cjs/utils/createLog.js +1 -1
- package/dist/cjs/utils/link.d.ts +12 -8
- package/dist/cjs/utils/link.js +14 -33
- package/dist/utils/createLog.js +1 -1
- package/dist/utils/createLog.js.map +1 -1
- package/dist/utils/link.d.ts +12 -8
- package/dist/utils/link.d.ts.map +1 -1
- package/dist/utils/link.js +14 -33
- package/dist/utils/link.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@ remember _which file_ a message came from — and worse, forgetting to pull thos
|
|
|
5
5
|
out before shipping. So I made this.
|
|
6
6
|
|
|
7
7
|
It's basically `console.log` with the rough edges sanded off: every message gets a
|
|
8
|
-
level tag, a timestamp, and
|
|
9
|
-
from. And it stays quiet in production, so you
|
|
10
|
-
not worry about them.
|
|
8
|
+
level tag, a timestamp, and the file and line it came from — as a **clickable link**
|
|
9
|
+
you can open straight from your terminal. And it stays quiet in production, so you
|
|
10
|
+
can leave your logs where they are and not worry about them.
|
|
11
11
|
|
|
12
12
|
No dependencies. No config. Import it and you're done.
|
|
13
13
|
|
|
@@ -39,21 +39,17 @@ Auth user logged in
|
|
|
39
39
|
Each line is tagged by level — `[INFO]`, `[WARN]`, or `[ERROR]` — followed by the
|
|
40
40
|
timestamp and the source location, with your arguments on the next line.
|
|
41
41
|
|
|
42
|
-
## Click to
|
|
42
|
+
## Click to open the source
|
|
43
43
|
|
|
44
|
-
That `(server.ts:42)` at the end of every log isn't just text — in
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
That `(server.ts:42)` at the end of every log isn't just text — when you're in a
|
|
45
|
+
terminal, it's a **clickable link** that opens the file the log came from. No more
|
|
46
|
+
hunting for where a message came from, and the line number is right there in the
|
|
47
|
+
label.
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`(server.ts:42)` text —
|
|
51
|
-
|
|
52
|
-
If your terminal supports links but isn't auto-detected, you can force them on:
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
FORCE_HYPERLINK=1 node app.js
|
|
56
|
-
```
|
|
49
|
+
There's nothing to configure. Links show up automatically when output goes to a
|
|
50
|
+
terminal, and when it's piped to a file or another program they quietly drop to
|
|
51
|
+
plain `(server.ts:42)` text — so your log files never get cluttered with escape
|
|
52
|
+
codes.
|
|
57
53
|
|
|
58
54
|
## What about production?
|
|
59
55
|
|
|
@@ -24,7 +24,7 @@ function formatLocation(caller, streamName) {
|
|
|
24
24
|
if (caller.file !== null &&
|
|
25
25
|
caller.line !== null &&
|
|
26
26
|
(0, link_js_1.supportsHyperlinks)(streamName))
|
|
27
|
-
return (0, link_js_1.hyperlink)(caller.label, (0, link_js_1.fileUrl)(caller.file
|
|
27
|
+
return (0, link_js_1.hyperlink)(caller.label, (0, link_js_1.fileUrl)(caller.file));
|
|
28
28
|
return caller.label;
|
|
29
29
|
}
|
|
30
30
|
/**
|
package/dist/cjs/utils/link.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Builds a `file://` URL
|
|
3
|
-
*
|
|
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.
|
|
4
7
|
*/
|
|
5
|
-
export declare function fileUrl(file: string
|
|
8
|
+
export declare function fileUrl(file: string): string;
|
|
6
9
|
/**
|
|
7
10
|
* Wraps `text` in an OSC-8 terminal hyperlink pointing at `url`. Terminals that
|
|
8
|
-
* support OSC-8 render `text` as a clickable link; others
|
|
11
|
+
* support OSC-8 render `text` as a clickable link; others ignore the escape and
|
|
12
|
+
* simply show `text`.
|
|
9
13
|
*/
|
|
10
14
|
export declare function hyperlink(text: string, url: string): string;
|
|
11
15
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* Whether to emit OSC-8 hyperlinks for the given stream. Driven solely by the
|
|
17
|
+
* stream being an interactive terminal (`isTTY`) — no env vars, no config. When
|
|
18
|
+
* output is piped or redirected, links are skipped so escapes never end up in
|
|
19
|
+
* files or logs. Terminals that don't understand OSC-8 just show the plain text.
|
|
16
20
|
*/
|
|
17
21
|
export declare function supportsHyperlinks(streamName: "stdout" | "stderr"): boolean;
|
package/dist/cjs/utils/link.js
CHANGED
|
@@ -11,16 +11,19 @@ exports.hyperlink = hyperlink;
|
|
|
11
11
|
exports.supportsHyperlinks = supportsHyperlinks;
|
|
12
12
|
const node_url_1 = require("node:url");
|
|
13
13
|
/**
|
|
14
|
-
* Builds a `file://` URL
|
|
15
|
-
*
|
|
14
|
+
* Builds a valid `file://` URL for a path so terminals can open it on click.
|
|
15
|
+
* Paths already in `file://` form are used as-is. We intentionally do NOT append
|
|
16
|
+
* `:line` — that isn't a valid URI and breaks file openers (e.g. GNOME/`gio`,
|
|
17
|
+
* which would look for a file literally named `foo.ts:42`). The line number
|
|
18
|
+
* stays visible in the link's display text instead.
|
|
16
19
|
*/
|
|
17
|
-
function fileUrl(file
|
|
18
|
-
|
|
19
|
-
return `${base}:${line}`;
|
|
20
|
+
function fileUrl(file) {
|
|
21
|
+
return file.startsWith("file://") ? file : (0, node_url_1.pathToFileURL)(file).href;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Wraps `text` in an OSC-8 terminal hyperlink pointing at `url`. Terminals that
|
|
23
|
-
* support OSC-8 render `text` as a clickable link; others
|
|
25
|
+
* support OSC-8 render `text` as a clickable link; others ignore the escape and
|
|
26
|
+
* simply show `text`.
|
|
24
27
|
*/
|
|
25
28
|
function hyperlink(text, url) {
|
|
26
29
|
const OSC = "\x1b]8;;";
|
|
@@ -28,36 +31,14 @@ function hyperlink(text, url) {
|
|
|
28
31
|
return `${OSC}${url}${BEL}${text}${OSC}${BEL}`;
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
34
|
+
* Whether to emit OSC-8 hyperlinks for the given stream. Driven solely by the
|
|
35
|
+
* stream being an interactive terminal (`isTTY`) — no env vars, no config. When
|
|
36
|
+
* output is piped or redirected, links are skipped so escapes never end up in
|
|
37
|
+
* files or logs. Terminals that don't understand OSC-8 just show the plain text.
|
|
35
38
|
*/
|
|
36
39
|
function supportsHyperlinks(streamName) {
|
|
37
40
|
if (typeof process === "undefined")
|
|
38
41
|
return false;
|
|
39
|
-
const env = process.env;
|
|
40
|
-
const force = env.FORCE_HYPERLINK;
|
|
41
|
-
if (force !== undefined && force !== "")
|
|
42
|
-
return force !== "0" && force.toLowerCase() !== "false";
|
|
43
42
|
const stream = streamName === "stdout" ? process.stdout : process.stderr;
|
|
44
|
-
|
|
45
|
-
return false;
|
|
46
|
-
if (env.TERM === "dumb")
|
|
47
|
-
return false;
|
|
48
|
-
if (env.CI !== undefined && env.CI !== "")
|
|
49
|
-
return false;
|
|
50
|
-
const program = env.TERM_PROGRAM;
|
|
51
|
-
if (program === "vscode" ||
|
|
52
|
-
program === "iTerm.app" ||
|
|
53
|
-
program === "Hyper" ||
|
|
54
|
-
program === "WezTerm")
|
|
55
|
-
return true;
|
|
56
|
-
if (env.WT_SESSION)
|
|
57
|
-
return true; // Windows Terminal
|
|
58
|
-
if (env.KITTY_WINDOW_ID)
|
|
59
|
-
return true;
|
|
60
|
-
if (env.VTE_VERSION !== undefined && Number(env.VTE_VERSION) >= 5000)
|
|
61
|
-
return true; // GNOME, etc.
|
|
62
|
-
return false;
|
|
43
|
+
return Boolean(stream?.isTTY);
|
|
63
44
|
}
|
package/dist/utils/createLog.js
CHANGED
|
@@ -18,7 +18,7 @@ function formatLocation(caller, streamName) {
|
|
|
18
18
|
if (caller.file !== null &&
|
|
19
19
|
caller.line !== null &&
|
|
20
20
|
supportsHyperlinks(streamName))
|
|
21
|
-
return hyperlink(caller.label, fileUrl(caller.file
|
|
21
|
+
return hyperlink(caller.label, fileUrl(caller.file));
|
|
22
22
|
return caller.label;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLog.js","sourceRoot":"","sources":["../../src/utils/createLog.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,SAA0B,MAAM,gBAAgB,CAAA;AACvD,OAAO,YAAY,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAK3C;;;;;GAKG;AACH,SAAS,cAAc,CACrB,MAAc,EACd,UAA+B;IAE/B,IACE,MAAM,CAAC,IAAI,KAAK,IAAI;QACpB,MAAM,CAAC,IAAI,KAAK,IAAI;QACpB,kBAAkB,CAAC,UAAU,CAAC;QAE9B,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"createLog.js","sourceRoot":"","sources":["../../src/utils/createLog.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,SAA0B,MAAM,gBAAgB,CAAA;AACvD,OAAO,YAAY,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAK3C;;;;;GAKG;AACH,SAAS,cAAc,CACrB,MAAc,EACd,UAA+B;IAE/B,IACE,MAAM,CAAC,IAAI,KAAK,IAAI;QACpB,MAAM,CAAC,IAAI,KAAK,IAAI;QACpB,kBAAkB,CAAC,UAAU,CAAC;QAE9B,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IACtD,OAAO,MAAM,CAAC,KAAK,CAAA;AACrB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,OAAmB,EACnB,GAAW;IAEX,MAAM,UAAU,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;IAC1D,OAAO,CAAC,GAAG,IAAe,EAAQ,EAAE;QAClC,IAAI,CAAC,YAAY,EAAE;YAAE,OAAM;QAC3B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;QAC1B,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;QACnD,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,IAAI,QAAQ,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,CAAC,CAAA;IAC7E,CAAC,CAAA;AACH,CAAC"}
|
package/dist/utils/link.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Builds a `file://` URL
|
|
3
|
-
*
|
|
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.
|
|
4
7
|
*/
|
|
5
|
-
export declare function fileUrl(file: string
|
|
8
|
+
export declare function fileUrl(file: string): string;
|
|
6
9
|
/**
|
|
7
10
|
* Wraps `text` in an OSC-8 terminal hyperlink pointing at `url`. Terminals that
|
|
8
|
-
* support OSC-8 render `text` as a clickable link; others
|
|
11
|
+
* support OSC-8 render `text` as a clickable link; others ignore the escape and
|
|
12
|
+
* simply show `text`.
|
|
9
13
|
*/
|
|
10
14
|
export declare function hyperlink(text: string, url: string): string;
|
|
11
15
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* Whether to emit OSC-8 hyperlinks for the given stream. Driven solely by the
|
|
17
|
+
* stream being an interactive terminal (`isTTY`) — no env vars, no config. When
|
|
18
|
+
* output is piped or redirected, links are skipped so escapes never end up in
|
|
19
|
+
* files or logs. Terminals that don't understand OSC-8 just show the plain text.
|
|
16
20
|
*/
|
|
17
21
|
export declare function supportsHyperlinks(streamName: "stdout" | "stderr"): boolean;
|
|
18
22
|
//# sourceMappingURL=link.d.ts.map
|
package/dist/utils/link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/utils/link.ts"],"names":[],"mappings":"AASA
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/utils/link.ts"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAI3E"}
|
package/dist/utils/link.js
CHANGED
|
@@ -6,16 +6,19 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
8
|
/**
|
|
9
|
-
* Builds a `file://` URL
|
|
10
|
-
*
|
|
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.
|
|
11
14
|
*/
|
|
12
|
-
export function fileUrl(file
|
|
13
|
-
|
|
14
|
-
return `${base}:${line}`;
|
|
15
|
+
export function fileUrl(file) {
|
|
16
|
+
return file.startsWith("file://") ? file : pathToFileURL(file).href;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Wraps `text` in an OSC-8 terminal hyperlink pointing at `url`. Terminals that
|
|
18
|
-
* support OSC-8 render `text` as a clickable link; others
|
|
20
|
+
* support OSC-8 render `text` as a clickable link; others ignore the escape and
|
|
21
|
+
* simply show `text`.
|
|
19
22
|
*/
|
|
20
23
|
export function hyperlink(text, url) {
|
|
21
24
|
const OSC = "\x1b]8;;";
|
|
@@ -23,37 +26,15 @@ export function hyperlink(text, url) {
|
|
|
23
26
|
return `${OSC}${url}${BEL}${text}${OSC}${BEL}`;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
29
|
+
* Whether to emit OSC-8 hyperlinks for the given stream. Driven solely by the
|
|
30
|
+
* stream being an interactive terminal (`isTTY`) — no env vars, no config. When
|
|
31
|
+
* output is piped or redirected, links are skipped so escapes never end up in
|
|
32
|
+
* files or logs. Terminals that don't understand OSC-8 just show the plain text.
|
|
30
33
|
*/
|
|
31
34
|
export function supportsHyperlinks(streamName) {
|
|
32
35
|
if (typeof process === "undefined")
|
|
33
36
|
return false;
|
|
34
|
-
const env = process.env;
|
|
35
|
-
const force = env.FORCE_HYPERLINK;
|
|
36
|
-
if (force !== undefined && force !== "")
|
|
37
|
-
return force !== "0" && force.toLowerCase() !== "false";
|
|
38
37
|
const stream = streamName === "stdout" ? process.stdout : process.stderr;
|
|
39
|
-
|
|
40
|
-
return false;
|
|
41
|
-
if (env.TERM === "dumb")
|
|
42
|
-
return false;
|
|
43
|
-
if (env.CI !== undefined && env.CI !== "")
|
|
44
|
-
return false;
|
|
45
|
-
const program = env.TERM_PROGRAM;
|
|
46
|
-
if (program === "vscode" ||
|
|
47
|
-
program === "iTerm.app" ||
|
|
48
|
-
program === "Hyper" ||
|
|
49
|
-
program === "WezTerm")
|
|
50
|
-
return true;
|
|
51
|
-
if (env.WT_SESSION)
|
|
52
|
-
return true; // Windows Terminal
|
|
53
|
-
if (env.KITTY_WINDOW_ID)
|
|
54
|
-
return true;
|
|
55
|
-
if (env.VTE_VERSION !== undefined && Number(env.VTE_VERSION) >= 5000)
|
|
56
|
-
return true; // GNOME, etc.
|
|
57
|
-
return false;
|
|
38
|
+
return Boolean(stream?.isTTY);
|
|
58
39
|
}
|
|
59
40
|
//# sourceMappingURL=link.js.map
|
package/dist/utils/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/utils/link.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/utils/link.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAA;AACrE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,GAAW;IACjD,MAAM,GAAG,GAAG,UAAU,CAAA;IACtB,MAAM,GAAG,GAAG,MAAM,CAAA;IAClB,OAAO,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,EAAE,CAAA;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAA+B;IAChE,IAAI,OAAO,OAAO,KAAK,WAAW;QAAE,OAAO,KAAK,CAAA;IAChD,MAAM,MAAM,GAAG,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAA;IACxE,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meadown/logger",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "A tiny, zero-dependency logger for Node.js and TypeScript that tags each line, timestamps it, shows the source file and line, and goes quiet in production.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logger",
|