@carno.js/logger 1.0.7 → 1.0.9

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.
@@ -57,6 +57,7 @@ export declare class LoggerService {
57
57
  private flushTimer;
58
58
  private flushInterval;
59
59
  constructor(config?: LoggerConfig);
60
+ shutdown(): void;
60
61
  /**
61
62
  * Debug level log.
62
63
  */
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.LoggerService = exports.LogLevel = void 0;
4
13
  /**
@@ -13,6 +22,7 @@ var LogLevel;
13
22
  LogLevel[LogLevel["FATAL"] = 4] = "FATAL";
14
23
  LogLevel[LogLevel["SILENT"] = 5] = "SILENT";
15
24
  })(LogLevel || (exports.LogLevel = LogLevel = {}));
25
+ const core_1 = require("@carno.js/core");
16
26
  // ANSI color codes for beautiful output
17
27
  const COLORS = {
18
28
  reset: '\x1b[0m',
@@ -77,6 +87,11 @@ class LoggerService {
77
87
  if (this.flushInterval > 0) {
78
88
  this.flushTimer = setInterval(() => this.flush(), this.flushInterval);
79
89
  }
90
+ // Ensure logs are flushed when the process exits
91
+ process.on('exit', () => this.flush());
92
+ }
93
+ shutdown() {
94
+ this.flush();
80
95
  }
81
96
  /**
82
97
  * Debug level log.
@@ -233,3 +248,9 @@ class LoggerService {
233
248
  }
234
249
  }
235
250
  exports.LoggerService = LoggerService;
251
+ __decorate([
252
+ (0, core_1.OnApplicationShutdown)(),
253
+ __metadata("design:type", Function),
254
+ __metadata("design:paramtypes", []),
255
+ __metadata("design:returntype", void 0)
256
+ ], LoggerService.prototype, "shutdown", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carno.js/logger",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "High-performance async logger for carno.js",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -22,5 +22,5 @@
22
22
  "publishConfig": {
23
23
  "access": "public"
24
24
  },
25
- "gitHead": "efb31a63e5e15d225a89f7b0da4c71372900e523"
25
+ "gitHead": "fa05f099ca5f185b7f823d5d3304cce111046584"
26
26
  }
@@ -33,6 +33,8 @@ export interface LoggerConfig {
33
33
  flushInterval?: number;
34
34
  }
35
35
 
36
+ import { OnApplicationShutdown } from '@carno.js/core';
37
+
36
38
  /**
37
39
  * Structured log data.
38
40
  */
@@ -104,6 +106,7 @@ export class LoggerService {
104
106
  private flushTimer: Timer | null = null;
105
107
  private flushInterval: number;
106
108
 
109
+
107
110
  constructor(config: LoggerConfig = {}) {
108
111
  this.level = this.parseLevel(config.level ?? LogLevel.INFO);
109
112
  this.pretty = config.pretty ?? true;
@@ -115,6 +118,14 @@ export class LoggerService {
115
118
  if (this.flushInterval > 0) {
116
119
  this.flushTimer = setInterval(() => this.flush(), this.flushInterval);
117
120
  }
121
+
122
+ // Ensure logs are flushed when the process exits
123
+ process.on('exit', () => this.flush());
124
+ }
125
+
126
+ @OnApplicationShutdown()
127
+ shutdown(): void {
128
+ this.flush();
118
129
  }
119
130
 
120
131
  /**