@navios/core 0.1.12 → 0.1.14
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/dist/_tsup-dts-rollup.d.mts +9 -0
- package/dist/_tsup-dts-rollup.d.ts +9 -0
- package/dist/index.js +1336 -1308
- package/dist/index.mjs +1334 -1306
- package/package.json +3 -3
- package/src/logger/console-logger.service.mts +41 -3
- package/src/service-locator/service-locator.mts +1 -0
- package/src/services/controller-adapter.service.mts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navios/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Oleksandr Hanzha",
|
|
6
6
|
"email": "alex@granted.name"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"main": "./dist/index.js",
|
|
16
16
|
"module": "./dist/index.mjs",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@navios/common": "^0.1.
|
|
18
|
+
"@navios/common": "^0.1.5",
|
|
19
19
|
"zod": "^3.23.8"
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"./package.json": "./package.json"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@navios/common": "^0.1.
|
|
35
|
+
"@navios/common": "^0.1.5",
|
|
36
36
|
"tsx": "^4.19.4",
|
|
37
37
|
"typescript": "^5.8.3",
|
|
38
38
|
"zod": "^3.24.4"
|
|
@@ -5,7 +5,8 @@ import { inspect } from 'util'
|
|
|
5
5
|
import type { LogLevel } from './log-levels.mjs'
|
|
6
6
|
import type { LoggerService } from './logger-service.interface.mjs'
|
|
7
7
|
|
|
8
|
-
import { Injectable } from '../service-locator/index.mjs'
|
|
8
|
+
import { getServiceLocator, Injectable } from '../service-locator/index.mjs'
|
|
9
|
+
import { Request } from '../tokens/index.mjs'
|
|
9
10
|
import {
|
|
10
11
|
clc,
|
|
11
12
|
isFunction,
|
|
@@ -36,6 +37,10 @@ export interface ConsoleLoggerOptions {
|
|
|
36
37
|
* Note: This option is not used when `json` is enabled.
|
|
37
38
|
*/
|
|
38
39
|
prefix?: string
|
|
40
|
+
/**
|
|
41
|
+
* If enabled, will add a request ID to the log message.
|
|
42
|
+
*/
|
|
43
|
+
requestId?: boolean
|
|
39
44
|
/**
|
|
40
45
|
* If enabled, will print the log message in JSON format.
|
|
41
46
|
*/
|
|
@@ -128,6 +133,10 @@ export class ConsoleLogger implements LoggerService {
|
|
|
128
133
|
* The context of the logger (can be set manually or automatically inferred).
|
|
129
134
|
*/
|
|
130
135
|
protected context?: string
|
|
136
|
+
/**
|
|
137
|
+
* Request ID (if enabled).
|
|
138
|
+
*/
|
|
139
|
+
protected requestId: string | null = null
|
|
131
140
|
/**
|
|
132
141
|
* The original context of the logger (set in the constructor).
|
|
133
142
|
*/
|
|
@@ -168,6 +177,24 @@ export class ConsoleLogger implements LoggerService {
|
|
|
168
177
|
this.context = context
|
|
169
178
|
this.originalContext = context
|
|
170
179
|
}
|
|
180
|
+
if (opts?.requestId) {
|
|
181
|
+
const locator = getServiceLocator()
|
|
182
|
+
locator
|
|
183
|
+
.getEventBus()
|
|
184
|
+
.on(locator.getInstanceIdentifier(Request, undefined), 'create', () => {
|
|
185
|
+
const request = locator.getSyncInstance(Request, undefined)
|
|
186
|
+
this.requestId = request?.id ?? null
|
|
187
|
+
})
|
|
188
|
+
locator
|
|
189
|
+
.getEventBus()
|
|
190
|
+
.on(
|
|
191
|
+
locator.getInstanceIdentifier(Request, undefined),
|
|
192
|
+
'destroy',
|
|
193
|
+
() => {
|
|
194
|
+
this.requestId = null
|
|
195
|
+
},
|
|
196
|
+
)
|
|
197
|
+
}
|
|
171
198
|
}
|
|
172
199
|
|
|
173
200
|
/**
|
|
@@ -358,6 +385,7 @@ export class ConsoleLogger implements LoggerService {
|
|
|
358
385
|
message: unknown
|
|
359
386
|
context?: string
|
|
360
387
|
stack?: unknown
|
|
388
|
+
requestId?: string
|
|
361
389
|
}
|
|
362
390
|
|
|
363
391
|
const logObject: JsonLogObject = {
|
|
@@ -374,6 +402,9 @@ export class ConsoleLogger implements LoggerService {
|
|
|
374
402
|
if (options.errorStack) {
|
|
375
403
|
logObject.stack = options.errorStack
|
|
376
404
|
}
|
|
405
|
+
if (this.options.requestId && this.requestId) {
|
|
406
|
+
logObject.requestId = this.requestId
|
|
407
|
+
}
|
|
377
408
|
|
|
378
409
|
const formattedMessage =
|
|
379
410
|
!this.options.colors && this.inspectOptions.compact === true
|
|
@@ -383,7 +414,7 @@ export class ConsoleLogger implements LoggerService {
|
|
|
383
414
|
}
|
|
384
415
|
|
|
385
416
|
protected formatPid(pid: number) {
|
|
386
|
-
return `[${this.options.prefix}] ${pid}
|
|
417
|
+
return `[${this.options.prefix}] ${pid} - `
|
|
387
418
|
}
|
|
388
419
|
|
|
389
420
|
protected formatContext(context: string): string {
|
|
@@ -406,7 +437,14 @@ export class ConsoleLogger implements LoggerService {
|
|
|
406
437
|
const output = this.stringifyMessage(message, logLevel)
|
|
407
438
|
pidMessage = this.colorize(pidMessage, logLevel)
|
|
408
439
|
formattedLogLevel = this.colorize(formattedLogLevel, logLevel)
|
|
409
|
-
return `${pidMessage}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}\n`
|
|
440
|
+
return `${pidMessage}${this.getRequestId()}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}\n`
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
protected getRequestId() {
|
|
444
|
+
if (this.options.requestId && this.requestId) {
|
|
445
|
+
return `(${this.colorize(this.requestId, 'log')}) `
|
|
446
|
+
}
|
|
447
|
+
return ''
|
|
410
448
|
}
|
|
411
449
|
|
|
412
450
|
protected stringifyMessage(message: unknown, logLevel: LogLevel): string {
|