@adriangalilea/utils 2.30.0 → 2.32.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.
@@ -1,108 +1,113 @@
1
1
  /**
2
- * A Next.js-style logger for TypeScript applications
3
- * Provides colored output with Unicode symbols for different log levels
2
+ * Terminal-first logger with two renderings and one automatic decision.
4
3
  *
5
- * Known limitations:
6
- * - createLogger() is just a prefix wrapper, not a real scoped instance.
7
- * No per-scope level control (can't silence 'bor' but keep 'bdns' verbose).
8
- * - No withTag/child pattern — consumer can't control library log levels.
4
+ * Two knobs, never confusing: format = how lines render, time = whether
5
+ * lines carry time. Each defaults sensibly and independently.
9
6
  *
10
- * Candidate replacement: consola (unjs). Same DX goals, solves all the above:
11
- * - consola.level = N at runtime
12
- * - consola.withTag('bdns') for scoped loggers that inherit global level
13
- * - Pretty dev output, JSON in prod, browser support, 0 deps
14
- * - https://github.com/unjs/consola
7
+ * Format — LOG_FORMAT=human|record, or setLogFormat(). Default by TTY
8
+ * detection on the sink: a TTY gets human (symbols, color, a line meant
9
+ * for eyes), anything else gets record (level words, plain text, a line
10
+ * meant for a file read later). Detection happens on the stream actually
11
+ * written to (stderr), never a sibling stream.
15
12
  *
16
- * TODO: test consola in dokploy instance before migrating.
13
+ * Time — LOG_TIME=1|0, or setLogTime(). Default: on in Node record mode,
14
+ * off everywhere else (human eyes don't need stamps; browser and Worker
15
+ * consoles stamp lines themselves). Record time opens the line with UTC
16
+ * RFC3339; human time prefixes a dim local HH:MM:SS (a human knows
17
+ * today's date).
18
+ *
19
+ * The record line with time on, identical across go-utils and py-utils by
20
+ * design:
21
+ * 2026-08-07T12:34:56Z WARN [scope] message
22
+ * UTC RFC3339 seconds precision · level word padded to 5 · scope brackets
23
+ * only when scoped · no color, no symbols. Grep WARN, not ⚠.
24
+ *
25
+ * Sinks
26
+ * Node/Bun/Deno: every level writes to stderr through console.error, so
27
+ * stdout stays clean for data and cli/live's console routing keeps log
28
+ * lines above an active region.
29
+ * Browser: level-mapped console methods (debug/info/warn/error), human.
30
+ * Workers: level-mapped console methods, record.
31
+ *
32
+ * Levels vs verbs
33
+ * Levels filter: silent < error < warn < info < debug < trace. An unknown
34
+ * LOG_LEVEL is a misconfiguration and throws Panic.
35
+ * Verbs express outcome and are renderings, never levels:
36
+ * error ⨯ fail ⨯ (error) · warn ⚠ (warn) · info · success ✓ · wait ○ ·
37
+ * ready ▶ · step • (info) · debug ◦ (debug) · trace » (trace).
38
+ * In record mode a verb renders as its level word.
39
+ *
40
+ * Scopes
41
+ * log.scope('api') returns a child whose lines carry [api]; scopes nest
42
+ * and join: log.scope('api').scope('auth') → [api auth]. A scoped logger
43
+ * resolves its threshold from {SCOPE}_LOG_LEVEL (upper-cased, joined and
44
+ * sanitized to A-Z0-9_: API_AUTH_LOG_LEVEL, then API_LOG_LEVEL), falling
45
+ * back to setLogLevel(), then LOG_LEVEL, then info — read live, so one
46
+ * subsystem can be silenced or opened up without touching code.
47
+ *
48
+ * Config is env plus three runtime setters — setLogLevel(), setLogFormat(),
49
+ * setLogTime(). No handlers, no formatters, no init. NO_COLOR /
50
+ * FORCE_COLOR override color within human mode. Unknown values of any
51
+ * knob throw Panic. All internal memory is bounded.
52
+ *
53
+ * Siblings: go-utils and py-utils implement the same doctrine in their own
54
+ * idioms; the record line format is identical by design.
17
55
  */
18
- export declare const bold: (str: string) => string;
19
- export declare const dim: (str: string) => string;
20
- export declare const red: (str: string) => string;
21
- export declare const green: (str: string) => string;
22
- export declare const yellow: (str: string) => string;
23
- export declare const blue: (str: string) => string;
24
- export declare const magenta: (str: string) => string;
25
- export declare const cyan: (str: string) => string;
26
- export declare const white: (str: string) => string;
27
- export declare const gray: (str: string) => string;
28
- export declare const purple: (str: string) => string;
29
- export declare const bgRed: (str: string) => string;
30
- export declare const bgGreen: (str: string) => string;
31
- export declare const bgYellow: (str: string) => string;
32
- export declare const bgBlue: (str: string) => string;
33
- export declare const bgMagenta: (str: string) => string;
34
- export declare const bgCyan: (str: string) => string;
35
- export declare const bgWhite: (str: string) => string;
36
- type LogLevelName = "error" | "warn" | "info" | "trace";
37
- /** Set the global log level at runtime. Overrides LOG_LEVEL env var. */
38
- export declare function setLogLevel(level: LogLevelName): void;
39
- export declare function bootstrap(...messages: string[]): void;
40
- export declare function wait(...messages: unknown[]): void;
41
- export declare function error(...messages: unknown[]): void;
42
- export declare function warn(...messages: unknown[]): void;
43
- export declare function ready(...messages: unknown[]): void;
44
- export declare function info(...messages: unknown[]): void;
45
- export declare function success(...messages: unknown[]): void;
46
- export declare function event(...messages: unknown[]): void;
47
- export declare function trace(...messages: unknown[]): void;
48
- export declare function warnOnce(...messages: unknown[]): void;
49
- export declare function time(label: string): void;
50
- export declare function timeEnd(label: string): void;
51
- export declare function createLogger(prefix: string): {
52
- wait: (...messages: unknown[]) => void;
53
- error: (...messages: unknown[]) => void;
54
- warn: (...messages: unknown[]) => void;
55
- ready: (...messages: unknown[]) => void;
56
- info: (...messages: unknown[]) => void;
57
- success: (...messages: unknown[]) => void;
58
- event: (...messages: unknown[]) => void;
59
- trace: (...messages: unknown[]) => void;
60
- warnOnce: (...messages: unknown[]) => void;
61
- time: (label: string) => void;
62
- timeEnd: (label: string) => void;
56
+ export type LogFormat = "human" | "record";
57
+ /** Force human or record rendering at runtime. Wins over LOG_FORMAT and auto-detection. */
58
+ export declare function setLogFormat(format: LogFormat): void;
59
+ /** Force time prefixes on or off at runtime. Wins over LOG_TIME and the defaults. */
60
+ export declare function setLogTime(on: boolean): void;
61
+ declare const LEVELS: {
62
+ readonly silent: 0;
63
+ readonly error: 1;
64
+ readonly warn: 2;
65
+ readonly info: 3;
66
+ readonly debug: 4;
67
+ readonly trace: 5;
63
68
  };
64
- declare const log: {
65
- wait: typeof wait;
66
- error: typeof error;
67
- warn: typeof warn;
68
- ready: typeof ready;
69
- info: typeof info;
70
- success: typeof success;
71
- event: typeof event;
72
- trace: typeof trace;
73
- warnOnce: typeof warnOnce;
74
- time: typeof time;
75
- timeEnd: typeof timeEnd;
76
- bootstrap: typeof bootstrap;
77
- createLogger: typeof createLogger;
69
+ export type LogLevel = keyof typeof LEVELS;
70
+ /** Set the global log level at runtime. Wins over LOG_LEVEL; per-scope env vars still win over this. */
71
+ export declare function setLogLevel(level: LogLevel): void;
72
+ export interface Logger {
73
+ error(...messages: unknown[]): void;
74
+ fail(...messages: unknown[]): void;
75
+ warn(...messages: unknown[]): void;
76
+ /** warn() that fires once per distinct message for the process lifetime. */
77
+ warnOnce(...messages: unknown[]): void;
78
+ info(...messages: unknown[]): void;
79
+ success(...messages: unknown[]): void;
80
+ wait(...messages: unknown[]): void;
81
+ ready(...messages: unknown[]): void;
82
+ /** Indented sub-step bullet under a wait/ready line. */
83
+ step(...messages: unknown[]): void;
84
+ debug(...messages: unknown[]): void;
85
+ trace(...messages: unknown[]): void;
86
+ /** Start a duration measurement; timeEnd() reports it at trace level. */
87
+ time(label: string): void;
88
+ timeEnd(label: string): void;
89
+ /** Child logger: lines carry [name], level reads {NAME}_LOG_LEVEL first. */
90
+ scope(name: string): Logger;
91
+ }
92
+ export declare const error: (...messages: unknown[]) => void;
93
+ export declare const fail: (...messages: unknown[]) => void;
94
+ export declare const warn: (...messages: unknown[]) => void;
95
+ export declare const warnOnce: (...messages: unknown[]) => void;
96
+ export declare const info: (...messages: unknown[]) => void;
97
+ export declare const success: (...messages: unknown[]) => void;
98
+ export declare const wait: (...messages: unknown[]) => void;
99
+ export declare const ready: (...messages: unknown[]) => void;
100
+ export declare const step: (...messages: unknown[]) => void;
101
+ export declare const debug: (...messages: unknown[]) => void;
102
+ export declare const trace: (...messages: unknown[]) => void;
103
+ export declare const time: (label: string) => void;
104
+ export declare const timeEnd: (label: string) => void;
105
+ export declare const scope: (name: string) => Logger;
106
+ /** The root logger plus its runtime knobs, for namespace-style consumers. */
107
+ export declare const log: Logger & {
78
108
  setLogLevel: typeof setLogLevel;
79
- colors: {
80
- bold: (str: string) => string;
81
- dim: (str: string) => string;
82
- red: (str: string) => string;
83
- green: (str: string) => string;
84
- yellow: (str: string) => string;
85
- blue: (str: string) => string;
86
- magenta: (str: string) => string;
87
- cyan: (str: string) => string;
88
- white: (str: string) => string;
89
- gray: (str: string) => string;
90
- purple: (str: string) => string;
91
- bgRed: (str: string) => string;
92
- bgGreen: (str: string) => string;
93
- bgYellow: (str: string) => string;
94
- bgBlue: (str: string) => string;
95
- bgMagenta: (str: string) => string;
96
- bgCyan: (str: string) => string;
97
- bgWhite: (str: string) => string;
98
- };
109
+ setLogFormat: typeof setLogFormat;
110
+ setLogTime: typeof setLogTime;
99
111
  };
100
- export { log };
101
- export declare function logAppStartup(options: {
102
- name: string;
103
- version: string;
104
- port: number;
105
- host?: string;
106
- environment?: string;
107
- }): void;
112
+ export {};
108
113
  //# sourceMappingURL=log.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/universal/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAsDH,eAAO,MAAM,IAAI,QALgB,MAAM,WAKC,CAAC;AACzC,eAAO,MAAM,GAAG,QANiB,MAAM,WAMD,CAAC;AACvC,eAAO,MAAM,GAAG,QAPiB,MAAM,WAOD,CAAC;AACvC,eAAO,MAAM,KAAK,QARe,MAAM,WAQG,CAAC;AAC3C,eAAO,MAAM,MAAM,QATc,MAAM,WASK,CAAC;AAC7C,eAAO,MAAM,IAAI,QAVgB,MAAM,WAUC,CAAC;AACzC,eAAO,MAAM,OAAO,QAXa,MAAM,WAWO,CAAC;AAC/C,eAAO,MAAM,IAAI,QAZgB,MAAM,WAYC,CAAC;AACzC,eAAO,MAAM,KAAK,QAbe,MAAM,WAaG,CAAC;AAC3C,eAAO,MAAM,IAAI,QAdgB,MAAM,WAcC,CAAC;AACzC,eAAO,MAAM,MAAM,QAfc,MAAM,WAeK,CAAC;AAG7C,eAAO,MAAM,KAAK,QAlBe,MAAM,WAkBG,CAAC;AAC3C,eAAO,MAAM,OAAO,Q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