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 +113 -96
- package/dist/index.d.mts +53 -10
- package/dist/index.d.ts +53 -10
- package/dist/index.js +4 -2
- package/dist/index.mjs +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,150 +1,167 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
>
|
|
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
|
-
|
|
13
|
-
[](https://github.com/user/devink/blob/main/LICENSE)
|
|
14
|
-
[](https://www.npmjs.com/package/devink)
|
|
15
|
-
[](https://bundlephobia.com/result?p=devink)
|
|
9
|
+
# devink
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
> A fast, lightweight, and professional **TypeScript logger** with zero dependencies. Keep your terminal cool, soothing, and strictly structured.
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
[](https://npmjs.org/package/devink)
|
|
14
|
+
[](https://opensource.org/licenses/MIT)
|
|
20
15
|
|
|
21
|
-
|
|
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
|
-
|
|
18
|
+
---
|
|
24
19
|
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
import { createLogger } from 'devink';
|
|
42
|
-
|
|
43
|
-
const logger = createLogger({ timestamps: true });
|
|
39
|
+
```bash
|
|
40
|
+
yarn add devink
|
|
41
|
+
```
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
47
|
+
---
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
## 💻 Usage
|
|
54
50
|
|
|
55
|
-
|
|
51
|
+
### Basic CLI Logger
|
|
56
52
|
|
|
57
|
-
|
|
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
|
-
|
|
55
|
+
```ts
|
|
56
|
+
import { createLogger } from 'devink';
|
|
62
57
|
|
|
63
58
|
const logger = createLogger({
|
|
64
|
-
|
|
65
|
-
|
|
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.
|
|
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
|
-
###
|
|
69
|
+
### Structured JSON Logging
|
|
70
|
+
|
|
71
|
+
Perfect for production environments where log aggregation is crucial:
|
|
78
72
|
|
|
79
|
-
|
|
73
|
+
```ts
|
|
74
|
+
import { createLogger } from 'devink';
|
|
80
75
|
|
|
81
|
-
```typescript
|
|
82
76
|
const logger = createLogger({
|
|
83
|
-
|
|
77
|
+
mode: 'json',
|
|
78
|
+
level: 'trace',
|
|
84
79
|
});
|
|
85
80
|
|
|
86
|
-
logger.info('
|
|
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
|
-
###
|
|
90
|
-
|
|
91
|
-
Deep-merge your theme overrides seamlessly.
|
|
85
|
+
### Beautiful Boxed Output
|
|
92
86
|
|
|
93
|
-
|
|
94
|
-
import { createLogger, ansi } from 'devink';
|
|
87
|
+
Make important startup messages or critical alerts pop in the console:
|
|
95
88
|
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
108
|
-
|
|
92
|
+
logger.box(
|
|
93
|
+
'System Ready',
|
|
94
|
+
'All microservices have booted successfully.\nListening on http://localhost:8080',
|
|
95
|
+
);
|
|
109
96
|
```
|
|
110
97
|
|
|
111
|
-
|
|
98
|
+
---
|
|
112
99
|
|
|
113
|
-
|
|
100
|
+
## ⚙️ Configuration
|
|
114
101
|
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
121
|
+
```ts
|
|
122
|
+
import { createLogger, classicTheme } from 'devink';
|
|
123
|
+
|
|
124
|
+
const logger = createLogger({
|
|
125
|
+
theme: classicTheme,
|
|
126
|
+
});
|
|
123
127
|
```
|
|
124
128
|
|
|
125
|
-
|
|
129
|
+
### Custom Transports
|
|
126
130
|
|
|
127
|
-
|
|
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
|
-
|
|
133
|
+
```ts
|
|
134
|
+
import { createLogger, Transport, TransportContext } from 'devink';
|
|
135
|
+
import fs from 'node:fs';
|
|
130
136
|
|
|
131
|
-
|
|
137
|
+
class FileTransport implements Transport {
|
|
138
|
+
write(ctx: TransportContext) {
|
|
139
|
+
fs.appendFileSync('app.log', ctx.raw + '\n');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
132
142
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
const logger = createLogger({
|
|
144
|
+
transports: [new FileTransport()], // Now writes to app.log instead of console
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
139
149
|
|
|
140
|
-
##
|
|
150
|
+
## 🎨 ANSI Capabilities
|
|
141
151
|
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
37
|
-
private
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
37
|
-
private
|
|
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
|
|
2
|
-
`+this.highlightJson(
|
|
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
|
|
2
|
-
`+this.highlightJson(
|
|
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};
|