@reliverse/relinka 2.2.9 → 2.3.2

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.
Files changed (4) hide show
  1. package/README.md +261 -260
  2. package/dist/mod.d.ts +1 -11
  3. package/dist/mod.js +18 -6
  4. package/package.json +11 -10
package/README.md CHANGED
@@ -1,260 +1,261 @@
1
- # @reliverse/relinka
2
-
3
- A modern, lightweight logging library for TypeScript/JavaScript with both synchronous and asynchronous logging capabilities. Perfect for CLI tools, build systems, and concurrent applications.
4
-
5
- ## Features
6
-
7
- - 🚀 **Dual Mode**: Synchronous (`logger`) and asynchronous (`relinka`) logging
8
- - 🎨 **Colored Output**: Beautiful, color-coded log levels using [@reliverse/relico](https://github.com/reliverse/relico)
9
- - 📦 **Zero Dependencies**: Only depends on `@reliverse/relico` for colors
10
- - 🔒 **Thread-Safe**: Async logger uses write queuing to prevent interleaving
11
- - 🎯 **Type-Safe**: Full TypeScript support with proper type inference
12
- - 📝 **Multiple Log Levels**: `log`, `error`, `fatal`, `warn`, `info`, `success`, `debug`, `box`, `raw`
13
- - 🎭 **Callable Interface**: Use as a function or with method calls
14
- - ⚡ **Non-Blocking**: Async logger queues writes but returns immediately
15
-
16
- ## Installation
17
-
18
- ```bash
19
- bun add @reliverse/relinka
20
- # or
21
- npm install @reliverse/relinka
22
- # or
23
- pnpm add @reliverse/relinka
24
- ```
25
-
26
- ## Quick Start
27
-
28
- ```typescript
29
- import { logger, relinka } from "@reliverse/relinka";
30
-
31
- // Synchronous logging (blocks until write completes)
32
- logger.info("Application started");
33
- logger.success("Build completed successfully");
34
- logger.error("Failed to load configuration");
35
-
36
- // Asynchronous logging (queues writes, returns immediately)
37
- await relinka.info("Processing files...");
38
- await relinka.success("All files processed");
39
- await relinka.error("File processing failed");
40
- ```
41
-
42
- ## When to Use Sync vs Async
43
-
44
- ### Use `logger` (Synchronous) when:
45
- - ✅ Sequential logging (like CLI tools with ordered output)
46
- - ✅ Small, frequent console writes
47
- - ✅ Error reporting that needs to maintain order
48
- - ✅ When you need guaranteed write completion before continuing
49
- - ✅ CLI tools where output order is critical
50
-
51
- ### Use `relinka` (Asynchronous) when:
52
- - Logging from multiple concurrent async operations
53
- - ✅ High-frequency logging where you don't want to block
54
- - ✅ Large log outputs that could slow down execution
55
- - ✅ Fire-and-forget logging (writes are queued and happen in background)
56
- - ✅ When order matters but you don't want to wait for each write
57
-
58
- **Note**: `relinka` queues writes in order but returns immediately without waiting for completion. This prevents blocking while maintaining write order.
59
-
60
- ## API
61
-
62
- ### Log Levels
63
-
64
- Both `logger` and `relinka` support the following log levels:
65
-
66
- | Level | Symbol | Color | Description |
67
- |-------|--------|-------|-------------|
68
- | `log` | `│ ` | White | General logging |
69
- | `error` | `✖ ` | Red | Error messages |
70
- | `fatal` | `☠ ` | Red | Fatal errors |
71
- | `warn` | `⚠ ` | Yellow | Warning messages |
72
- | `info` | `■ ` | Blue | Informational messages |
73
- | `success` | `✓ ` | Green | Success messages |
74
- | `debug` | `✱ ` | Gray | Debug messages |
75
- | `box` | - | White | Box-formatted messages |
76
- | `raw` | - | - | Raw output (no formatting) |
77
-
78
- ### Usage Patterns
79
-
80
- #### Method Calls
81
-
82
- ```typescript
83
- import { logger, relinka } from "@reliverse/relinka";
84
-
85
- // Synchronous
86
- logger.log("General message");
87
- logger.info("Information");
88
- logger.success("Operation succeeded");
89
- logger.warn("Warning message");
90
- logger.error("Error occurred");
91
- logger.fatal("Fatal error");
92
- logger.debug("Debug information");
93
- logger.box("Boxed message");
94
- logger.raw("Raw output without formatting");
95
-
96
- // Asynchronous (returns Promise<void>)
97
- await relinka.log("General message");
98
- await relinka.info("Information");
99
- await relinka.success("Operation succeeded");
100
- await relinka.warn("Warning message");
101
- await relinka.error("Error occurred");
102
- await relinka.fatal("Fatal error");
103
- await relinka.debug("Debug information");
104
- await relinka.box("Boxed message");
105
- await relinka.raw("Raw output without formatting");
106
- ```
107
-
108
- #### Callable Function
109
-
110
- Both loggers can be called as functions with the log level as the first argument:
111
-
112
- ```typescript
113
- import { logger, relinka } from "@reliverse/relinka";
114
-
115
- // Synchronous
116
- logger("info", "Application started");
117
- logger("success", "Build completed");
118
- logger("error", "Build failed");
119
-
120
- // Asynchronous
121
- await relinka("info", "Processing started");
122
- await relinka("success", "Processing completed");
123
- await relinka("error", "Processing failed");
124
- ```
125
-
126
- #### Multiple Arguments
127
-
128
- All log methods accept multiple arguments, which are automatically joined:
129
-
130
- ```typescript
131
- logger.info("User", username, "logged in");
132
- // Output: ■ User john_doe logged in
133
-
134
- logger.error("Failed to connect to", host, "on port", port);
135
- // Output: ✖ Failed to connect to localhost on port 3000
136
- ```
137
-
138
- ## Examples
139
-
140
- ### CLI Tool (Synchronous)
141
-
142
- ```typescript
143
- import { logger } from "@reliverse/relinka";
144
-
145
- async function buildProject() {
146
- logger.info("Starting build process...");
147
-
148
- try {
149
- // Build steps
150
- logger.success("Build completed successfully");
151
- } catch (error) {
152
- logger.error("Build failed:", error);
153
- process.exit(1);
154
- }
155
- }
156
- ```
157
-
158
- ### Concurrent Operations (Asynchronous)
159
-
160
- ```typescript
161
- import { relinka } from "@reliverse/relinka";
162
-
163
- async function processFiles(files: string[]) {
164
- // All logs are queued and won't block execution
165
- await Promise.all(
166
- files.map(async (file) => {
167
- await relinka.info(`Processing ${file}...`);
168
- // Process file...
169
- await relinka.success(`Completed ${file}`);
170
- })
171
- );
172
-
173
- // Writes happen in background, maintaining order
174
- await relinka.info("All files processed");
175
- }
176
- ```
177
-
178
- ### Box Formatting
179
-
180
- ```typescript
181
- import { logger } from "@reliverse/relinka";
182
-
183
- logger.box(`
184
- Welcome to My Application
185
- Version 1.0.0
186
- Ready to serve requests
187
- `);
188
-
189
- // Output:
190
- // ┌──────────────────────────────┐
191
- // │ Welcome to My Application │
192
- // │ Version 1.0.0 │
193
- // │ Ready to serve requests
194
- // └──────────────────────────────┘
195
- ```
196
-
197
- ### Error Handling
198
-
199
- ```typescript
200
- import { logger } from "@reliverse/relinka";
201
-
202
- try {
203
- await riskyOperation();
204
- logger.success("Operation completed");
205
- } catch (error) {
206
- logger.error("Operation failed");
207
- logger.fatal("Application cannot continue");
208
- if (error instanceof Error) {
209
- logger.raw(error.stack);
210
- }
211
- process.exit(1);
212
- }
213
- ```
214
-
215
- ### Conditional Logging
216
-
217
- ```typescript
218
- import { logger } from "@reliverse/relinka";
219
-
220
- const DEBUG = process.env.DEBUG === "true";
221
-
222
- if (DEBUG) {
223
- logger.debug("Debug mode enabled");
224
- logger.debug("Configuration:", config);
225
- }
226
- ```
227
-
228
- ## TypeScript Support
229
-
230
- Full TypeScript support with proper type inference:
231
-
232
- ```typescript
233
- import type { Logger, LoggerAsync } from "@reliverse/relinka";
234
- import { logger, relinka } from "@reliverse/relinka";
235
-
236
- // Type-safe log level
237
- type LogLevel = "log" | "error" | "fatal" | "warn" | "info" | "success" | "debug" | "box" | "raw";
238
-
239
- // Logger types
240
- const syncLogger: Logger = logger;
241
- const asyncLogger: LoggerAsync = relinka;
242
-
243
- // Function call with type safety
244
- logger("info", "Message"); // ✅ Valid
245
- relinka("info", "Message"); // Valid, returns Promise<void>
246
- ```
247
-
248
- ## Requirements
249
-
250
- - **Runtime**: Bun (uses `Bun.write` for async operations)
251
- - **TypeScript**: 5.0+ (for best experience)
252
-
253
- ## License
254
-
255
- MIT
256
-
257
- ## Related Packages
258
-
259
- - [@reliverse/relico](https://github.com/reliverse/relico) - Color utilities used by relinka
260
-
1
+ # @reliverse/relinka
2
+
3
+ A modern, lightweight logging library for TypeScript/JavaScript with both synchronous and asynchronous logging capabilities. Perfect for CLI tools, build systems, and concurrent applications.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **Dual Mode**: Synchronous (`logger`) and asynchronous (`relinka`) logging
8
+ - 🎨 **Colored Output**: Beautiful, color-coded log levels using [@reliverse/relico](https://github.com/reliverse/relico)
9
+ - 📦 **Zero Dependencies**: Only depends on `@reliverse/relico` for colors
10
+ - 🔒 **Thread-Safe**: Async logger uses write queuing to prevent interleaving
11
+ - 🎯 **Type-Safe**: Full TypeScript support with proper type inference
12
+ - 📝 **Multiple Log Levels**: `log`, `error`, `fatal`, `warn`, `info`, `success`, `debug`, `box`, `raw`
13
+ - 🎭 **Callable Interface**: Use as a function or with method calls
14
+ - ⚡ **Non-Blocking**: Async logger queues writes but returns immediately
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ bun add @reliverse/relinka
20
+ # or
21
+ npm install @reliverse/relinka
22
+ # or
23
+ pnpm add @reliverse/relinka
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```typescript
29
+ import { logger, relinka } from "@reliverse/relinka";
30
+
31
+ // Synchronous logging (blocks until write completes)
32
+ logger.info("Application started");
33
+ logger.success("Build completed successfully");
34
+ logger.error("Failed to load configuration");
35
+
36
+ // Asynchronous logging (queues writes, returns immediately)
37
+ await relinka.info("Processing files...");
38
+ await relinka.success("All files processed");
39
+ await relinka.error("File processing failed");
40
+ ```
41
+
42
+ ## When to Use Sync vs Async
43
+
44
+ ### Use `logger` (Synchronous) when:
45
+
46
+ - ✅ Sequential logging (like CLI tools with ordered output)
47
+ - ✅ Small, frequent console writes
48
+ - ✅ Error reporting that needs to maintain order
49
+ - ✅ When you need guaranteed write completion before continuing
50
+ - ✅ CLI tools where output order is critical
51
+
52
+ ### Use `relinka` (Asynchronous) when:
53
+
54
+ - ✅ Logging from multiple concurrent async operations
55
+ - ✅ High-frequency logging where you don't want to block
56
+ - ✅ Large log outputs that could slow down execution
57
+ - ✅ Fire-and-forget logging (writes are queued and happen in background)
58
+ - When order matters but you don't want to wait for each write
59
+
60
+ **Note**: `relinka` queues writes in order but returns immediately without waiting for completion. This prevents blocking while maintaining write order.
61
+
62
+ ## API
63
+
64
+ ### Log Levels
65
+
66
+ Both `logger` and `relinka` support the following log levels:
67
+
68
+ | Level | Symbol | Color | Description |
69
+ | --------- | ------ | ------ | -------------------------- |
70
+ | `log` | `│ ` | White | General logging |
71
+ | `error` | `✖ ` | Red | Error messages |
72
+ | `fatal` | `☠ ` | Red | Fatal errors |
73
+ | `warn` | `⚠ ` | Yellow | Warning messages |
74
+ | `info` | `■ ` | Blue | Informational messages |
75
+ | `success` | `✓ ` | Green | Success messages |
76
+ | `debug` | `✱ ` | Gray | Debug messages |
77
+ | `box` | - | White | Box-formatted messages |
78
+ | `raw` | - | - | Raw output (no formatting) |
79
+
80
+ ### Usage Patterns
81
+
82
+ #### Method Calls
83
+
84
+ ```typescript
85
+ import { logger, relinka } from "@reliverse/relinka";
86
+
87
+ // Synchronous
88
+ logger.log("General message");
89
+ logger.info("Information");
90
+ logger.success("Operation succeeded");
91
+ logger.warn("Warning message");
92
+ logger.error("Error occurred");
93
+ logger.fatal("Fatal error");
94
+ logger.debug("Debug information");
95
+ logger.box("Boxed message");
96
+ logger.raw("Raw output without formatting");
97
+
98
+ // Asynchronous (returns Promise<void>)
99
+ await relinka.log("General message");
100
+ await relinka.info("Information");
101
+ await relinka.success("Operation succeeded");
102
+ await relinka.warn("Warning message");
103
+ await relinka.error("Error occurred");
104
+ await relinka.fatal("Fatal error");
105
+ await relinka.debug("Debug information");
106
+ await relinka.box("Boxed message");
107
+ await relinka.raw("Raw output without formatting");
108
+ ```
109
+
110
+ #### Callable Function
111
+
112
+ Both loggers can be called as functions with the log level as the first argument:
113
+
114
+ ```typescript
115
+ import { logger, relinka } from "@reliverse/relinka";
116
+
117
+ // Synchronous
118
+ logger("info", "Application started");
119
+ logger("success", "Build completed");
120
+ logger("error", "Build failed");
121
+
122
+ // Asynchronous
123
+ await relinka("info", "Processing started");
124
+ await relinka("success", "Processing completed");
125
+ await relinka("error", "Processing failed");
126
+ ```
127
+
128
+ #### Multiple Arguments
129
+
130
+ All log methods accept multiple arguments, which are automatically joined:
131
+
132
+ ```typescript
133
+ logger.info("User", username, "logged in");
134
+ // Output: ■ User john_doe logged in
135
+
136
+ logger.error("Failed to connect to", host, "on port", port);
137
+ // Output: ✖ Failed to connect to localhost on port 3000
138
+ ```
139
+
140
+ ## Examples
141
+
142
+ ### CLI Tool (Synchronous)
143
+
144
+ ```typescript
145
+ import { logger } from "@reliverse/relinka";
146
+
147
+ async function buildProject() {
148
+ logger.info("Starting build process...");
149
+
150
+ try {
151
+ // Build steps
152
+ logger.success("Build completed successfully");
153
+ } catch (error) {
154
+ logger.error("Build failed:", error);
155
+ process.exit(1);
156
+ }
157
+ }
158
+ ```
159
+
160
+ ### Concurrent Operations (Asynchronous)
161
+
162
+ ```typescript
163
+ import { relinka } from "@reliverse/relinka";
164
+
165
+ async function processFiles(files: string[]) {
166
+ // All logs are queued and won't block execution
167
+ await Promise.all(
168
+ files.map(async (file) => {
169
+ await relinka.info(`Processing ${file}...`);
170
+ // Process file...
171
+ await relinka.success(`Completed ${file}`);
172
+ })
173
+ );
174
+
175
+ // Writes happen in background, maintaining order
176
+ await relinka.info("All files processed");
177
+ }
178
+ ```
179
+
180
+ ### Box Formatting
181
+
182
+ ```typescript
183
+ import { logger } from "@reliverse/relinka";
184
+
185
+ logger.box(`
186
+ Welcome to My Application
187
+ Version 1.0.0
188
+ Ready to serve requests
189
+ `);
190
+
191
+ // Output:
192
+ // ┌──────────────────────────────┐
193
+ // │ Welcome to My Application
194
+ // │ Version 1.0.0 │
195
+ // │ Ready to serve requests │
196
+ // └──────────────────────────────┘
197
+ ```
198
+
199
+ ### Error Handling
200
+
201
+ ```typescript
202
+ import { logger } from "@reliverse/relinka";
203
+
204
+ try {
205
+ await riskyOperation();
206
+ logger.success("Operation completed");
207
+ } catch (error) {
208
+ logger.error("Operation failed");
209
+ logger.fatal("Application cannot continue");
210
+ if (error instanceof Error) {
211
+ logger.raw(error.stack);
212
+ }
213
+ process.exit(1);
214
+ }
215
+ ```
216
+
217
+ ### Conditional Logging
218
+
219
+ ```typescript
220
+ import { logger } from "@reliverse/relinka";
221
+
222
+ const DEBUG = process.env.DEBUG === "true";
223
+
224
+ if (DEBUG) {
225
+ logger.debug("Debug mode enabled");
226
+ logger.debug("Configuration:", config);
227
+ }
228
+ ```
229
+
230
+ ## TypeScript Support
231
+
232
+ Full TypeScript support with proper type inference:
233
+
234
+ ```typescript
235
+ import type { Logger, LoggerAsync } from "@reliverse/relinka";
236
+ import { logger, relinka } from "@reliverse/relinka";
237
+
238
+ // Type-safe log level
239
+ type LogLevel = "log" | "error" | "fatal" | "warn" | "info" | "success" | "debug" | "box" | "raw";
240
+
241
+ // Logger types
242
+ const syncLogger: Logger = logger;
243
+ const asyncLogger: LoggerAsync = relinka;
244
+
245
+ // Function call with type safety
246
+ logger("info", "Message"); // ✅ Valid
247
+ relinka("info", "Message"); // ✅ Valid, returns Promise<void>
248
+ ```
249
+
250
+ ## Requirements
251
+
252
+ - **Runtime**: Bun (uses `Bun.write` for async operations)
253
+ - **TypeScript**: 5.0+ (for best experience)
254
+
255
+ ## License
256
+
257
+ MIT
258
+
259
+ ## Related Packages
260
+
261
+ - [@reliverse/relico](https://github.com/reliverse/relico) - Color utilities used by relinka
package/dist/mod.d.ts CHANGED
@@ -1,14 +1,4 @@
1
- declare const LOG_COLORS: {
2
- readonly log: any;
3
- readonly error: any;
4
- readonly fatal: any;
5
- readonly warn: any;
6
- readonly info: any;
7
- readonly success: any;
8
- readonly debug: any;
9
- readonly box: any;
10
- };
11
- type LogLevel = keyof typeof LOG_COLORS;
1
+ type LogLevel = "log" | "error" | "fatal" | "warn" | "info" | "success" | "debug" | "box";
12
2
  interface LoggerBase {
13
3
  log: (...args: unknown[]) => void | Promise<void>;
14
4
  error: (...args: unknown[]) => void | Promise<void>;
package/dist/mod.js CHANGED
@@ -23,13 +23,19 @@ const LOG_SYMBOLS = {
23
23
  let writeLock = Promise.resolve();
24
24
  const formatMessage = (...args) => {
25
25
  const len = args.length;
26
- if (len === 0) return "";
27
- if (len === 1) return String(args[0]);
26
+ if (len === 0) {
27
+ return "";
28
+ }
29
+ if (len === 1) {
30
+ return String(args[0]);
31
+ }
28
32
  return args.map(String).join(" ");
29
33
  };
30
34
  const createPrefixedMessage = (level, message) => {
31
35
  const symbol = LOG_SYMBOLS[level];
32
- if (symbol === "") return message;
36
+ if (symbol === "") {
37
+ return message;
38
+ }
33
39
  return symbol + message;
34
40
  };
35
41
  const formatBox = (message) => {
@@ -41,9 +47,13 @@ const formatBox = (message) => {
41
47
  let maxWidth = 0;
42
48
  for (let i = 0; i < lineCount; i++) {
43
49
  const line = lines[i];
44
- if (line === void 0) continue;
50
+ if (line === void 0) {
51
+ continue;
52
+ }
45
53
  const len = line.length;
46
- if (len > maxWidth) maxWidth = len;
54
+ if (len > maxWidth) {
55
+ maxWidth = len;
56
+ }
47
57
  }
48
58
  const padding = 2;
49
59
  const width = maxWidth + padding * 2;
@@ -61,7 +71,9 @@ ${bottom}`;
61
71
  let content = "";
62
72
  for (let i = 0; i < lineCount; i++) {
63
73
  const line = lines[i];
64
- if (line === void 0) continue;
74
+ if (line === void 0) {
75
+ continue;
76
+ }
65
77
  const padded = line.padEnd(maxWidth);
66
78
  content += `\u2502${leftPadding}${padded}${rightPadding}\u2502
67
79
  `;
package/package.json CHANGED
@@ -1,24 +1,25 @@
1
1
  {
2
2
  "name": "@reliverse/relinka",
3
- "version": "2.2.9",
3
+ "version": "2.3.2",
4
4
  "private": false,
5
- "type": "module",
6
5
  "description": "@reliverse/relinka is a modern and lightweight logging library.",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist",
9
+ "package.json",
10
+ "README.md"
11
+ ],
12
+ "type": "module",
7
13
  "exports": {
8
14
  ".": {
9
15
  "types": "./dist/mod.d.ts",
10
16
  "default": "./dist/mod.js"
11
17
  }
12
18
  },
13
- "dependencies": {
14
- "@reliverse/relico": "2.2.9"
15
- },
16
19
  "publishConfig": {
17
20
  "access": "public"
18
21
  },
19
- "files": [
20
- "dist",
21
- "package.json"
22
- ],
23
- "license": "MIT"
22
+ "dependencies": {
23
+ "@reliverse/relico": "2.3.2"
24
+ }
24
25
  }