@reliverse/relinka 1.5.5 → 1.5.7

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/bin/impl.js CHANGED
@@ -1,8 +1,8 @@
1
+ import os from "node:os";
1
2
  import path from "@reliverse/pathkit";
2
3
  import { re } from "@reliverse/relico";
3
4
  import fs from "@reliverse/relifso";
4
5
  import { loadConfig } from "c12";
5
- import os from "node:os";
6
6
  import {
7
7
  DEFAULT_RELINKA_CONFIG,
8
8
  ENABLE_DEV_DEBUG,
@@ -43,13 +43,9 @@ export async function relinkaConfig(options = {}) {
43
43
  await fs.ensureDir(path.dirname(logFilePath));
44
44
  await fs.writeFile(logFilePath, "");
45
45
  if (isVerboseEnabled(config)) {
46
- console.log(`[Relinka Fresh Log] Cleared log file: ${logFilePath}`);
47
46
  }
48
- } catch (err) {
47
+ } catch (_err) {
49
48
  if (isVerboseEnabled(config)) {
50
- console.error(
51
- `[Relinka Fresh Log Error] Failed to clear log file: ${err instanceof Error ? err.message : String(err)}`
52
- );
53
49
  }
54
50
  }
55
51
  }
@@ -77,14 +73,10 @@ async function initializeConfig() {
77
73
  if (result.config?.relinka) {
78
74
  currentConfig = { ...DEFAULT_RELINKA_CONFIG, ...result.config.relinka };
79
75
  if (ENABLE_DEV_DEBUG) {
80
- console.log("[Dev Debug] Using relinka config from dler config");
81
76
  }
82
77
  } else {
83
78
  currentConfig = { ...DEFAULT_RELINKA_CONFIG };
84
79
  if (ENABLE_DEV_DEBUG) {
85
- console.log(
86
- "[Dev Debug] No relinka config in dler config, using defaults"
87
- );
88
80
  }
89
81
  }
90
82
  } catch {
@@ -99,21 +91,14 @@ async function initializeConfig() {
99
91
  });
100
92
  currentConfig = relinkaResult.config;
101
93
  if (ENABLE_DEV_DEBUG) {
102
- console.log(
103
- "[Dev Debug] Dler config loading failed, using separate relinka config"
104
- );
105
94
  }
106
95
  }
107
96
  isConfigInitialized = true;
108
97
  resolveRelinkaConfig?.(currentConfig);
109
98
  resolveRelinkaConfig = void 0;
110
99
  if (ENABLE_DEV_DEBUG) {
111
- console.log("[Dev Debug] Final configuration:", currentConfig);
112
100
  }
113
- } catch (err) {
114
- console.error(
115
- `[Relinka Config Error] Failed to load config: ${err instanceof Error ? err.message : String(err)}`
116
- );
101
+ } catch (_err) {
117
102
  currentConfig = { ...DEFAULT_RELINKA_CONFIG };
118
103
  isConfigInitialized = true;
119
104
  resolveRelinkaConfig?.(currentConfig);
@@ -140,10 +125,7 @@ function setupBufferFlushTimer() {
140
125
  }
141
126
  }
142
127
  }
143
- initializeConfig().catch((err) => {
144
- console.error(
145
- `[Relinka Config Error] Unhandled error: ${err instanceof Error ? err.message : String(err)}`
146
- );
128
+ initializeConfig().catch((_err) => {
147
129
  if (!isConfigInitialized) {
148
130
  currentConfig = { ...DEFAULT_RELINKA_CONFIG };
149
131
  isConfigInitialized = true;
@@ -191,7 +173,9 @@ function getDateString(date = /* @__PURE__ */ new Date()) {
191
173
  ).padStart(2, "0")}`;
192
174
  }
193
175
  function getTimestamp(config) {
194
- if (!config.timestamp?.enabled) return "";
176
+ if (!config.timestamp?.enabled) {
177
+ return "";
178
+ }
195
179
  const now = /* @__PURE__ */ new Date();
196
180
  const format = config.timestamp?.format || "YYYY-MM-DD HH:mm:ss.SSS";
197
181
  return format.replace("YYYY", String(now.getFullYear())).replace("MM", String(now.getMonth() + 1).padStart(2, "0")).replace("DD", String(now.getDate()).padStart(2, "0")).replace("HH", String(now.getHours()).padStart(2, "0")).replace("mm", String(now.getMinutes()).padStart(2, "0")).replace("ss", String(now.getSeconds()).padStart(2, "0")).replace("SSS", String(now.getMilliseconds()).padStart(3, "0"));
@@ -245,7 +229,9 @@ function getLevelStyle(config, level) {
245
229
  };
246
230
  }
247
231
  function formatDetails(details) {
248
- if (details === void 0) return "";
232
+ if (details === void 0) {
233
+ return "";
234
+ }
249
235
  if (details instanceof Error) {
250
236
  return `
251
237
  Stack Trace: ${details.stack || details.message}`;
@@ -315,84 +301,74 @@ async function getLogFilesSortedByDate(config) {
315
301
  logFiles.push(path.join(file, subFile));
316
302
  }
317
303
  }
318
- } catch (subDirErr) {
304
+ } catch (_subDirErr) {
319
305
  if (isVerboseEnabled(config)) {
320
- console.error(
321
- `[Relinka FS Debug] Error reading subdirectory ${filePath}: ${subDirErr instanceof Error ? subDirErr.message : String(subDirErr)}`
322
- );
323
306
  }
324
307
  }
325
308
  }
326
- } catch (err) {
309
+ } catch (_err) {
327
310
  if (isVerboseEnabled(config)) {
328
- console.error(
329
- `[Relinka FS Debug] Error accessing ${filePath}: ${err instanceof Error ? err.message : String(err)}`
330
- );
331
311
  }
332
312
  }
333
313
  }
334
- if (logFiles.length === 0) return [];
335
- const fileInfoPromises = logFiles.map(
336
- async (fileName) => {
337
- const filePath = path.join(logDirectoryPath, fileName);
338
- try {
339
- const stats = await fs.stat(filePath);
340
- if (stats.isFile()) {
341
- return { path: filePath, mtime: stats.mtime.getTime() };
342
- }
343
- return null;
344
- } catch (err) {
345
- if (isVerboseEnabled(config)) {
346
- console.error(
347
- `[Relinka FS Debug] Error reading stats for ${filePath}: ${err instanceof Error ? err.message : String(err)}`
348
- );
349
- }
350
- return null;
314
+ if (logFiles.length === 0) {
315
+ return [];
316
+ }
317
+ const fileInfoPromises = logFiles.map(async (fileName) => {
318
+ const filePath = path.join(logDirectoryPath, fileName);
319
+ try {
320
+ const stats = await fs.stat(filePath);
321
+ if (stats.isFile()) {
322
+ return { path: filePath, mtime: stats.mtime.getTime() };
323
+ }
324
+ return null;
325
+ } catch (_err) {
326
+ if (isVerboseEnabled(config)) {
351
327
  }
328
+ return null;
352
329
  }
353
- );
330
+ });
354
331
  const logFileInfos = (await Promise.all(fileInfoPromises)).filter(Boolean);
355
332
  return logFileInfos.sort((a, b) => b.mtime - a.mtime);
356
- } catch (readErr) {
333
+ } catch (_readErr) {
357
334
  if (isVerboseEnabled(config)) {
358
- console.error(
359
- `[Relinka FS Error] Failed reading directory ${logDirectoryPath}: ${readErr instanceof Error ? readErr.message : String(readErr)}`
360
- );
361
335
  }
362
336
  return [];
363
337
  }
364
338
  }
365
339
  async function deleteFiles(filePaths, config) {
366
- if (filePaths.length === 0) return;
367
- const results = await Promise.allSettled(
368
- filePaths.map((filePath) => fs.unlink(filePath))
369
- );
340
+ if (filePaths.length === 0) {
341
+ return;
342
+ }
343
+ const results = await Promise.allSettled(filePaths.map((filePath) => fs.unlink(filePath)));
370
344
  const errors = results.map(
371
345
  (result, index) => result.status === "rejected" ? { path: filePaths[index], error: result.reason } : null
372
346
  ).filter(Boolean);
373
347
  if (errors.length > 0 && isVerboseEnabled(config)) {
374
- console.error(
375
- `[Relinka FS Error] Failed to delete ${errors.length} log files:`,
376
- errors.map(
377
- (e) => `${e?.path}: ${e?.error instanceof Error ? e.error.message : String(e?.error)}`
378
- ).join(", ")
379
- );
380
348
  }
381
349
  }
382
350
  let sigintHandler;
383
351
  let sigtermHandler;
384
352
  export async function relinkaShutdown() {
385
- activeTimers.forEach((timer) => clearTimeout(timer));
353
+ activeTimers.forEach((timer) => {
354
+ clearTimeout(timer);
355
+ });
386
356
  activeTimers.length = 0;
387
357
  cleanupScheduled = false;
388
- if (sigintHandler) process.off("SIGINT", sigintHandler);
389
- if (sigtermHandler) process.off("SIGTERM", sigtermHandler);
358
+ if (sigintHandler) {
359
+ process.off("SIGINT", sigintHandler);
360
+ }
361
+ if (sigtermHandler) {
362
+ process.off("SIGTERM", sigtermHandler);
363
+ }
390
364
  await flushAllLogBuffers();
391
365
  }
392
366
  async function cleanupOldLogFiles(config) {
393
367
  const maxFiles = getMaxLogFiles(config);
394
368
  const cleanupInterval = getCleanupInterval(config);
395
- if (!shouldSaveLogs(config) || maxFiles <= 0) return;
369
+ if (!shouldSaveLogs(config) || maxFiles <= 0) {
370
+ return;
371
+ }
396
372
  const now = Date.now();
397
373
  if (now - lastCleanupTime < cleanupInterval) {
398
374
  if (!cleanupScheduled) {
@@ -402,12 +378,11 @@ async function cleanupOldLogFiles(config) {
402
378
  cleanupScheduled = false;
403
379
  lastCleanupTime = Date.now();
404
380
  const index = activeTimers.indexOf(timer);
405
- if (index !== -1) activeTimers.splice(index, 1);
406
- cleanupOldLogFiles(config).catch((err) => {
381
+ if (index !== -1) {
382
+ activeTimers.splice(index, 1);
383
+ }
384
+ cleanupOldLogFiles(config).catch((_err) => {
407
385
  if (isVerboseEnabled(config)) {
408
- console.error(
409
- `[Relinka Delayed Cleanup Error] ${err instanceof Error ? err.message : String(err)}`
410
- );
411
386
  }
412
387
  });
413
388
  }, delay);
@@ -424,17 +399,11 @@ async function cleanupOldLogFiles(config) {
424
399
  if (filesToDelete.length > 0) {
425
400
  await deleteFiles(filesToDelete, config);
426
401
  if (isVerboseEnabled(config)) {
427
- console.log(
428
- `[Relinka Cleanup] Deleted ${filesToDelete.length} old log file(s). Kept ${maxFiles}.`
429
- );
430
402
  }
431
403
  }
432
404
  }
433
- } catch (err) {
405
+ } catch (_err) {
434
406
  if (isVerboseEnabled(config)) {
435
- console.error(
436
- `[Relinka Cleanup Error] Failed during log cleanup: ${err instanceof Error ? err.message : String(err)}`
437
- );
438
407
  }
439
408
  }
440
409
  }
@@ -443,11 +412,8 @@ async function appendToLogFileImmediate(config, absoluteLogFilePath, logMessage)
443
412
  await fs.ensureDir(path.dirname(absoluteLogFilePath));
444
413
  await fs.appendFile(absoluteLogFilePath, `${logMessage}
445
414
  `);
446
- } catch (err) {
415
+ } catch (_err) {
447
416
  if (isVerboseEnabled(config)) {
448
- console.error(
449
- `[Relinka File Error] Failed to write to log file ${absoluteLogFilePath}: ${err instanceof Error ? err.message : String(err)}`
450
- );
451
417
  }
452
418
  }
453
419
  }
@@ -483,11 +449,8 @@ function flushLogBuffer(config, filePath) {
483
449
  buffer.lastFlush = Date.now();
484
450
  logWriteChain = logWriteChain.then(() => {
485
451
  return appendToLogFileImmediate(config, filePath, content);
486
- }).catch((err) => {
452
+ }).catch((_err) => {
487
453
  if (isVerboseEnabled(config)) {
488
- console.error(
489
- `[Relinka Buffer Flush Error] Failed to flush buffer for ${filePath}: ${err instanceof Error ? err.message : String(err)}`
490
- );
491
454
  }
492
455
  });
493
456
  return logWriteChain;
@@ -497,9 +460,7 @@ function queueLogWrite(config, absoluteLogFilePath, logMessage) {
497
460
  }
498
461
  export async function flushAllLogBuffers() {
499
462
  const filePaths = Array.from(logBuffers.keys());
500
- await Promise.all(
501
- filePaths.map((path2) => flushLogBuffer(currentConfig, path2))
502
- );
463
+ await Promise.all(filePaths.map((path2) => flushLogBuffer(currentConfig, path2)));
503
464
  }
504
465
  function internalFatalLogAndThrow(message, ...args) {
505
466
  const formatted = formatLogMessage(currentConfig, "fatal", message, args);
@@ -510,10 +471,7 @@ function internalFatalLogAndThrow(message, ...args) {
510
471
  fs.ensureDirSync(path.dirname(absoluteLogFilePath));
511
472
  fs.appendFileSync(absoluteLogFilePath, `${formatted}
512
473
  `);
513
- } catch (err) {
514
- console.error(
515
- `[Relinka Fatal File Error] Failed to write fatal error: ${err instanceof Error ? err.message : String(err)}`
516
- );
474
+ } catch (_err) {
517
475
  }
518
476
  }
519
477
  if (isDevEnv()) {
@@ -525,7 +483,9 @@ export function shouldNeverHappen(message, ...args) {
525
483
  return internalFatalLogAndThrow(message, ...args);
526
484
  }
527
485
  export function truncateString(msg, maxLength = 100) {
528
- if (!msg || msg.length <= maxLength) return msg;
486
+ if (!msg || msg.length <= maxLength) {
487
+ return msg;
488
+ }
529
489
  return `${msg.slice(0, maxLength - 1)}\u2026`;
530
490
  }
531
491
  export function casesHandled(unexpectedCase) {
@@ -535,7 +495,9 @@ export function casesHandled(unexpectedCase) {
535
495
  );
536
496
  }
537
497
  function registerExitHandlers() {
538
- if (globalThis[EXIT_GUARD]) return;
498
+ if (globalThis[EXIT_GUARD]) {
499
+ return;
500
+ }
539
501
  globalThis[EXIT_GUARD] = true;
540
502
  process.once("beforeExit", () => {
541
503
  void flushAllLogBuffers();
@@ -550,13 +512,11 @@ function registerExitHandlers() {
550
512
  process.once("SIGTERM", sigtermHandler);
551
513
  }
552
514
  registerExitHandlers();
553
- export const relinka = (type, message, ...args) => {
515
+ export const relinka = ((type, message, ...args) => {
554
516
  if (type === "clear") {
555
- console.clear();
556
517
  return;
557
518
  }
558
519
  if (message === "") {
559
- console.log();
560
520
  return;
561
521
  }
562
522
  const levelName = type.toLowerCase();
@@ -567,35 +527,22 @@ export const relinka = (type, message, ...args) => {
567
527
  return;
568
528
  }
569
529
  const details = args.length > 1 ? args : args[0];
570
- const formatted = formatLogMessage(
571
- currentConfig,
572
- levelName,
573
- message,
574
- details
575
- );
530
+ const formatted = formatLogMessage(currentConfig, levelName, message, details);
576
531
  logToConsole(currentConfig, levelName, formatted);
577
532
  if (shouldSaveLogs(currentConfig) && levelName !== "fatal") {
578
533
  const absoluteLogFilePath = getLogFilePath(currentConfig);
579
- queueLogWrite(currentConfig, absoluteLogFilePath, formatted).catch(
580
- (err) => {
581
- if (isVerboseEnabled(currentConfig)) {
582
- console.error(
583
- `[Relinka File Error] Failed to write log line: ${err instanceof Error ? err.message : String(err)}`
584
- );
585
- }
534
+ queueLogWrite(currentConfig, absoluteLogFilePath, formatted).catch((_err) => {
535
+ if (isVerboseEnabled(currentConfig)) {
586
536
  }
587
- );
537
+ });
588
538
  if (getMaxLogFiles(currentConfig) > 0) {
589
- cleanupOldLogFiles(currentConfig).catch((err) => {
539
+ cleanupOldLogFiles(currentConfig).catch((_err) => {
590
540
  if (isVerboseEnabled(currentConfig)) {
591
- console.error(
592
- `[Relinka Cleanup Error] ${err instanceof Error ? err.message : String(err)}`
593
- );
594
541
  }
595
542
  });
596
543
  }
597
544
  }
598
- };
545
+ });
599
546
  relinka.error = (message, ...args) => relinka("error", message, ...args);
600
547
  relinka.fatal = (message, ...args) => relinka("fatal", message, ...args);
601
548
  relinka.info = (message, ...args) => relinka("info", message, ...args);
@@ -611,7 +558,6 @@ relinka.clear = () => relinka("clear", "");
611
558
  relinka.message = (message, ...args) => relinka("message", message, ...args);
612
559
  export async function relinkaAsync(type, message, ...args) {
613
560
  if (message === "") {
614
- console.log();
615
561
  return;
616
562
  }
617
563
  await relinkaConfig({ supportFreshLogFile: false });
@@ -623,12 +569,7 @@ export async function relinkaAsync(type, message, ...args) {
623
569
  return;
624
570
  }
625
571
  const details = args.length > 1 ? args : args[0];
626
- const formatted = formatLogMessage(
627
- currentConfig,
628
- levelName,
629
- message,
630
- details
631
- );
572
+ const formatted = formatLogMessage(currentConfig, levelName, message, details);
632
573
  logToConsole(currentConfig, levelName, formatted);
633
574
  if (shouldSaveLogs(currentConfig)) {
634
575
  const absoluteLogFilePath = getLogFilePath(currentConfig);
@@ -637,11 +578,8 @@ export async function relinkaAsync(type, message, ...args) {
637
578
  if (getMaxLogFiles(currentConfig) > 0) {
638
579
  await cleanupOldLogFiles(currentConfig);
639
580
  }
640
- } catch (err) {
581
+ } catch (_err) {
641
582
  if (isVerboseEnabled(currentConfig)) {
642
- console.error(
643
- `[Relinka File Async Error] Error during file logging/cleanup: ${err instanceof Error ? err.message : String(err)}`
644
- );
645
583
  }
646
584
  }
647
585
  }
package/bin/mod.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { message, step, log, logger } from "./alias.js";
2
- export type { RelinkaDirsConfig, LogLevelConfig, LogLevelsConfig, LogLevel, RelinkaConfig, LogFileInfo, RelinkaFunction, RelinkaConfigOptions, } from "./setup.js";
3
- export { loadRelinkaConfig, relinkaConfig, relinkaShutdown, flushAllLogBuffers, shouldNeverHappen, truncateString, casesHandled, relinka, relinkaAsync, defineConfig, formatBox, } from "./impl.js";
1
+ export { log, logger, message, step } from "./alias.js";
2
+ export { casesHandled, defineConfig, flushAllLogBuffers, formatBox, loadRelinkaConfig, relinka, relinkaAsync, relinkaConfig, relinkaShutdown, shouldNeverHappen, truncateString, } from "./impl.js";
3
+ export type { LogFileInfo, LogLevel, LogLevelConfig, LogLevelsConfig, RelinkaConfig, RelinkaConfigOptions, RelinkaDirsConfig, RelinkaFunction, } from "./setup.js";
package/bin/mod.js CHANGED
@@ -1,14 +1,14 @@
1
- export { message, step, log, logger } from "./alias.js";
1
+ export { log, logger, message, step } from "./alias.js";
2
2
  export {
3
+ casesHandled,
4
+ defineConfig,
5
+ flushAllLogBuffers,
6
+ formatBox,
3
7
  loadRelinkaConfig,
8
+ relinka,
9
+ relinkaAsync,
4
10
  relinkaConfig,
5
11
  relinkaShutdown,
6
- flushAllLogBuffers,
7
12
  shouldNeverHappen,
8
- truncateString,
9
- casesHandled,
10
- relinka,
11
- relinkaAsync,
12
- defineConfig,
13
- formatBox
13
+ truncateString
14
14
  } from "./impl.js";
package/bin/setup.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { DefaultColorKeys } from "@reliverse/relico";
1
+ import type { DefaultColorKeys } from "./types";
2
2
  export declare const ENABLE_DEV_DEBUG = false;
3
3
  export declare const EXIT_GUARD: unique symbol;
4
4
  /** Configuration for directory-related settings. */
package/bin/types.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { ColorName, ReStyleKey } from "@reliverse/relico";
2
+ export type DefaultColorKeys = ColorName | ReStyleKey;
package/bin/types.js ADDED
File without changes
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "dependencies": {
3
3
  "@reliverse/pathkit": "^1.3.4",
4
- "@reliverse/relico": "^1.1.2",
4
+ "@reliverse/relico": "^1.3.5",
5
5
  "@reliverse/relifso": "^1.4.5",
6
- "c12": "^3.0.4"
6
+ "c12": "^3.2.0"
7
7
  },
8
8
  "description": "@reliverse/relinka is a modern, minimal logging library that actually feels right. It's not just pretty output — it's a system: smart formatting, file-safe logging, runtime config support, and a fatal mode built for developers who care about correctness.",
9
- "homepage": "https://docs.reliverse.org",
9
+ "homepage": "https://docs.reliverse.org/cli",
10
10
  "license": "MIT",
11
11
  "name": "@reliverse/relinka",
12
12
  "type": "module",
13
- "version": "1.5.5",
13
+ "version": "1.5.7",
14
14
  "keywords": [
15
15
  "logger",
16
16
  "consola",