devink 1.0.2 → 1.0.4

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
@@ -1,150 +1,167 @@
1
- <h1 align="center">
2
- <br>
3
- <br>
4
- <img width="320" src="https://raw.githubusercontent.com/harrymate22/devink/main/media/logo.png" alt="devink">
5
- <br>
6
- <br>
7
- <br>
8
- </h1>
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/harrymate22/devink/main/media/logo.png" alt="devink logo" width="200" />
3
+ </p>
9
4
 
10
- > Fast, lightweight, professional terminal logger. Zero dependencies.
5
+ <p align="center">
6
+ <img src="https://raw.githubusercontent.com/harrymate22/devink/main/media/demo.png" alt="devink demo" width="600" />
7
+ </p>
11
8
 
12
- [![npm version](https://badgen.net/npm/v/devink)](https://npmjs.com/package/devink)
13
- [![license](https://badgen.net/github/license/user/devink)](https://github.com/user/devink/blob/main/LICENSE)
14
- [![types](https://badgen.net/npm/types/devink)](https://www.npmjs.com/package/devink)
15
- [![dependencies](https://badgen.net/bundlephobia/dependency-count/devink)](https://bundlephobia.com/result?p=devink)
9
+ # devink
16
10
 
17
- ![](https://raw.githubusercontent.com/harrymate22/devink/main/media/demo.png)
11
+ > A fast, lightweight, and professional **TypeScript logger** with zero dependencies. Keep your terminal cool, soothing, and strictly structured.
18
12
 
19
- **Devink** is a production-grade, zero-dependency Node.js logging library featuring custom transports, graceful JSON serialization, a deep-merging theme system, and automatic ANSI color detection.
13
+ [![npm version](https://img.shields.io/npm/v/devink.svg)](https://npmjs.org/package/devink)
14
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
20
15
 
21
- Designed specifically built for high-performance CLI tools, servers, and modern development environments. 🚀
16
+ `devink` is a zero-dependency **Node.js logger** designed for developers who need high performance, beautiful **CLI output**, and structured **JSON logging**. With full **ANSI color support**, dynamic terminal capability detection, and customizable transports, it's the perfect production-ready logger for modern TS/JS environments.
22
17
 
23
- ## Highlights
18
+ ---
24
19
 
25
- - **Zero Dependencies**: Pure, self-contained raw ANSI escape engine (`NO_COLOR`, `FORCE_COLOR`, `TERM`, `isTTY` support).
26
- - **Graceful Error Handling**: Bulletproof object stringification gracefully handles Circular JSON crashes.
27
- - **Custom Transports**: Redirect logs to files, external services, or any custom stream easily.
28
- - **Deep Theme System**: Merge your own styles tightly without overriding whole config structures.
29
- - **Lightweight & Fast**: Extremely fast execution.
30
- - **Modern Module Setup**: Full TypeScript compatibility, exporting ESM (`import`) and CommonJS (`require`).
20
+ ## 🚀 Features
31
21
 
32
- ## Installation
22
+ - **Zero Dependencies**: Lightweight and ultra-fast. No bloated `node_modules`.
23
+ - **Full ANSI & 256/RGB Color Support**: Beautiful, soothing UI themes for the terminal. No harsh contrast.
24
+ - **Structured JSON Logging**: Instantly switch to JSON mode for seamless integration with Datadog, ELK, AWS CloudWatch, and parsing tools.
25
+ - **Log Levels & Priority Filtering**: Granular control via `trace`, `debug`, `info`, `warn`, `error`, and `fatal`.
26
+ - **Custom Transports**: Route logs to files, external APIs, or custom formatting engines.
27
+ - **Terminal Capability Detection**: Automatically detects `process.stdout.isTTY`, `FORCE_COLOR`, `NO_COLOR`, and `CI` environments.
28
+ - **Boxed Output**: Help crucial information stand out with Unicode-boxed messages.
29
+ - **TypeScript native**: Built with TS, exporting standard typings out-of-the-box.
30
+
31
+ ---
32
+
33
+ ## 📦 Installation
33
34
 
34
35
  ```bash
35
36
  npm install devink
36
37
  ```
37
38
 
38
- ## Quick Start
39
-
40
- ```typescript
41
- import { createLogger } from 'devink';
42
-
43
- const logger = createLogger({ timestamps: true });
39
+ ```bash
40
+ yarn add devink
41
+ ```
44
42
 
45
- logger.success('Database connection established');
46
- logger.info('Listening on port 3000');
47
- logger.warn('Memory usage above 80%');
48
- logger.error('Request failed', { status: 500 });
43
+ ```bash
44
+ pnpm add devink
49
45
  ```
50
46
 
51
- ## Advanced Usage
47
+ ---
52
48
 
53
- ### Custom Transports
49
+ ## 💻 Usage
54
50
 
55
- Devink allows you to intercept output and route it to your own methods. No more hardcoded `console.log`.
51
+ ### Basic CLI Logger
56
52
 
57
- ```typescript
58
- import { createLogger } from 'devink';
59
- import fs from 'fs';
53
+ Create a beautiful terminal logger with timestamps and the modern theme out of the box:
60
54
 
61
- const fileStream = fs.createWriteStream('./app.log', { flags: 'a' });
55
+ ```ts
56
+ import { createLogger } from 'devink';
62
57
 
63
58
  const logger = createLogger({
64
- transport: {
65
- // Override log execution logic
66
- success: (...args) => fileStream.write(`[PASS] ${args.join(' ')}\n`),
67
- error: (...args) => {
68
- console.error(...args); // Keep console logging
69
- fileStream.write(`[CRITICAL] ${args.join(' ')}\n`);
70
- },
71
- },
59
+ timestamps: true,
60
+ level: 'info',
72
61
  });
73
62
 
74
- logger.success('User registered!'); // Goes straight to app.log
63
+ logger.info('Server started on port 3000');
64
+ logger.success('Database connected successfully');
65
+ logger.warn('Rate limit approaching');
66
+ logger.error(new Error('Connection timeout'));
75
67
  ```
76
68
 
77
- ### Color Control
69
+ ### Structured JSON Logging
70
+
71
+ Perfect for production environments where log aggregation is crucial:
78
72
 
79
- For environments where strict text formatting is required, Devink lets you disable ANSI explicitly.
73
+ ```ts
74
+ import { createLogger } from 'devink';
80
75
 
81
- ```typescript
82
76
  const logger = createLogger({
83
- colors: false, // Instantly strips all ANSI escape codes
77
+ mode: 'json',
78
+ level: 'trace',
84
79
  });
85
80
 
86
- logger.info('This will definitely be plain text.');
81
+ logger.info('Processing payment', { userId: 123, amount: 49.99 });
82
+ // Output: {"level":"info","time":"2023-10-25T14:30:00.000Z","message":["Processing payment",{"userId":123,"amount":49.99}]}
87
83
  ```
88
84
 
89
- ### Deep Theming
90
-
91
- Deep-merge your theme overrides seamlessly.
85
+ ### Beautiful Boxed Output
92
86
 
93
- ```typescript
94
- import { createLogger, ansi } from 'devink';
87
+ Make important startup messages or critical alerts pop in the console:
95
88
 
96
- const customLogger = createLogger({
97
- theme: {
98
- // Colors text differently
99
- warn: (msg) => ansi.magenta(ansi.bold(msg)),
100
- prefix: {
101
- // Overrides ONLY the success icon, preserving defaults for others
102
- success: ansi.green('🚀 SUCCESS'),
103
- },
104
- },
105
- });
89
+ ```ts
90
+ const logger = createLogger();
106
91
 
107
- customLogger.success('Payload deployed!');
108
- customLogger.warn('Custom colored warning.');
92
+ logger.box(
93
+ 'System Ready',
94
+ 'All microservices have booted successfully.\nListening on http://localhost:8080',
95
+ );
109
96
  ```
110
97
 
111
- ### Safe Serialization
98
+ ---
112
99
 
113
- No more logging crashes from deep object introspection or circular references.
100
+ ## ⚙️ Configuration
114
101
 
115
- ```typescript
116
- const logger = createLogger();
102
+ The `createLogger` function accepts an optional `LoggerOptions` object:
103
+
104
+ | Property | Type | Default | Description |
105
+ | ------------ | ------------------ | -------------------- | -------------------------------------------------------------------------------------- |
106
+ | `level` | `LogLevelName` | `'trace'` | Minimum log level to output (`trace` < `debug` < `info` < `warn` < `error` < `fatal`). |
107
+ | `mode` | `'text' \| 'json'` | `'text'` | Output mode. Text formats for the console, JSON formats for log aggregators. |
108
+ | `colors` | `boolean` | `true` | Whether to use ANSI colors. Automatically disabled if terminal doesn't support it. |
109
+ | `timestamps` | `boolean` | `false` | Prepend a timestamp to text outputs (`[HH:MM:SS]`). |
110
+ | `theme` | `Partial<Theme>` | `modernTheme` | Customize the prefix, success, error, warn, and info styling. |
111
+ | `transports` | `Transport[]` | `[ConsoleTransport]` | Target output locations hooks (e.g., standard out, file streams). |
112
+
113
+ ### Theme Presets
114
+
115
+ `devink` ships with several UI/UX optimized presets, designed for accessibility and developer comfort:
117
116
 
118
- const circularObj: any = {};
119
- circularObj.self = circularObj;
117
+ - `modernTheme` (Default): Soft, cool hex colors (`#10b981`, `#f43f5e`, `#38bdf8`) with dim text to prevent eye strain.
118
+ - `classicTheme`: Standard ANSI colors (Red, Green, Yellow, Cyan).
119
+ - `minimalTheme`: Prefix icons only, without extra text like "success" or "error".
120
120
 
121
- // Doesn't throw! Gently recovers to '[Unserializable Object]'
122
- logger.error('Error snapshot:', circularObj);
121
+ ```ts
122
+ import { createLogger, classicTheme } from 'devink';
123
+
124
+ const logger = createLogger({
125
+ theme: classicTheme,
126
+ });
123
127
  ```
124
128
 
125
- ## API Reference
129
+ ### Custom Transports
126
130
 
127
- ### `createLogger(options?: LoggerOptions)`
131
+ You can easily route logs anywhere by providing objects that implement the `Transport` interface (which requires a `write(ctx: TransportContext)` method).
128
132
 
129
- Creates a new `Logger` instance.
133
+ ```ts
134
+ import { createLogger, Transport, TransportContext } from 'devink';
135
+ import fs from 'node:fs';
130
136
 
131
- #### `LoggerOptions`
137
+ class FileTransport implements Transport {
138
+ write(ctx: TransportContext) {
139
+ fs.appendFileSync('app.log', ctx.raw + '\n');
140
+ }
141
+ }
132
142
 
133
- | Option | Type | Default | Description |
134
- | :----------- | :------------------- | :------------------ | :------------------------------------------------------- |
135
- | `timestamps` | `boolean` | `false` | Prepends `[HH:MM:SS]` timestamp to every message. |
136
- | `colors` | `boolean` | `true` | When `false`, all output will be stripped of ANSI codes. |
137
- | `theme` | `Partial<Theme>` | `{}` | Deep partial override of color structures and prefixes. |
138
- | `transport` | `Partial<Transport>` | `console.*` methods | Custom output handler for standard log layers. |
143
+ const logger = createLogger({
144
+ transports: [new FileTransport()], // Now writes to app.log instead of console
145
+ });
146
+ ```
147
+
148
+ ---
139
149
 
140
- ## Runtime Compatibility
150
+ ## 🎨 ANSI Capabilities
141
151
 
142
- - Node.js `^18.0.0` or newer
143
- - Fully compatible with ESM & CommonJS
152
+ If you want to build your own CLI tools, `devink` exports its high-performance, zero-dependency ANSI utilities:
153
+
154
+ ```ts
155
+ import { ansi } from 'devink';
156
+
157
+ console.log(ansi.rgb(255, 100, 50, 'True RGB text!'));
158
+ console.log(ansi.hex('#34d399', 'Hex coded text!'));
159
+ console.log(ansi.color256(128, '256 color terminal support!'));
160
+ console.log(ansi.dim('Low contrast subtitle.'));
161
+ ```
144
162
 
145
- Built with ❤️ by **[Harry Mate](https://github.com/harrymate22)**.
146
- 🌟 If you find this library helpful, consider dropping a **Star** on GitHub and **[following me (@harrymate22)](https://github.com/harrymate22)** for more open-source tools!
163
+ ---
147
164
 
148
- ## License
165
+ ## 📄 License
149
166
 
150
167
  MIT © [harrymate22](https://github.com/harrymate22)
package/dist/index.d.mts CHANGED
@@ -10,35 +10,68 @@ interface Theme {
10
10
  info: string;
11
11
  };
12
12
  }
13
+ declare const modernTheme: Theme;
14
+ declare const minimalTheme: Theme;
15
+ declare const classicTheme: Theme;
13
16
  declare const defaultTheme: Theme;
14
17
 
18
+ declare enum LogLevel {
19
+ trace = 10,
20
+ debug = 20,
21
+ info = 30,
22
+ success = 35,
23
+ warn = 40,
24
+ error = 50,
25
+ fatal = 60,
26
+ none = 100
27
+ }
28
+ type LogLevelName = keyof typeof LogLevel;
29
+ interface TransportContext {
30
+ level: LogLevelName;
31
+ levelValue: number;
32
+ message: unknown[];
33
+ formatted: string;
34
+ raw: string;
35
+ timestamp: string;
36
+ }
15
37
  interface Transport {
16
- success: (...args: unknown[]) => void;
17
- error: (...args: unknown[]) => void;
18
- warn: (...args: unknown[]) => void;
19
- info: (...args: unknown[]) => void;
38
+ write(ctx: TransportContext): void;
20
39
  }
21
40
  interface LoggerOptions {
22
41
  theme?: Partial<Theme>;
23
42
  timestamps?: boolean;
24
43
  colors?: boolean;
25
- transport?: Partial<Transport>;
44
+ level?: LogLevelName;
45
+ mode?: 'text' | 'json';
46
+ transports?: Transport[];
47
+ }
48
+ declare class ConsoleTransport implements Transport {
49
+ write(ctx: TransportContext): void;
26
50
  }
27
51
  declare class Logger {
28
52
  private theme;
29
53
  private timestamps;
30
54
  private colors;
31
- private transport;
55
+ private level;
56
+ private mode;
57
+ private transports;
58
+ private timeCache;
32
59
  constructor(options?: LoggerOptions);
60
+ private shouldLog;
33
61
  private getTimestamp;
62
+ private safeStringify;
34
63
  private highlightJson;
35
64
  private formatMessage;
36
- private stripAnsi;
37
- private output;
65
+ private emit;
66
+ private dispatch;
38
67
  success(...message: unknown[]): void;
39
68
  error(...message: unknown[]): void;
40
69
  warn(...message: unknown[]): void;
41
70
  info(...message: unknown[]): void;
71
+ trace(...message: unknown[]): void;
72
+ debug(...message: unknown[]): void;
73
+ fatal(...message: unknown[]): void;
74
+ box(title: string, message: string): void;
42
75
  }
43
76
  declare const createLogger: (options?: LoggerOptions) => Logger;
44
77
 
@@ -67,21 +100,29 @@ declare const dim: (text: string) => string;
67
100
  declare const italic: (text: string) => string;
68
101
  declare const underline: (text: string) => string;
69
102
  declare const inverse: (text: string) => string;
103
+ declare const rgb: (r: number, g: number, b: number, text: string) => string;
104
+ declare const bgRgb: (r: number, g: number, b: number, text: string) => string;
70
105
  declare const hex: (hexCode: string, text: string) => string;
71
106
  declare const bgHex: (hexCode: string, text: string) => string;
107
+ declare const color256: (code: number, text: string) => string;
108
+ declare const bgColor256: (code: number, text: string) => string;
109
+ declare const stripAnsi: (text: string) => string;
72
110
 
73
111
  declare const ansi_bgBlack: typeof bgBlack;
74
112
  declare const ansi_bgBlue: typeof bgBlue;
113
+ declare const ansi_bgColor256: typeof bgColor256;
75
114
  declare const ansi_bgCyan: typeof bgCyan;
76
115
  declare const ansi_bgGreen: typeof bgGreen;
77
116
  declare const ansi_bgHex: typeof bgHex;
78
117
  declare const ansi_bgMagenta: typeof bgMagenta;
79
118
  declare const ansi_bgRed: typeof bgRed;
119
+ declare const ansi_bgRgb: typeof bgRgb;
80
120
  declare const ansi_bgWhite: typeof bgWhite;
81
121
  declare const ansi_bgYellow: typeof bgYellow;
82
122
  declare const ansi_black: typeof black;
83
123
  declare const ansi_blue: typeof blue;
84
124
  declare const ansi_bold: typeof bold;
125
+ declare const ansi_color256: typeof color256;
85
126
  declare const ansi_cyan: typeof cyan;
86
127
  declare const ansi_dim: typeof dim;
87
128
  declare const ansi_format: typeof format;
@@ -94,11 +135,13 @@ declare const ansi_italic: typeof italic;
94
135
  declare const ansi_magenta: typeof magenta;
95
136
  declare const ansi_red: typeof red;
96
137
  declare const ansi_reset: typeof reset;
138
+ declare const ansi_rgb: typeof rgb;
139
+ declare const ansi_stripAnsi: typeof stripAnsi;
97
140
  declare const ansi_underline: typeof underline;
98
141
  declare const ansi_white: typeof white;
99
142
  declare const ansi_yellow: typeof yellow;
100
143
  declare namespace ansi {
101
- export { ansi_bgBlack as bgBlack, ansi_bgBlue as bgBlue, ansi_bgCyan as bgCyan, ansi_bgGreen as bgGreen, ansi_bgHex as bgHex, ansi_bgMagenta as bgMagenta, ansi_bgRed as bgRed, ansi_bgWhite as bgWhite, ansi_bgYellow as bgYellow, ansi_black as black, ansi_blue as blue, ansi_bold as bold, ansi_cyan as cyan, ansi_dim as dim, ansi_format as format, ansi_gray as gray, ansi_green as green, ansi_hex as hex, ansi_inverse as inverse, ansi_isColorSupported as isColorSupported, ansi_italic as italic, ansi_magenta as magenta, ansi_red as red, ansi_reset as reset, ansi_underline as underline, ansi_white as white, ansi_yellow as yellow };
144
+ export { ansi_bgBlack as bgBlack, ansi_bgBlue as bgBlue, ansi_bgColor256 as bgColor256, ansi_bgCyan as bgCyan, ansi_bgGreen as bgGreen, ansi_bgHex as bgHex, ansi_bgMagenta as bgMagenta, ansi_bgRed as bgRed, ansi_bgRgb as bgRgb, ansi_bgWhite as bgWhite, ansi_bgYellow as bgYellow, ansi_black as black, ansi_blue as blue, ansi_bold as bold, ansi_color256 as color256, ansi_cyan as cyan, ansi_dim as dim, ansi_format as format, ansi_gray as gray, ansi_green as green, ansi_hex as hex, ansi_inverse as inverse, ansi_isColorSupported as isColorSupported, ansi_italic as italic, ansi_magenta as magenta, ansi_red as red, ansi_reset as reset, ansi_rgb as rgb, ansi_stripAnsi as stripAnsi, ansi_underline as underline, ansi_white as white, ansi_yellow as yellow };
102
145
  }
103
146
 
104
- export { Logger, type LoggerOptions, type Theme, ansi, createLogger, defaultTheme };
147
+ export { ConsoleTransport, LogLevel, type LogLevelName, Logger, type LoggerOptions, type Theme, type Transport, type TransportContext, ansi, classicTheme, createLogger, defaultTheme, minimalTheme, modernTheme };
package/dist/index.d.ts CHANGED
@@ -10,35 +10,68 @@ interface Theme {
10
10
  info: string;
11
11
  };
12
12
  }
13
+ declare const modernTheme: Theme;
14
+ declare const minimalTheme: Theme;
15
+ declare const classicTheme: Theme;
13
16
  declare const defaultTheme: Theme;
14
17
 
18
+ declare enum LogLevel {
19
+ trace = 10,
20
+ debug = 20,
21
+ info = 30,
22
+ success = 35,
23
+ warn = 40,
24
+ error = 50,
25
+ fatal = 60,
26
+ none = 100
27
+ }
28
+ type LogLevelName = keyof typeof LogLevel;
29
+ interface TransportContext {
30
+ level: LogLevelName;
31
+ levelValue: number;
32
+ message: unknown[];
33
+ formatted: string;
34
+ raw: string;
35
+ timestamp: string;
36
+ }
15
37
  interface Transport {
16
- success: (...args: unknown[]) => void;
17
- error: (...args: unknown[]) => void;
18
- warn: (...args: unknown[]) => void;
19
- info: (...args: unknown[]) => void;
38
+ write(ctx: TransportContext): void;
20
39
  }
21
40
  interface LoggerOptions {
22
41
  theme?: Partial<Theme>;
23
42
  timestamps?: boolean;
24
43
  colors?: boolean;
25
- transport?: Partial<Transport>;
44
+ level?: LogLevelName;
45
+ mode?: 'text' | 'json';
46
+ transports?: Transport[];
47
+ }
48
+ declare class ConsoleTransport implements Transport {
49
+ write(ctx: TransportContext): void;
26
50
  }
27
51
  declare class Logger {
28
52
  private theme;
29
53
  private timestamps;
30
54
  private colors;
31
- private transport;
55
+ private level;
56
+ private mode;
57
+ private transports;
58
+ private timeCache;
32
59
  constructor(options?: LoggerOptions);
60
+ private shouldLog;
33
61
  private getTimestamp;
62
+ private safeStringify;
34
63
  private highlightJson;
35
64
  private formatMessage;
36
- private stripAnsi;
37
- private output;
65
+ private emit;
66
+ private dispatch;
38
67
  success(...message: unknown[]): void;
39
68
  error(...message: unknown[]): void;
40
69
  warn(...message: unknown[]): void;
41
70
  info(...message: unknown[]): void;
71
+ trace(...message: unknown[]): void;
72
+ debug(...message: unknown[]): void;
73
+ fatal(...message: unknown[]): void;
74
+ box(title: string, message: string): void;
42
75
  }
43
76
  declare const createLogger: (options?: LoggerOptions) => Logger;
44
77
 
@@ -67,21 +100,29 @@ declare const dim: (text: string) => string;
67
100
  declare const italic: (text: string) => string;
68
101
  declare const underline: (text: string) => string;
69
102
  declare const inverse: (text: string) => string;
103
+ declare const rgb: (r: number, g: number, b: number, text: string) => string;
104
+ declare const bgRgb: (r: number, g: number, b: number, text: string) => string;
70
105
  declare const hex: (hexCode: string, text: string) => string;
71
106
  declare const bgHex: (hexCode: string, text: string) => string;
107
+ declare const color256: (code: number, text: string) => string;
108
+ declare const bgColor256: (code: number, text: string) => string;
109
+ declare const stripAnsi: (text: string) => string;
72
110
 
73
111
  declare const ansi_bgBlack: typeof bgBlack;
74
112
  declare const ansi_bgBlue: typeof bgBlue;
113
+ declare const ansi_bgColor256: typeof bgColor256;
75
114
  declare const ansi_bgCyan: typeof bgCyan;
76
115
  declare const ansi_bgGreen: typeof bgGreen;
77
116
  declare const ansi_bgHex: typeof bgHex;
78
117
  declare const ansi_bgMagenta: typeof bgMagenta;
79
118
  declare const ansi_bgRed: typeof bgRed;
119
+ declare const ansi_bgRgb: typeof bgRgb;
80
120
  declare const ansi_bgWhite: typeof bgWhite;
81
121
  declare const ansi_bgYellow: typeof bgYellow;
82
122
  declare const ansi_black: typeof black;
83
123
  declare const ansi_blue: typeof blue;
84
124
  declare const ansi_bold: typeof bold;
125
+ declare const ansi_color256: typeof color256;
85
126
  declare const ansi_cyan: typeof cyan;
86
127
  declare const ansi_dim: typeof dim;
87
128
  declare const ansi_format: typeof format;
@@ -94,11 +135,13 @@ declare const ansi_italic: typeof italic;
94
135
  declare const ansi_magenta: typeof magenta;
95
136
  declare const ansi_red: typeof red;
96
137
  declare const ansi_reset: typeof reset;
138
+ declare const ansi_rgb: typeof rgb;
139
+ declare const ansi_stripAnsi: typeof stripAnsi;
97
140
  declare const ansi_underline: typeof underline;
98
141
  declare const ansi_white: typeof white;
99
142
  declare const ansi_yellow: typeof yellow;
100
143
  declare namespace ansi {
101
- export { ansi_bgBlack as bgBlack, ansi_bgBlue as bgBlue, ansi_bgCyan as bgCyan, ansi_bgGreen as bgGreen, ansi_bgHex as bgHex, ansi_bgMagenta as bgMagenta, ansi_bgRed as bgRed, ansi_bgWhite as bgWhite, ansi_bgYellow as bgYellow, ansi_black as black, ansi_blue as blue, ansi_bold as bold, ansi_cyan as cyan, ansi_dim as dim, ansi_format as format, ansi_gray as gray, ansi_green as green, ansi_hex as hex, ansi_inverse as inverse, ansi_isColorSupported as isColorSupported, ansi_italic as italic, ansi_magenta as magenta, ansi_red as red, ansi_reset as reset, ansi_underline as underline, ansi_white as white, ansi_yellow as yellow };
144
+ export { ansi_bgBlack as bgBlack, ansi_bgBlue as bgBlue, ansi_bgColor256 as bgColor256, ansi_bgCyan as bgCyan, ansi_bgGreen as bgGreen, ansi_bgHex as bgHex, ansi_bgMagenta as bgMagenta, ansi_bgRed as bgRed, ansi_bgRgb as bgRgb, ansi_bgWhite as bgWhite, ansi_bgYellow as bgYellow, ansi_black as black, ansi_blue as blue, ansi_bold as bold, ansi_color256 as color256, ansi_cyan as cyan, ansi_dim as dim, ansi_format as format, ansi_gray as gray, ansi_green as green, ansi_hex as hex, ansi_inverse as inverse, ansi_isColorSupported as isColorSupported, ansi_italic as italic, ansi_magenta as magenta, ansi_red as red, ansi_reset as reset, ansi_rgb as rgb, ansi_stripAnsi as stripAnsi, ansi_underline as underline, ansi_white as white, ansi_yellow as yellow };
102
145
  }
103
146
 
104
- export { Logger, type LoggerOptions, type Theme, ansi, createLogger, defaultTheme };
147
+ export { ConsoleTransport, LogLevel, type LogLevelName, Logger, type LoggerOptions, type Theme, type Transport, type TransportContext, ansi, classicTheme, createLogger, defaultTheme, minimalTheme, modernTheme };
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
- 'use strict';var h=Object.defineProperty;var x=(t,s)=>{for(var r in s)h(t,r,{get:s[r],enumerable:true});};var l={};x(l,{bgBlack:()=>I,bgBlue:()=>M,bgCyan:()=>E,bgGreen:()=>R,bgHex:()=>g,bgMagenta:()=>S,bgRed:()=>L,bgWhite:()=>N,bgYellow:()=>C,black:()=>d,blue:()=>v,bold:()=>o,cyan:()=>k,dim:()=>j,format:()=>e,gray:()=>m,green:()=>T,hex:()=>n,inverse:()=>z,isColorSupported:()=>p,italic:()=>A,magenta:()=>O,red:()=>w,reset:()=>b,underline:()=>J,white:()=>y,yellow:()=>$});var p=!process.env.NO_COLOR&&(process.env.FORCE_COLOR||process.stdout?.isTTY||process.env.TERM==="xterm-256color"),e=(t,s)=>p?`\x1B[${t}m${s}\x1B[0m`:s,b=t=>e(0,t),d=t=>e(30,t),w=t=>e(31,t),T=t=>e(32,t),$=t=>e(33,t),v=t=>e(34,t),O=t=>e(35,t),k=t=>e(36,t),y=t=>e(37,t),m=t=>e(90,t),I=t=>e(40,t),L=t=>e(41,t),R=t=>e(42,t),C=t=>e(43,t),M=t=>e(44,t),S=t=>e(45,t),E=t=>e(46,t),N=t=>e(47,t),o=t=>e(1,t),j=t=>e(2,t),A=t=>e(3,t),J=t=>e(4,t),z=t=>e(7,t),n=(t,s)=>{if(!p)return s;let r=t.replace(/^#/,"");if(r.length!==6)return s;let i=parseInt(r.substring(0,2),16),u=parseInt(r.substring(2,4),16),f=parseInt(r.substring(4,6),16);return `\x1B[38;2;${i};${u};${f}m${s}\x1B[0m`},g=(t,s)=>{if(!p)return s;let r=t.replace(/^#/,"");if(r.length!==6)return s;let i=parseInt(r.substring(0,2),16),u=parseInt(r.substring(2,4),16),f=parseInt(r.substring(4,6),16);return `\x1B[48;2;${i};${u};${f}m${s}\x1B[0m`};var a={success:t=>t,error:t=>t,warn:t=>t,info:t=>t,prefix:{success:n("#10b981","\u2714")+" "+g("#064e3b",n("#34d399",o(" SUCCESS "))),error:n("#ef4444","\u2716")+" "+g("#7f1d1d",n("#f87171",o(" ERROR "))),warn:n("#f59e0b","\u26A0")+" "+g("#78350f",n("#fbbf24",o(" WARNING "))),info:n("#0ea5e9","\u2139")+" "+g("#0c4a6e",n("#38bdf8",o(" INFO ")))}};var B={success:console.log,error:console.error,warn:console.warn,info:console.info},c=class{theme;timestamps;colors;transport;constructor(s={}){this.theme={...a,...s.theme,prefix:{...a.prefix,...s.theme?.prefix}},this.timestamps=s.timestamps??false,this.colors=s.colors??true,this.transport={...B,...s.transport};}getTimestamp(){if(!this.timestamps)return "";let r=new Date().toISOString().split("T")[1]?.split(".")[0];return m(`[${r}] `)}highlightJson(s){return this.colors?s.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,r=>/^"/.test(r)?/:$/.test(r)?n("#9ca3af",r.slice(0,-1))+":":n("#34d399",r):/true|false/.test(r)?n("#c084fc",r):/null/.test(r)?n("#f87171",r):n("#fbbf24",r)):s}formatMessage(s){return s.map(r=>{if(typeof r=="string")return r;try{let i=JSON.stringify(r,null,2);return `
2
- `+this.highlightJson(i)}catch{return "[Unserializable Object]"}}).join(" ")}stripAnsi(s){return s.replace(/\x1b\[[0-9;]*m/g,"")}output(s,r){let i=this.colors?r:this.stripAnsi(r);this.transport[s](i);}success(...s){let r=this.formatMessage(s);this.output("success",`${this.getTimestamp()}${this.theme.prefix.success} ${this.theme.success(r)}`);}error(...s){let r=this.formatMessage(s);this.output("error",`${this.getTimestamp()}${this.theme.prefix.error} ${this.theme.error(r)}`);}warn(...s){let r=this.formatMessage(s);this.output("warn",`${this.getTimestamp()}${this.theme.prefix.warn} ${this.theme.warn(r)}`);}info(...s){let r=this.formatMessage(s);this.output("info",`${this.getTimestamp()}${this.theme.prefix.info} ${this.theme.info(r)}`);}},F=t=>new c(t);exports.Logger=c;exports.ansi=l;exports.createLogger=F;exports.defaultTheme=a;
1
+ 'use strict';var M=Object.defineProperty;var A=(t,r)=>{for(var e in r)M(t,e,{get:r[e],enumerable:true});};var I={};A(I,{bgBlack:()=>F,bgBlue:()=>Y,bgColor256:()=>tt,bgCyan:()=>G,bgGreen:()=>U,bgHex:()=>Q,bgMagenta:()=>D,bgRed:()=>L,bgRgb:()=>R,bgWhite:()=>H,bgYellow:()=>W,black:()=>B,blue:()=>J,bold:()=>P,color256:()=>X,cyan:()=>v,dim:()=>h,format:()=>i,gray:()=>b,green:()=>w,hex:()=>s,inverse:()=>K,isColorSupported:()=>p,italic:()=>Z,magenta:()=>_,red:()=>d,reset:()=>V,rgb:()=>S,stripAnsi:()=>u,underline:()=>q,white:()=>z,yellow:()=>T});var x=process.env,p=!x.NO_COLOR&&(x.FORCE_COLOR||process.stdout&&process.stdout.isTTY||x.TERM==="xterm-256color"||x.CI==="true"),i=(t,r)=>p?`\x1B[${t}m${r}\x1B[0m`:r,V=t=>i(0,t),B=t=>i(30,t),d=t=>i(31,t),w=t=>i(32,t),T=t=>i(33,t),J=t=>i(34,t),_=t=>i(35,t),v=t=>i(36,t),z=t=>i(37,t),b=t=>i(90,t),F=t=>i(40,t),L=t=>i(41,t),U=t=>i(42,t),W=t=>i(43,t),Y=t=>i(44,t),D=t=>i(45,t),G=t=>i(46,t),H=t=>i(47,t),P=t=>i(1,t),h=t=>i(2,t),Z=t=>i(3,t),q=t=>i(4,t),K=t=>i(7,t),S=(t,r,e,o)=>p?`\x1B[38;2;${t};${r};${e}m${o}\x1B[0m`:o,R=(t,r,e,o)=>p?`\x1B[48;2;${t};${r};${e}m${o}\x1B[0m`:o,s=(t,r)=>{if(!p)return r;let e=t.replace(/^#/,"");return e.length!==6?r:S(parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16),r)},Q=(t,r)=>{if(!p)return r;let e=t.replace(/^#/,"");return e.length!==6?r:R(parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16),r)},X=(t,r)=>p?`\x1B[38;5;${t}m${r}\x1B[0m`:r,tt=(t,r)=>p?`\x1B[48;5;${t}m${r}\x1B[0m`:r,u=t=>t.replace(/\x1b\[[0-9;]*m/g,"");var N={success:t=>s("#10b981",t),error:t=>s("#f43f5e",t),warn:t=>s("#f59e0b",t),info:t=>s("#38bdf8",t),prefix:{success:s("#10b981","\u2714")+" "+s("#34d399",h("success")),error:s("#f43f5e","\u2716")+" "+s("#fb7185",h("error")),warn:s("#f59e0b","\u26A0")+" "+s("#fbbf24",h("warn")),info:s("#38bdf8","\u2139")+" "+s("#7dd3fc",h("info"))}},rt={success:t=>t,error:t=>t,warn:t=>t,info:t=>t,prefix:{success:s("#10b981","\u2714"),error:s("#f43f5e","\u2716"),warn:s("#f59e0b","\u26A0"),info:s("#38bdf8","\u2139")}},et={success:t=>w(t),error:t=>d(t),warn:t=>T(t),info:t=>v(t),prefix:{success:w("SUCCESS"),error:d("ERROR"),warn:T("WARN"),info:v("INFO")}},$=N;var y=(n=>(n[n.trace=10]="trace",n[n.debug=20]="debug",n[n.info=30]="info",n[n.success=35]="success",n[n.warn=40]="warn",n[n.error=50]="error",n[n.fatal=60]="fatal",n[n.none=100]="none",n))(y||{}),C=class{write(r){(r.levelValue>=50?console.error:console.log)(r.formatted);}},k=class{theme;timestamps;colors;level;mode;transports;timeCache={time:"",str:""};constructor(r={}){this.theme={...$,...r.theme,prefix:{...$.prefix,...r.theme?.prefix}},this.timestamps=r.timestamps??false,this.colors=r.colors??!!p,this.level=y[r.level??"trace"],this.mode=r.mode??"text",this.transports=r.transports??[new C];}shouldLog(r){return r>=this.level}getTimestamp(){if(!this.timestamps)return {iso:"",formatted:""};let e=new Date().toISOString(),o=e.split("T")[1]?.split(".")[0]||"";if(this.timeCache.time===o)return {iso:e,formatted:this.timeCache.str};let g=b(`[${o}] `);return this.timeCache={time:o,str:g},{iso:e,formatted:g}}safeStringify(r,e){let o=new Set;return JSON.stringify(r,(g,a)=>{if(typeof a=="object"&&a!==null){if(o.has(a))return "[Circular]";o.add(a);}return a},e)}highlightJson(r){return !this.colors||r.length>5e3?r:r.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,e=>/^"/.test(e)?/:$/.test(e)?s("#9ca3af",e.slice(0,-1))+":":s("#34d399",e):/true|false/.test(e)?s("#c084fc",e):/null/.test(e)?s("#f87171",e):s("#fbbf24",e))}formatMessage(r){return r.map(e=>{if(typeof e=="string")return e;if(e instanceof Error)return e.stack||e.message;try{return `
2
+ `+this.highlightJson(this.safeStringify(e,2))}catch{return "[Unserializable]"}}).join(" ")}emit(r,e,o,g){let a=y[r];if(!this.shouldLog(a))return;let f=this.getTimestamp(),m,n;if(this.mode==="json"){let c={level:r,time:f.iso,message:g.length===1?g[0]:g};m=n=this.safeStringify(c);}else {let c=this.formatMessage(g);m=`${f.formatted}${e} ${o(c)}`,n=u(m),this.colors||(m=n);}this.dispatch(r,a,g,m,n,f.iso);}dispatch(r,e,o,g,a,f){let m={level:r,levelValue:e,message:o,formatted:g,raw:a,timestamp:f};for(let n=0;n<this.transports.length;n++)this.transports[n]?.write(m);}success(...r){this.emit("success",this.theme.prefix.success,this.theme.success,r);}error(...r){this.emit("error",this.theme.prefix.error,this.theme.error,r);}warn(...r){this.emit("warn",this.theme.prefix.warn,this.theme.warn,r);}info(...r){this.emit("info",this.theme.prefix.info,this.theme.info,r);}trace(...r){this.emit("trace",b("\u{1F50D}"),b,r);}debug(...r){this.emit("debug",s("#94a3b8","\u{1F41B}"),e=>s("#94a3b8",e),r);}fatal(...r){this.emit("fatal",s("#be123c","\u{1F480}"),e=>s("#be123c",e),r);}box(r,e){let o=30;if(!this.shouldLog(o))return;let g=e.split(`
3
+ `),a=Math.max(r.length,...g.map(l=>u(l).length))+4,f=`\u250C\u2500 ${r} ${"\u2500".repeat(a-r.length-3)}\u2510`,m=`\u2514${"\u2500".repeat(a)}\u2518`,n=g.map(l=>{let E=a-u(l).length-2;return `\u2502 ${l}${" ".repeat(Math.max(0,E))} \u2502`}),c=[f,...n,m].join(`
4
+ `),O=u(c);if(this.mode==="json"){let l=this.getTimestamp();c=O=this.safeStringify({level:"info",time:l.iso,title:r,message:e}),this.dispatch("info",o,[e],c,O,l.iso);return}this.colors&&(c=s("#38bdf8",c));let j=this.getTimestamp();this.dispatch("info",o,[e],c,O,j.iso);}},st=t=>new k(t);exports.ConsoleTransport=C;exports.LogLevel=y;exports.Logger=k;exports.ansi=I;exports.classicTheme=et;exports.createLogger=st;exports.defaultTheme=$;exports.minimalTheme=rt;exports.modernTheme=N;
package/dist/index.mjs CHANGED
@@ -1,2 +1,4 @@
1
- var h=Object.defineProperty;var x=(t,s)=>{for(var r in s)h(t,r,{get:s[r],enumerable:true});};var l={};x(l,{bgBlack:()=>I,bgBlue:()=>M,bgCyan:()=>E,bgGreen:()=>R,bgHex:()=>g,bgMagenta:()=>S,bgRed:()=>L,bgWhite:()=>N,bgYellow:()=>C,black:()=>d,blue:()=>v,bold:()=>o,cyan:()=>k,dim:()=>j,format:()=>e,gray:()=>m,green:()=>T,hex:()=>n,inverse:()=>z,isColorSupported:()=>p,italic:()=>A,magenta:()=>O,red:()=>w,reset:()=>b,underline:()=>J,white:()=>y,yellow:()=>$});var p=!process.env.NO_COLOR&&(process.env.FORCE_COLOR||process.stdout?.isTTY||process.env.TERM==="xterm-256color"),e=(t,s)=>p?`\x1B[${t}m${s}\x1B[0m`:s,b=t=>e(0,t),d=t=>e(30,t),w=t=>e(31,t),T=t=>e(32,t),$=t=>e(33,t),v=t=>e(34,t),O=t=>e(35,t),k=t=>e(36,t),y=t=>e(37,t),m=t=>e(90,t),I=t=>e(40,t),L=t=>e(41,t),R=t=>e(42,t),C=t=>e(43,t),M=t=>e(44,t),S=t=>e(45,t),E=t=>e(46,t),N=t=>e(47,t),o=t=>e(1,t),j=t=>e(2,t),A=t=>e(3,t),J=t=>e(4,t),z=t=>e(7,t),n=(t,s)=>{if(!p)return s;let r=t.replace(/^#/,"");if(r.length!==6)return s;let i=parseInt(r.substring(0,2),16),u=parseInt(r.substring(2,4),16),f=parseInt(r.substring(4,6),16);return `\x1B[38;2;${i};${u};${f}m${s}\x1B[0m`},g=(t,s)=>{if(!p)return s;let r=t.replace(/^#/,"");if(r.length!==6)return s;let i=parseInt(r.substring(0,2),16),u=parseInt(r.substring(2,4),16),f=parseInt(r.substring(4,6),16);return `\x1B[48;2;${i};${u};${f}m${s}\x1B[0m`};var a={success:t=>t,error:t=>t,warn:t=>t,info:t=>t,prefix:{success:n("#10b981","\u2714")+" "+g("#064e3b",n("#34d399",o(" SUCCESS "))),error:n("#ef4444","\u2716")+" "+g("#7f1d1d",n("#f87171",o(" ERROR "))),warn:n("#f59e0b","\u26A0")+" "+g("#78350f",n("#fbbf24",o(" WARNING "))),info:n("#0ea5e9","\u2139")+" "+g("#0c4a6e",n("#38bdf8",o(" INFO ")))}};var B={success:console.log,error:console.error,warn:console.warn,info:console.info},c=class{theme;timestamps;colors;transport;constructor(s={}){this.theme={...a,...s.theme,prefix:{...a.prefix,...s.theme?.prefix}},this.timestamps=s.timestamps??false,this.colors=s.colors??true,this.transport={...B,...s.transport};}getTimestamp(){if(!this.timestamps)return "";let r=new Date().toISOString().split("T")[1]?.split(".")[0];return m(`[${r}] `)}highlightJson(s){return this.colors?s.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,r=>/^"/.test(r)?/:$/.test(r)?n("#9ca3af",r.slice(0,-1))+":":n("#34d399",r):/true|false/.test(r)?n("#c084fc",r):/null/.test(r)?n("#f87171",r):n("#fbbf24",r)):s}formatMessage(s){return s.map(r=>{if(typeof r=="string")return r;try{let i=JSON.stringify(r,null,2);return `
2
- `+this.highlightJson(i)}catch{return "[Unserializable Object]"}}).join(" ")}stripAnsi(s){return s.replace(/\x1b\[[0-9;]*m/g,"")}output(s,r){let i=this.colors?r:this.stripAnsi(r);this.transport[s](i);}success(...s){let r=this.formatMessage(s);this.output("success",`${this.getTimestamp()}${this.theme.prefix.success} ${this.theme.success(r)}`);}error(...s){let r=this.formatMessage(s);this.output("error",`${this.getTimestamp()}${this.theme.prefix.error} ${this.theme.error(r)}`);}warn(...s){let r=this.formatMessage(s);this.output("warn",`${this.getTimestamp()}${this.theme.prefix.warn} ${this.theme.warn(r)}`);}info(...s){let r=this.formatMessage(s);this.output("info",`${this.getTimestamp()}${this.theme.prefix.info} ${this.theme.info(r)}`);}},F=t=>new c(t);export{c as Logger,l as ansi,F as createLogger,a as defaultTheme};
1
+ var M=Object.defineProperty;var A=(t,r)=>{for(var e in r)M(t,e,{get:r[e],enumerable:true});};var I={};A(I,{bgBlack:()=>F,bgBlue:()=>Y,bgColor256:()=>tt,bgCyan:()=>G,bgGreen:()=>U,bgHex:()=>Q,bgMagenta:()=>D,bgRed:()=>L,bgRgb:()=>R,bgWhite:()=>H,bgYellow:()=>W,black:()=>B,blue:()=>J,bold:()=>P,color256:()=>X,cyan:()=>v,dim:()=>h,format:()=>i,gray:()=>b,green:()=>w,hex:()=>s,inverse:()=>K,isColorSupported:()=>p,italic:()=>Z,magenta:()=>_,red:()=>d,reset:()=>V,rgb:()=>S,stripAnsi:()=>u,underline:()=>q,white:()=>z,yellow:()=>T});var x=process.env,p=!x.NO_COLOR&&(x.FORCE_COLOR||process.stdout&&process.stdout.isTTY||x.TERM==="xterm-256color"||x.CI==="true"),i=(t,r)=>p?`\x1B[${t}m${r}\x1B[0m`:r,V=t=>i(0,t),B=t=>i(30,t),d=t=>i(31,t),w=t=>i(32,t),T=t=>i(33,t),J=t=>i(34,t),_=t=>i(35,t),v=t=>i(36,t),z=t=>i(37,t),b=t=>i(90,t),F=t=>i(40,t),L=t=>i(41,t),U=t=>i(42,t),W=t=>i(43,t),Y=t=>i(44,t),D=t=>i(45,t),G=t=>i(46,t),H=t=>i(47,t),P=t=>i(1,t),h=t=>i(2,t),Z=t=>i(3,t),q=t=>i(4,t),K=t=>i(7,t),S=(t,r,e,o)=>p?`\x1B[38;2;${t};${r};${e}m${o}\x1B[0m`:o,R=(t,r,e,o)=>p?`\x1B[48;2;${t};${r};${e}m${o}\x1B[0m`:o,s=(t,r)=>{if(!p)return r;let e=t.replace(/^#/,"");return e.length!==6?r:S(parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16),r)},Q=(t,r)=>{if(!p)return r;let e=t.replace(/^#/,"");return e.length!==6?r:R(parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16),r)},X=(t,r)=>p?`\x1B[38;5;${t}m${r}\x1B[0m`:r,tt=(t,r)=>p?`\x1B[48;5;${t}m${r}\x1B[0m`:r,u=t=>t.replace(/\x1b\[[0-9;]*m/g,"");var N={success:t=>s("#10b981",t),error:t=>s("#f43f5e",t),warn:t=>s("#f59e0b",t),info:t=>s("#38bdf8",t),prefix:{success:s("#10b981","\u2714")+" "+s("#34d399",h("success")),error:s("#f43f5e","\u2716")+" "+s("#fb7185",h("error")),warn:s("#f59e0b","\u26A0")+" "+s("#fbbf24",h("warn")),info:s("#38bdf8","\u2139")+" "+s("#7dd3fc",h("info"))}},rt={success:t=>t,error:t=>t,warn:t=>t,info:t=>t,prefix:{success:s("#10b981","\u2714"),error:s("#f43f5e","\u2716"),warn:s("#f59e0b","\u26A0"),info:s("#38bdf8","\u2139")}},et={success:t=>w(t),error:t=>d(t),warn:t=>T(t),info:t=>v(t),prefix:{success:w("SUCCESS"),error:d("ERROR"),warn:T("WARN"),info:v("INFO")}},$=N;var y=(n=>(n[n.trace=10]="trace",n[n.debug=20]="debug",n[n.info=30]="info",n[n.success=35]="success",n[n.warn=40]="warn",n[n.error=50]="error",n[n.fatal=60]="fatal",n[n.none=100]="none",n))(y||{}),C=class{write(r){(r.levelValue>=50?console.error:console.log)(r.formatted);}},k=class{theme;timestamps;colors;level;mode;transports;timeCache={time:"",str:""};constructor(r={}){this.theme={...$,...r.theme,prefix:{...$.prefix,...r.theme?.prefix}},this.timestamps=r.timestamps??false,this.colors=r.colors??!!p,this.level=y[r.level??"trace"],this.mode=r.mode??"text",this.transports=r.transports??[new C];}shouldLog(r){return r>=this.level}getTimestamp(){if(!this.timestamps)return {iso:"",formatted:""};let e=new Date().toISOString(),o=e.split("T")[1]?.split(".")[0]||"";if(this.timeCache.time===o)return {iso:e,formatted:this.timeCache.str};let g=b(`[${o}] `);return this.timeCache={time:o,str:g},{iso:e,formatted:g}}safeStringify(r,e){let o=new Set;return JSON.stringify(r,(g,a)=>{if(typeof a=="object"&&a!==null){if(o.has(a))return "[Circular]";o.add(a);}return a},e)}highlightJson(r){return !this.colors||r.length>5e3?r:r.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,e=>/^"/.test(e)?/:$/.test(e)?s("#9ca3af",e.slice(0,-1))+":":s("#34d399",e):/true|false/.test(e)?s("#c084fc",e):/null/.test(e)?s("#f87171",e):s("#fbbf24",e))}formatMessage(r){return r.map(e=>{if(typeof e=="string")return e;if(e instanceof Error)return e.stack||e.message;try{return `
2
+ `+this.highlightJson(this.safeStringify(e,2))}catch{return "[Unserializable]"}}).join(" ")}emit(r,e,o,g){let a=y[r];if(!this.shouldLog(a))return;let f=this.getTimestamp(),m,n;if(this.mode==="json"){let c={level:r,time:f.iso,message:g.length===1?g[0]:g};m=n=this.safeStringify(c);}else {let c=this.formatMessage(g);m=`${f.formatted}${e} ${o(c)}`,n=u(m),this.colors||(m=n);}this.dispatch(r,a,g,m,n,f.iso);}dispatch(r,e,o,g,a,f){let m={level:r,levelValue:e,message:o,formatted:g,raw:a,timestamp:f};for(let n=0;n<this.transports.length;n++)this.transports[n]?.write(m);}success(...r){this.emit("success",this.theme.prefix.success,this.theme.success,r);}error(...r){this.emit("error",this.theme.prefix.error,this.theme.error,r);}warn(...r){this.emit("warn",this.theme.prefix.warn,this.theme.warn,r);}info(...r){this.emit("info",this.theme.prefix.info,this.theme.info,r);}trace(...r){this.emit("trace",b("\u{1F50D}"),b,r);}debug(...r){this.emit("debug",s("#94a3b8","\u{1F41B}"),e=>s("#94a3b8",e),r);}fatal(...r){this.emit("fatal",s("#be123c","\u{1F480}"),e=>s("#be123c",e),r);}box(r,e){let o=30;if(!this.shouldLog(o))return;let g=e.split(`
3
+ `),a=Math.max(r.length,...g.map(l=>u(l).length))+4,f=`\u250C\u2500 ${r} ${"\u2500".repeat(a-r.length-3)}\u2510`,m=`\u2514${"\u2500".repeat(a)}\u2518`,n=g.map(l=>{let E=a-u(l).length-2;return `\u2502 ${l}${" ".repeat(Math.max(0,E))} \u2502`}),c=[f,...n,m].join(`
4
+ `),O=u(c);if(this.mode==="json"){let l=this.getTimestamp();c=O=this.safeStringify({level:"info",time:l.iso,title:r,message:e}),this.dispatch("info",o,[e],c,O,l.iso);return}this.colors&&(c=s("#38bdf8",c));let j=this.getTimestamp();this.dispatch("info",o,[e],c,O,j.iso);}},st=t=>new k(t);export{C as ConsoleTransport,y as LogLevel,k as Logger,I as ansi,et as classicTheme,st as createLogger,$ as defaultTheme,rt as minimalTheme,N as modernTheme};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devink",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Fast, lightweight, professional logger built with TypeScript. No dependencies.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",