@leancodepl/logger 10.4.0 → 10.5.0
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/CHANGELOG.md +14 -0
- package/README.md +156 -11
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/{cliLogger-BIKHGxBN.js → cliLogger-B-IrZcje.js} +1 -1
- package/dist/{cliLogger-xnFprY-d.cjs → cliLogger-DrCrhkRC.cjs} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/json.cjs +1 -1
- package/dist/json.js +1 -1
- package/dist/lib/cliLogger.d.ts +26 -7
- package/dist/lib/cliLogger.d.ts.map +1 -1
- package/dist/lib/jsonLogger.d.ts +28 -7
- package/dist/lib/jsonLogger.d.ts.map +1 -1
- package/dist/lib/logLevels.d.ts +25 -0
- package/dist/lib/logLevels.d.ts.map +1 -1
- package/dist/lib/logger.d.ts +114 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/nestLogger.d.ts +21 -0
- package/dist/lib/nestLogger.d.ts.map +1 -1
- package/dist/{logger-Xwf0bgzB.js → logger-CFrlEist.js} +1 -1
- package/dist/logger-RyIBF1kr.cjs +1 -0
- package/dist/nest.cjs +2 -2
- package/dist/nest.js +37 -34
- package/package.json +1 -1
- package/dist/logger-CSPbXuiG.cjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [10.5.0](https://github.com/leancodepl/js_corelibrary/compare/v10.4.0...v10.5.0) (2026-07-01)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **logger:** add tsconfig.spec project reference to fix typecheck
|
|
11
|
+
([88911da](https://github.com/leancodepl/js_corelibrary/commit/88911da2459efb5694d375602c3277f6ed819080))
|
|
12
|
+
- resolve pre-existing typecheck errors in logger affected set
|
|
13
|
+
([9bb40cf](https://github.com/leancodepl/js_corelibrary/commit/9bb40cf62ffd84b55f1bb20a19aef1fcf7a15dff))
|
|
14
|
+
|
|
15
|
+
# Change Log
|
|
16
|
+
|
|
17
|
+
All notable changes to this project will be documented in this file. See
|
|
18
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
19
|
+
|
|
6
20
|
# [10.4.0](https://github.com/leancodepl/js_corelibrary/compare/v10.3.1...v10.4.0) (2026-06-23)
|
|
7
21
|
|
|
8
22
|
**Note:** Version bump only for package @leancodepl/logger
|
package/README.md
CHANGED
|
@@ -7,9 +7,151 @@ A lightweight, type-safe logger with middleware support and contextual messages.
|
|
|
7
7
|
- **`@leancodepl/logger`** – Core API below (custom handlers, context, middleware).
|
|
8
8
|
- **`@leancodepl/logger/cli`** – Colored console preset with log levels: `createCliLogger`, `LogLevel`, `allLogLevels`.
|
|
9
9
|
- **`@leancodepl/logger/json`** – JSON lines to stdout: `createJsonLogger` with the same level options as CLI.
|
|
10
|
-
- **`@leancodepl/logger/nest`** – NestJS adapter: `createNestJsonLogger()` implementing `LoggerService` with JSON
|
|
10
|
+
- **`@leancodepl/logger/nest`** – NestJS adapter: `createNestJsonLogger()` implementing `LoggerService` with JSON
|
|
11
|
+
output.
|
|
11
12
|
|
|
12
|
-
##
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @leancodepl/logger
|
|
17
|
+
# or
|
|
18
|
+
yarn add @leancodepl/logger
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## API
|
|
22
|
+
|
|
23
|
+
### `createLogger(methods)`
|
|
24
|
+
|
|
25
|
+
Creates a logger from a map of method definitions. Each definition becomes a callable method on the returned logger, and
|
|
26
|
+
the logger starts with an empty context that can be extended via `withContext`.
|
|
27
|
+
|
|
28
|
+
**Parameters:**
|
|
29
|
+
|
|
30
|
+
- `methods: TDefs` - Map of method name to its `MethodHandler`
|
|
31
|
+
|
|
32
|
+
**Returns:** A logger exposing the defined methods plus `withContext` and `withMiddleware`.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { createLogger } from "@leancodepl/logger"
|
|
36
|
+
|
|
37
|
+
const logger = createLogger({
|
|
38
|
+
info: (context, ...messages) => console.info(...messages),
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
logger.withContext({ requestId: "req-1" }).info("started")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `isContextualMessage(message)`
|
|
45
|
+
|
|
46
|
+
Type guard that narrows a `LoggerMessage` to a `ContextualLoggerMessage`. Used by logger implementations to decide
|
|
47
|
+
whether a message must be invoked with the context or logged as-is.
|
|
48
|
+
|
|
49
|
+
**Parameters:**
|
|
50
|
+
|
|
51
|
+
- `message: LoggerMessage<TContext, TOutput>` - The message to inspect
|
|
52
|
+
|
|
53
|
+
**Returns:** `true` when the message is a context-consuming function.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { isContextualMessage } from "@leancodepl/logger"
|
|
57
|
+
|
|
58
|
+
const resolved = isContextualMessage(message) ? message(context) : message
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `createCliLogger(options)`
|
|
62
|
+
|
|
63
|
+
Creates a logger preset for command-line output. Each log level maps to the matching `console` method and is prefixed
|
|
64
|
+
with a colorized `[LEVEL]` label via middleware. Messages below the enabled threshold are skipped.
|
|
65
|
+
|
|
66
|
+
**Parameters:**
|
|
67
|
+
|
|
68
|
+
- `options?: { enabledLogLevels?: LogLevel[] }` - Levels that should be emitted; defaults to `defaultEnabledLogLevels`
|
|
69
|
+
(error, warn, success, info)
|
|
70
|
+
|
|
71
|
+
**Returns:** A logger with one method per `LogLevel` label.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { createCliLogger } from "@leancodepl/logger/cli"
|
|
75
|
+
|
|
76
|
+
const logger = createCliLogger()
|
|
77
|
+
logger.info("server started")
|
|
78
|
+
logger.error("something failed", new Error("boom"))
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### `createJsonLogger(options)`
|
|
82
|
+
|
|
83
|
+
Creates a logger preset that writes one JSON object per line to `process.stdout`. Each entry includes the level label,
|
|
84
|
+
an ISO timestamp, the joined message, and the context (when non-empty). `Error` values are serialized to
|
|
85
|
+
`{ message, stack }`. Messages below the enabled threshold are skipped.
|
|
86
|
+
|
|
87
|
+
**Parameters:**
|
|
88
|
+
|
|
89
|
+
- `options?: { enabledLogLevels?: LogLevel[] }` - Levels that should be emitted; defaults to `defaultEnabledLogLevels`
|
|
90
|
+
(error, warn, success, info)
|
|
91
|
+
|
|
92
|
+
**Returns:** A logger with one method per `LogLevel` label.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { createJsonLogger } from "@leancodepl/logger/json"
|
|
96
|
+
|
|
97
|
+
const logger = createJsonLogger()
|
|
98
|
+
logger.withContext({ requestId: "req-1" }).info("request handled")
|
|
99
|
+
// {"level":"info","timestamp":"...","message":"request handled","context":{"requestId":"req-1"}}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `createNestJsonLogger()`
|
|
103
|
+
|
|
104
|
+
Creates a NestJS-compatible `LoggerService` that emits one JSON object per line to `process.stdout`. When the final
|
|
105
|
+
optional parameter is a string, it is treated as Nest's `context` argument and recorded separately; remaining params are
|
|
106
|
+
joined into the message, with `Error` values reduced to their message.
|
|
107
|
+
|
|
108
|
+
**Returns:** A logger implementing Nest's `log`/`error`/`warn`/`debug`/`verbose`/`fatal` methods.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { createNestJsonLogger } from "@leancodepl/logger/nest"
|
|
112
|
+
|
|
113
|
+
const app = await NestFactory.create(AppModule, { logger: createNestJsonLogger() })
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### `isLogLevelEnabled(logLevel, enabledLogLevels)`
|
|
117
|
+
|
|
118
|
+
Returns whether a given level is present in the list of enabled levels.
|
|
119
|
+
|
|
120
|
+
**Parameters:**
|
|
121
|
+
|
|
122
|
+
- `logLevel: LogLevel` - The level to test
|
|
123
|
+
- `enabledLogLevels: LogLevel[]` - The currently enabled levels
|
|
124
|
+
|
|
125
|
+
**Returns:** `true` when `logLevel` is enabled.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { isLogLevelEnabled, LogLevel, defaultEnabledLogLevels } from "@leancodepl/logger"
|
|
129
|
+
|
|
130
|
+
isLogLevelEnabled(LogLevel.Debug, defaultEnabledLogLevels) // false
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Exported values and types
|
|
134
|
+
|
|
135
|
+
- `LogLevel` - Severity levels enum, ordered from most to least severe (lower numeric value is more severe): `Error`
|
|
136
|
+
(0), `Warn` (1), `Success` (2), `Info` (3), `Verbose` (4), `Debug` (5).
|
|
137
|
+
- `allLogLevels: LogLevel[]` - Every `LogLevel` in severity order.
|
|
138
|
+
- `defaultEnabledLogLevels: LogLevel[]` - Levels emitted by default by the presets: error, warn, success, and info.
|
|
139
|
+
- `logLevelToLabel` - Maps each `LogLevel` to its lowercase string label.
|
|
140
|
+
- `SupportedOutput` - The value types a logger method can accept and emit: `boolean | number | object | string`.
|
|
141
|
+
- `DefaultContext` - Default shape of a logger's context: `Record<string, unknown>`.
|
|
142
|
+
- `LoggerMessage<TContext, TOutput>` - A log argument: either a plain value or a function deriving the value from
|
|
143
|
+
context.
|
|
144
|
+
- `MethodHandler<TOutput>` - Low-level handler backing a single log method; receives the resolved context as its first
|
|
145
|
+
argument.
|
|
146
|
+
- `Logger<TContext, TDefs>` - A fully built logger: its methods plus `withMiddleware` and `withContext`.
|
|
147
|
+
- `LoggerWithContext<TContext, TLogger>` - Re-derives a built logger's public shape for a given context; use it to type
|
|
148
|
+
values that hold a logger.
|
|
149
|
+
- `CliLogger`, `JsonLogger`, `NestJsonLogger` - The logger types produced by the respective preset factories.
|
|
150
|
+
- `LoggerService` - Subset of the NestJS `LoggerService` interface implemented by `createNestJsonLogger`.
|
|
151
|
+
|
|
152
|
+
## Usage Examples
|
|
153
|
+
|
|
154
|
+
### Creating a Logger
|
|
13
155
|
|
|
14
156
|
```typescript
|
|
15
157
|
import { createLogger, isContextualMessage } from "@leancodepl/logger"
|
|
@@ -23,7 +165,7 @@ const logger = createLogger({
|
|
|
23
165
|
logger.info("Hello", "world") // "Hello world"
|
|
24
166
|
```
|
|
25
167
|
|
|
26
|
-
|
|
168
|
+
### Adding Context
|
|
27
169
|
|
|
28
170
|
Use `withContext` to add context values. Context accumulates across calls.
|
|
29
171
|
|
|
@@ -32,7 +174,7 @@ const appLogger = logger.withContext({ appName: "MyApp" })
|
|
|
32
174
|
const requestLogger = appLogger.withContext({ requestId: "req-123" })
|
|
33
175
|
```
|
|
34
176
|
|
|
35
|
-
|
|
177
|
+
### Using Context in Messages
|
|
36
178
|
|
|
37
179
|
Messages can be functions that receive the current context.
|
|
38
180
|
|
|
@@ -43,7 +185,7 @@ userLogger.info(({ userId }) => `User ${userId} logged in`)
|
|
|
43
185
|
// "User user-456 logged in"
|
|
44
186
|
```
|
|
45
187
|
|
|
46
|
-
|
|
188
|
+
### Adding Middleware
|
|
47
189
|
|
|
48
190
|
Use `withMiddleware` to wrap log methods. Middleware receives `next` (it is used to call a middleware from `logger` in
|
|
49
191
|
this case) and returns a new handler.
|
|
@@ -60,7 +202,7 @@ const loggerWithPrefix = logger.withMiddleware({
|
|
|
60
202
|
loggerWithPrefix.info("test") // "[INFO] test"
|
|
61
203
|
```
|
|
62
204
|
|
|
63
|
-
|
|
205
|
+
### Modifying Context in Middleware
|
|
64
206
|
|
|
65
207
|
Middleware can modify context before passing to the next handler.
|
|
66
208
|
|
|
@@ -75,7 +217,7 @@ const loggerWithTimestamp = logger.withMiddleware({
|
|
|
75
217
|
})
|
|
76
218
|
```
|
|
77
219
|
|
|
78
|
-
|
|
220
|
+
### Chaining Middleware
|
|
79
221
|
|
|
80
222
|
Middleware is applied in order, with later middleware being executed first, and passing its changes to the middleware
|
|
81
223
|
that was created before it.
|
|
@@ -100,7 +242,7 @@ const logger2 = logger
|
|
|
100
242
|
logger2.info("test") // "[1] [2] test"
|
|
101
243
|
```
|
|
102
244
|
|
|
103
|
-
|
|
245
|
+
### Typing Functions
|
|
104
246
|
|
|
105
247
|
When passing a logger to functions, use `LoggerWithContext` for proper typing.
|
|
106
248
|
|
|
@@ -230,7 +372,8 @@ const timedLogger = logger.withMiddleware({
|
|
|
230
372
|
|
|
231
373
|
## JSON preset (`@leancodepl/logger/json`)
|
|
232
374
|
|
|
233
|
-
Logger that writes one JSON object per line to stdout (level, timestamp, msg, optional context). Same log levels and
|
|
375
|
+
Logger that writes one JSON object per line to stdout (level, timestamp, msg, optional context). Same log levels and
|
|
376
|
+
`enabledLogLevels` option as the CLI preset.
|
|
234
377
|
|
|
235
378
|
```typescript
|
|
236
379
|
import { createJsonLogger, allLogLevels, LogLevel } from "@leancodepl/logger/json"
|
|
@@ -248,7 +391,8 @@ Supports `withContext` and `withMiddleware` like the base logger.
|
|
|
248
391
|
|
|
249
392
|
## Nest preset (`@leancodepl/logger/nest`)
|
|
250
393
|
|
|
251
|
-
NestJS `LoggerService` implementation that outputs JSON (same shape as the JSON preset). Use as a drop-in logger in Nest
|
|
394
|
+
NestJS `LoggerService` implementation that outputs JSON (same shape as the JSON preset). Use as a drop-in logger in Nest
|
|
395
|
+
apps.
|
|
252
396
|
|
|
253
397
|
```typescript
|
|
254
398
|
import { createNestJsonLogger, type LoggerService } from "@leancodepl/logger/nest"
|
|
@@ -258,4 +402,5 @@ logger.log("Application started")
|
|
|
258
402
|
logger.error("Something went wrong", "MyService")
|
|
259
403
|
```
|
|
260
404
|
|
|
261
|
-
If the last argument is a string, it is used as the `context` field in the JSON output (same behavior as Nest’s built-in
|
|
405
|
+
If the last argument is a string, it is used as the `context` field in the JSON output (same behavior as Nest’s built-in
|
|
406
|
+
logger).
|
package/dist/cli.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./cliLogger-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./cliLogger-DrCrhkRC.cjs");exports.createCliLogger=e.createCliLogger;
|
package/dist/cli.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const a=require("chalk"),L=require("./logger-
|
|
1
|
+
"use strict";const a=require("chalk"),L=require("./logger-RyIBF1kr.cjs"),e=require("./logLevels-B68KoC22.cjs"),c={[e.LogLevel.Error]:a.red,[e.LogLevel.Warn]:a.yellow,[e.LogLevel.Success]:a.green,[e.LogLevel.Info]:a.blue,[e.LogLevel.Verbose]:a.gray,[e.LogLevel.Debug]:a.magenta};function t(l,s){return s.map(o=>L.isContextualMessage(o)?o(l):o)}function u(l,s){return(o,...g)=>{if(e.isLogLevelEnabled(l,s)){const r=t(o,g);switch(l){case e.LogLevel.Error:console.error(...r);break;case e.LogLevel.Warn:console.warn(...r);break;case e.LogLevel.Success:console.log(...r);break;case e.LogLevel.Info:console.info(...r);break;case e.LogLevel.Verbose:console.log(...r);break;case e.LogLevel.Debug:console.log(...r);break}}}}function b(l){return s=>(o,...g)=>{const r=c[l],n=e.logLevelToLabel[l];s(o,r(`[${n.toUpperCase()}]`),...g)}}function i({enabledLogLevels:l=e.defaultEnabledLogLevels}={}){return L.createLogger({...e.allLogLevels.reduce((o,g)=>{const r=e.logLevelToLabel[g];return o[r]=u(g,l),o},{})}).withMiddleware({...e.allLogLevels.reduce((o,g)=>{const r=e.logLevelToLabel[g];return o[r]=b(g),o},{})})}exports.createCliLogger=i;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./logger-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./logger-RyIBF1kr.cjs"),g=require("./json.cjs"),l=require("./nest.cjs"),e=require("./logLevels-B68KoC22.cjs"),r=require("./cliLogger-DrCrhkRC.cjs");exports.createLogger=o.createLogger;exports.isContextualMessage=o.isContextualMessage;exports.createJsonLogger=g.createJsonLogger;exports.createNestJsonLogger=l.createNestJsonLogger;exports.LogLevel=e.LogLevel;exports.allLogLevels=e.allLogLevels;exports.defaultEnabledLogLevels=e.defaultEnabledLogLevels;exports.isLogLevelEnabled=e.isLogLevelEnabled;exports.logLevelToLabel=e.logLevelToLabel;exports.createCliLogger=r.createCliLogger;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as a, i as r } from "./logger-
|
|
1
|
+
import { c as a, i as r } from "./logger-CFrlEist.js";
|
|
2
2
|
import { createJsonLogger as l } from "./json.js";
|
|
3
3
|
import { createNestJsonLogger as g } from "./nest.js";
|
|
4
4
|
import { L as c, a as f, d as x, i, l as m } from "./logLevels-DN78PoTJ.js";
|
|
5
|
-
import { c as p } from "./cliLogger-
|
|
5
|
+
import { c as p } from "./cliLogger-B-IrZcje.js";
|
|
6
6
|
export {
|
|
7
7
|
c as LogLevel,
|
|
8
8
|
f as allLogLevels,
|
package/dist/json.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./logger-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./logger-RyIBF1kr.cjs"),s=require("./logLevels-B68KoC22.cjs");function c(e,r){return r.map(t=>o.isContextualMessage(t)?t(e):t)}function u(e){return e instanceof Error?{message:e.message,stack:e.stack}:e}function f(e){return typeof e=="object"&&e!==null?JSON.stringify(e):String(e)}function L(e,r){const t=s.logLevelToLabel[e];return(n,...a)=>{if(!s.isLogLevelEnabled(e,r))return;const g=c(n,a).map(l=>f(u(l))).join(" "),i={level:t,timestamp:new Date().toISOString(),message:g,...Object.keys(n).length>0?{context:n}:{}};process.stdout.write(JSON.stringify(i)+`
|
|
2
2
|
`)}}function p({enabledLogLevels:e=s.defaultEnabledLogLevels}={}){return o.createLogger({...s.allLogLevels.reduce((r,t)=>{const n=s.logLevelToLabel[t];return r[n]=L(t,e),r},{})})}exports.createJsonLogger=p;
|
package/dist/json.js
CHANGED
package/dist/lib/cliLogger.d.ts
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
-
import { MethodHandler } from './logger';
|
|
1
|
+
import { MethodHandler, SupportedOutput } from './logger';
|
|
2
2
|
import { LogLevel } from './logLevels';
|
|
3
3
|
type CreateCliLoggerOptions = {
|
|
4
4
|
enabledLogLevels?: LogLevel[];
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Creates a logger preset for command-line output. Each log level maps to the
|
|
8
|
+
* matching `console` method and is prefixed with a colorized `[LEVEL]` label
|
|
9
|
+
* via middleware. Messages below the enabled threshold are skipped.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Configuration for the CLI logger
|
|
12
|
+
* @param options.enabledLogLevels - Levels that should be emitted; defaults to
|
|
13
|
+
* {@link defaultEnabledLogLevels} (error, warn, success, info)
|
|
14
|
+
* @returns A logger with one method per {@link LogLevel} label
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const logger = createCliLogger()
|
|
18
|
+
* logger.info("server started")
|
|
19
|
+
* logger.error("something failed", new Error("boom"))
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
6
22
|
declare function createCliLogger({ enabledLogLevels }?: CreateCliLoggerOptions): import('./logger').Logger<{}, {
|
|
7
|
-
error: MethodHandler<
|
|
8
|
-
warn: MethodHandler<
|
|
9
|
-
success: MethodHandler<
|
|
10
|
-
info: MethodHandler<
|
|
11
|
-
verbose: MethodHandler<
|
|
12
|
-
debug: MethodHandler<
|
|
23
|
+
error: MethodHandler<SupportedOutput>;
|
|
24
|
+
warn: MethodHandler<SupportedOutput>;
|
|
25
|
+
success: MethodHandler<SupportedOutput>;
|
|
26
|
+
info: MethodHandler<SupportedOutput>;
|
|
27
|
+
verbose: MethodHandler<SupportedOutput>;
|
|
28
|
+
debug: MethodHandler<SupportedOutput>;
|
|
13
29
|
}>;
|
|
30
|
+
/**
|
|
31
|
+
* The logger type produced by {@link createCliLogger}.
|
|
32
|
+
*/
|
|
14
33
|
type CliLogger = ReturnType<typeof createCliLogger>;
|
|
15
34
|
export { type CliLogger, createCliLogger };
|
|
16
35
|
//# sourceMappingURL=cliLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliLogger.d.ts","sourceRoot":"","sources":["../../src/lib/cliLogger.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,aAAa,
|
|
1
|
+
{"version":3,"file":"cliLogger.d.ts","sourceRoot":"","sources":["../../src/lib/cliLogger.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,aAAa,EACb,eAAe,EAChB,MAAM,UAAU,CAAA;AACjB,OAAO,EAIL,QAAQ,EAGT,MAAM,aAAa,CAAA;AAwDpB,KAAK,sBAAsB,GAAG;IAAE,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAA;AAE/D;;;;;;;;;;;;;;;GAeG;AACH,iBAAS,eAAe,CAAC,EAAE,gBAA0C,EAAE,GAAE,sBAA2B;;;;;;;GAsBnG;AAED;;GAEG;AACH,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAEnD,OAAO,EAAE,KAAK,SAAS,EAAE,eAAe,EAAE,CAAA"}
|
package/dist/lib/jsonLogger.d.ts
CHANGED
|
@@ -1,16 +1,37 @@
|
|
|
1
|
-
import { MethodHandler } from './logger';
|
|
1
|
+
import { MethodHandler, SupportedOutput } from './logger';
|
|
2
2
|
import { LogLevel } from './logLevels';
|
|
3
3
|
type CreateJsonLoggerOptions = {
|
|
4
4
|
enabledLogLevels?: LogLevel[];
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Creates a logger preset that writes one JSON object per line to
|
|
8
|
+
* `process.stdout`. Each entry includes the level label, an ISO timestamp, the
|
|
9
|
+
* joined message, and the context (when non-empty). `Error` values are
|
|
10
|
+
* serialized to `{ message, stack }`. Messages below the enabled threshold are
|
|
11
|
+
* skipped.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Configuration for the JSON logger
|
|
14
|
+
* @param options.enabledLogLevels - Levels that should be emitted; defaults to
|
|
15
|
+
* {@link defaultEnabledLogLevels} (error, warn, success, info)
|
|
16
|
+
* @returns A logger with one method per {@link LogLevel} label
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const logger = createJsonLogger()
|
|
20
|
+
* logger.withContext({ requestId: "req-1" }).info("request handled")
|
|
21
|
+
* // {"level":"info","timestamp":"...","message":"request handled","context":{"requestId":"req-1"}}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
6
24
|
declare function createJsonLogger({ enabledLogLevels }?: CreateJsonLoggerOptions): import('./logger').Logger<{}, {
|
|
7
|
-
error: MethodHandler<
|
|
8
|
-
warn: MethodHandler<
|
|
9
|
-
success: MethodHandler<
|
|
10
|
-
info: MethodHandler<
|
|
11
|
-
verbose: MethodHandler<
|
|
12
|
-
debug: MethodHandler<
|
|
25
|
+
error: MethodHandler<SupportedOutput>;
|
|
26
|
+
warn: MethodHandler<SupportedOutput>;
|
|
27
|
+
success: MethodHandler<SupportedOutput>;
|
|
28
|
+
info: MethodHandler<SupportedOutput>;
|
|
29
|
+
verbose: MethodHandler<SupportedOutput>;
|
|
30
|
+
debug: MethodHandler<SupportedOutput>;
|
|
13
31
|
}>;
|
|
32
|
+
/**
|
|
33
|
+
* The logger type produced by {@link createJsonLogger}.
|
|
34
|
+
*/
|
|
14
35
|
type JsonLogger = ReturnType<typeof createJsonLogger>;
|
|
15
36
|
export { createJsonLogger, type JsonLogger };
|
|
16
37
|
//# sourceMappingURL=jsonLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../src/lib/jsonLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,
|
|
1
|
+
{"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../src/lib/jsonLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,EACb,eAAe,EAChB,MAAM,UAAU,CAAA;AACjB,OAAO,EAIL,QAAQ,EAGT,MAAM,aAAa,CAAA;AAyCpB,KAAK,uBAAuB,GAAG;IAAE,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAA;AAEhE;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,gBAAgB,CAAC,EAAE,gBAA0C,EAAE,GAAE,uBAA4B;;;;;;;GAWrG;AAED;;GAEG;AACH,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAErD,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,CAAA"}
|
package/dist/lib/logLevels.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Severity levels supported by the loggers, ordered from most to least severe.
|
|
3
|
+
* Lower numeric values are more severe.
|
|
4
|
+
*/
|
|
1
5
|
declare enum LogLevel {
|
|
2
6
|
Error = 0,
|
|
3
7
|
Warn = 1,
|
|
@@ -6,8 +10,19 @@ declare enum LogLevel {
|
|
|
6
10
|
Verbose = 4,
|
|
7
11
|
Debug = 5
|
|
8
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Every {@link LogLevel} in severity order. Useful for building a logger method
|
|
15
|
+
* per level.
|
|
16
|
+
*/
|
|
9
17
|
declare const allLogLevels: LogLevel[];
|
|
18
|
+
/**
|
|
19
|
+
* Levels emitted by default by the logger presets: error, warn, success, and
|
|
20
|
+
* info. Verbose and debug are excluded.
|
|
21
|
+
*/
|
|
10
22
|
declare const defaultEnabledLogLevels: LogLevel[];
|
|
23
|
+
/**
|
|
24
|
+
* Maps each {@link LogLevel} to its lowercase string label.
|
|
25
|
+
*/
|
|
11
26
|
declare const logLevelToLabel: {
|
|
12
27
|
readonly 0: "error";
|
|
13
28
|
readonly 1: "warn";
|
|
@@ -16,7 +31,17 @@ declare const logLevelToLabel: {
|
|
|
16
31
|
readonly 4: "verbose";
|
|
17
32
|
readonly 5: "debug";
|
|
18
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Union of the lowercase string labels for every {@link LogLevel}.
|
|
36
|
+
*/
|
|
19
37
|
type LogLevelLabel = (typeof logLevelToLabel)[keyof typeof logLevelToLabel];
|
|
38
|
+
/**
|
|
39
|
+
* Returns whether a given level is present in the list of enabled levels.
|
|
40
|
+
*
|
|
41
|
+
* @param logLevel - The level to test
|
|
42
|
+
* @param enabledLogLevels - The currently enabled levels
|
|
43
|
+
* @returns `true` when `logLevel` is enabled
|
|
44
|
+
*/
|
|
20
45
|
declare function isLogLevelEnabled(logLevel: LogLevel, enabledLogLevels: LogLevel[]): boolean;
|
|
21
46
|
export { allLogLevels, defaultEnabledLogLevels, isLogLevelEnabled, LogLevel, logLevelToLabel };
|
|
22
47
|
export type { LogLevelLabel };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logLevels.d.ts","sourceRoot":"","sources":["../../src/lib/logLevels.ts"],"names":[],"mappings":"AAAA,aAAK,QAAQ;IACX,KAAK,IAAI;IACT,IAAI,IAAI;IACR,OAAO,IAAI;IACX,IAAI,IAAI;IACR,OAAO,IAAI;IACX,KAAK,IAAI;CACV;AAED,QAAA,MAAM,YAAY,YAAqG,CAAA;AAEvH,QAAA,MAAM,uBAAuB,YAAmE,CAAA;AAEhG,QAAA,MAAM,eAAe;;;;;;;CAOX,CAAA;AAEV,KAAK,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAA;AAE3E,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,EAAE,WAE1E;AAED,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;AAC9F,YAAY,EAAE,aAAa,EAAE,CAAA"}
|
|
1
|
+
{"version":3,"file":"logLevels.d.ts","sourceRoot":"","sources":["../../src/lib/logLevels.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,aAAK,QAAQ;IACX,KAAK,IAAI;IACT,IAAI,IAAI;IACR,OAAO,IAAI;IACX,IAAI,IAAI;IACR,OAAO,IAAI;IACX,KAAK,IAAI;CACV;AAED;;;GAGG;AACH,QAAA,MAAM,YAAY,YAAqG,CAAA;AAEvH;;;GAGG;AACH,QAAA,MAAM,uBAAuB,YAAmE,CAAA;AAEhG;;GAEG;AACH,QAAA,MAAM,eAAe;;;;;;;CAOX,CAAA;AAEV;;GAEG;AACH,KAAK,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAA;AAE3E;;;;;;GAMG;AACH,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,EAAE,WAE1E;AAED,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;AAC9F,YAAY,EAAE,aAAa,EAAE,CAAA"}
|
package/dist/lib/logger.d.ts
CHANGED
|
@@ -1,26 +1,108 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The set of value types a logger method can accept and emit.
|
|
3
|
+
*
|
|
4
|
+
* The `unknown` member was intentionally dropped: a union containing `unknown`
|
|
5
|
+
* collapses to `unknown`, which silently widened every output type and defeated
|
|
6
|
+
* the generic inference the logger relies on. The remaining members cover every
|
|
7
|
+
* value the built-in loggers produce (strings, numbers, booleans, and arbitrary
|
|
8
|
+
* objects — including serialized `Error`s).
|
|
9
|
+
*/
|
|
10
|
+
type SupportedOutput = boolean | number | object | string;
|
|
11
|
+
/**
|
|
12
|
+
* Default shape of the contextual data carried by a logger. Any object keyed by
|
|
13
|
+
* string is accepted; richer context types narrow this via the generic
|
|
14
|
+
* parameters on {@link Logger} and {@link createLogger}.
|
|
15
|
+
*/
|
|
2
16
|
type DefaultContext = Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* A message that is computed lazily from the logger's current context. Receives
|
|
19
|
+
* the context and returns the value to log, so the value can depend on whatever
|
|
20
|
+
* context was attached via {@link Logger.withContext}.
|
|
21
|
+
*
|
|
22
|
+
* @template TContext - The context shape passed to the message factory
|
|
23
|
+
* @template TOutput - The value type the factory produces
|
|
24
|
+
*/
|
|
3
25
|
type ContextualLoggerMessage<TContext extends DefaultContext, TOutput = SupportedOutput> = (context: TContext) => TOutput;
|
|
26
|
+
/**
|
|
27
|
+
* A single argument accepted by a log method: either a plain value to log or a
|
|
28
|
+
* {@link ContextualLoggerMessage} that derives the value from the context.
|
|
29
|
+
*
|
|
30
|
+
* @template TContext - The context shape available to contextual messages
|
|
31
|
+
* @template TOutput - The value type produced
|
|
32
|
+
*/
|
|
4
33
|
type LoggerMessage<TContext extends DefaultContext = DefaultContext, TOutput extends SupportedOutput = string> = ContextualLoggerMessage<TContext, TOutput> | TOutput;
|
|
34
|
+
/**
|
|
35
|
+
* Call signature of a log method on a built logger. Accepts any number of
|
|
36
|
+
* messages (plain or contextual) and returns nothing.
|
|
37
|
+
*
|
|
38
|
+
* @template TContext - The context shape available to contextual messages
|
|
39
|
+
* @template TOutput - The value type each message produces
|
|
40
|
+
*/
|
|
5
41
|
interface LogMethod<TContext extends DefaultContext = DefaultContext, TOutput extends SupportedOutput = string> {
|
|
6
42
|
(...messages: LoggerMessage<TContext, TOutput>[]): void;
|
|
7
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Low-level handler backing a single log method. Unlike {@link LogMethod}, it
|
|
46
|
+
* receives the resolved context explicitly as its first argument, which is what
|
|
47
|
+
* lets middleware wrap and transform it.
|
|
48
|
+
*
|
|
49
|
+
* @template TOutput - The value type each message produces
|
|
50
|
+
*/
|
|
8
51
|
type MethodHandler<TOutput extends SupportedOutput = string> = (context: DefaultContext, ...messages: LoggerMessage<DefaultContext, TOutput>[]) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Map of method name to {@link MethodHandler}. This is the definition object
|
|
54
|
+
* passed to {@link createLogger} to describe the methods a logger exposes.
|
|
55
|
+
*
|
|
56
|
+
* @template TOutput - The value type each handler produces
|
|
57
|
+
*/
|
|
9
58
|
type MethodDefinitions<TOutput extends SupportedOutput = string> = Record<string, MethodHandler<TOutput>>;
|
|
10
59
|
type MethodsFromDefinitions<TContext extends DefaultContext, TDefs extends MethodDefinitions<SupportedOutput>> = {
|
|
11
60
|
[K in keyof TDefs]: TDefs[K] extends MethodHandler<infer TOutput> ? LogMethod<TContext, TOutput> : never;
|
|
12
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* A middleware wrapping a {@link MethodHandler}. Given the next handler in the
|
|
64
|
+
* chain, it returns a new handler, allowing it to transform the context or
|
|
65
|
+
* messages before (or after) delegating to `next`.
|
|
66
|
+
*
|
|
67
|
+
* @template TOutput - The value type the wrapped handler produces
|
|
68
|
+
*/
|
|
13
69
|
type Middleware<TOutput extends SupportedOutput = string> = (next: MethodHandler<TOutput>) => MethodHandler<TOutput>;
|
|
14
70
|
type MiddlewaresFor<TDefs extends MethodDefinitions<SupportedOutput>> = {
|
|
15
71
|
[K in keyof TDefs]?: TDefs[K] extends MethodHandler<infer TOutput> ? Middleware<TOutput> : never;
|
|
16
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* A fully built logger: every method from its definitions plus the
|
|
75
|
+
* {@link Logger.withMiddleware} and {@link Logger.withContext} combinators for
|
|
76
|
+
* deriving new loggers.
|
|
77
|
+
*
|
|
78
|
+
* @template TContext - The context shape carried by this logger
|
|
79
|
+
* @template TDefs - The method definitions backing this logger
|
|
80
|
+
*/
|
|
17
81
|
type Logger<TContext extends DefaultContext, TDefs extends MethodDefinitions<SupportedOutput>> = MethodsFromDefinitions<TContext, TDefs> & {
|
|
82
|
+
/**
|
|
83
|
+
* Returns a new logger whose listed methods are wrapped by the given
|
|
84
|
+
* middleware. Methods not listed are left untouched, and the original logger
|
|
85
|
+
* is not modified.
|
|
86
|
+
*/
|
|
18
87
|
withMiddleware: (middlewares: MiddlewaresFor<TDefs>) => Logger<TContext, TDefs>;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a new logger with `context` merged into the existing context. The
|
|
90
|
+
* original logger is not modified, so derived loggers can be created freely.
|
|
91
|
+
*/
|
|
19
92
|
withContext: <TNewContext extends DefaultContext>(context: TNewContext) => Logger<TContext & TNewContext, TDefs>;
|
|
20
93
|
};
|
|
21
94
|
type ExtractMethodDefs<T> = {
|
|
22
95
|
[K in keyof T as K extends "withContext" | "withMiddleware" ? never : T[K] extends LogMethod<DefaultContext, SupportedOutput> ? K : never]: T[K] extends LogMethod<DefaultContext, infer TOutput> ? MethodHandler<TOutput> : never;
|
|
23
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Re-derives a logger's public shape for a given context from the logger type
|
|
99
|
+
* itself (rather than from its method definitions). Useful for typing values
|
|
100
|
+
* that hold an already-built logger while preserving its method signatures and
|
|
101
|
+
* the {@link Logger.withMiddleware} / {@link Logger.withContext} combinators.
|
|
102
|
+
*
|
|
103
|
+
* @template TContext - The context shape to expose
|
|
104
|
+
* @template TLogger - The source logger type to extract methods from
|
|
105
|
+
*/
|
|
24
106
|
type LoggerWithContext<TContext extends DefaultContext, TLogger> = {
|
|
25
107
|
[K in keyof ExtractMethodDefs<TLogger>]: ExtractMethodDefs<TLogger>[K] extends MethodHandler<infer TOutput> ? LogMethod<TContext, TOutput> : never;
|
|
26
108
|
} & {
|
|
@@ -29,7 +111,38 @@ type LoggerWithContext<TContext extends DefaultContext, TLogger> = {
|
|
|
29
111
|
}) => LoggerWithContext<TContext, TLogger>;
|
|
30
112
|
withContext: <TNewContext extends DefaultContext>(context: TNewContext) => LoggerWithContext<TContext & TNewContext, TLogger>;
|
|
31
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Type guard that narrows a {@link LoggerMessage} to a
|
|
116
|
+
* {@link ContextualLoggerMessage}. Used by logger implementations to decide
|
|
117
|
+
* whether a message must be invoked with the context or logged as-is.
|
|
118
|
+
*
|
|
119
|
+
* @template TContext - The context shape available to contextual messages
|
|
120
|
+
* @template TOutput - The value type produced
|
|
121
|
+
* @param message - The message to inspect
|
|
122
|
+
* @returns `true` when the message is a context-consuming function
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const resolved = isContextualMessage(message) ? message(context) : message
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
32
128
|
declare function isContextualMessage<TContext extends DefaultContext, TOutput extends SupportedOutput>(message: LoggerMessage<TContext, TOutput>): message is ContextualLoggerMessage<TContext, TOutput>;
|
|
129
|
+
/**
|
|
130
|
+
* Creates a logger from a map of method definitions. Each definition becomes a
|
|
131
|
+
* callable method on the returned logger, and the logger starts with an empty
|
|
132
|
+
* context that can be extended via {@link Logger.withContext}.
|
|
133
|
+
*
|
|
134
|
+
* @template TDefs - The method definitions backing the logger
|
|
135
|
+
* @param methods - Map of method name to its {@link MethodHandler}
|
|
136
|
+
* @returns A logger exposing the defined methods plus `withContext` and `withMiddleware`
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const logger = createLogger({
|
|
140
|
+
* info: (context, ...messages) => console.info(...messages),
|
|
141
|
+
* })
|
|
142
|
+
*
|
|
143
|
+
* logger.withContext({ requestId: "req-1" }).info("started")
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
33
146
|
declare function createLogger<TDefs extends MethodDefinitions<SupportedOutput>>(methods: TDefs): Logger<{}, TDefs>;
|
|
34
147
|
export { createLogger, isContextualMessage };
|
|
35
148
|
export type { DefaultContext, Logger, LoggerMessage, LoggerWithContext, MethodHandler, SupportedOutput };
|
package/dist/lib/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"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"}
|
package/dist/lib/nestLogger.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subset of the NestJS `LoggerService` interface implemented by
|
|
3
|
+
* {@link createNestJsonLogger}. Mirrors Nest's expected logger contract so the
|
|
4
|
+
* JSON logger can be passed directly to a Nest application.
|
|
5
|
+
*/
|
|
1
6
|
export interface LoggerService {
|
|
2
7
|
log(message: any, ...optionalParams: any[]): any;
|
|
3
8
|
error(message: any, ...optionalParams: any[]): any;
|
|
@@ -7,7 +12,23 @@ export interface LoggerService {
|
|
|
7
12
|
fatal?(message: any, ...optionalParams: any[]): any;
|
|
8
13
|
setLogLevels?(levels: any[]): any;
|
|
9
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a NestJS-compatible {@link LoggerService} that emits one JSON object
|
|
17
|
+
* per line to `process.stdout`. When the final optional parameter is a string,
|
|
18
|
+
* it is treated as Nest's `context` argument and recorded separately; remaining
|
|
19
|
+
* params are joined into the message, with `Error` values reduced to their
|
|
20
|
+
* message.
|
|
21
|
+
*
|
|
22
|
+
* @returns A logger implementing Nest's `log`/`error`/`warn`/`debug`/`verbose`/`fatal` methods
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const app = await NestFactory.create(AppModule, { logger: createNestJsonLogger() })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
10
28
|
declare function createNestJsonLogger(): LoggerService;
|
|
29
|
+
/**
|
|
30
|
+
* The logger type produced by {@link createNestJsonLogger}.
|
|
31
|
+
*/
|
|
11
32
|
type NestJsonLogger = ReturnType<typeof createNestJsonLogger>;
|
|
12
33
|
export { createNestJsonLogger, type NestJsonLogger };
|
|
13
34
|
//# sourceMappingURL=nestLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nestLogger.d.ts","sourceRoot":"","sources":["../../src/lib/nestLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nestLogger.d.ts","sourceRoot":"","sources":["../../src/lib/nestLogger.ts"],"names":[],"mappings":"AA2CA;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IAChD,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IAClD,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IACjD,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IACnD,OAAO,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IACrD,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IACnD,YAAY,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,iBAAS,oBAAoB,IAAI,aAAa,CA8B7C;AAED;;GAEG;AACH,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAE7D,OAAO,EAAE,oBAAoB,EAAE,KAAK,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function f(e){return typeof e=="function"}function g(e){return u({},e)}function u(e,a){const n={...a},r={};for(const t of Object.keys(n))Object.defineProperty(r,t,{value:(...o)=>{n[t]?.(e,...o)},enumerable:!0,configurable:!0});return r.withMiddleware=t=>{const o={...n};for(const s of Object.keys(t)){const c=t[s],i=n[s];c&&i&&(o[s]=c(i))}return u(e,o)},r.withContext=t=>u({...e,...t},n),r}exports.createLogger=g;exports.isContextualMessage=f;
|
package/dist/nest.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`)}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./logger-RyIBF1kr.cjs");function n(r){return r}function f(r,t){return[r,...t].map(o=>o instanceof Error?o.message:typeof o=="object"&&o!==null?JSON.stringify(o):String(o)).join(" ")}function m(r,t,e){const o=e.at(-1),a=typeof o=="string"?o:void 0,g=a!==void 0?e.slice(0,-1):e,i=f(t,g),c={level:r,timestamp:new Date().toISOString(),message:i,...a!==void 0?{context:a}:{}};process.stdout.write(JSON.stringify(c)+`
|
|
2
|
+
`)}function s(r){return(t,...e)=>{const[o="",...a]=e;m(r,o,a)}}function l(){const r=u.createLogger({log:s("info"),error:s("error"),warn:s("warn"),debug:s("debug"),verbose:s("verbose"),fatal:s("fatal")});return{log(t,...e){r.log(t,...e.map(n))},error(t,...e){r.error(t,...e.map(n))},warn(t,...e){r.warn(t,...e.map(n))},debug(t,...e){r.debug(t,...e.map(n))},verbose(t,...e){r.verbose(t,...e.map(n))},fatal(t,...e){r.fatal(t,...e.map(n))}}}exports.createNestJsonLogger=l;
|
package/dist/nest.js
CHANGED
|
@@ -1,53 +1,56 @@
|
|
|
1
|
-
import { c } from "./logger-
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
import { c as u } from "./logger-CFrlEist.js";
|
|
2
|
+
function o(r) {
|
|
3
|
+
return r;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function f(r, e) {
|
|
6
|
+
return [r, ...e].map((n) => n instanceof Error ? n.message : typeof n == "object" && n !== null ? JSON.stringify(n) : String(n)).join(" ");
|
|
7
|
+
}
|
|
8
|
+
function m(r, e, t) {
|
|
9
|
+
const n = t.at(-1), a = typeof n == "string" ? n : void 0, g = a !== void 0 ? t.slice(0, -1) : t, i = f(e, g), c = {
|
|
10
|
+
level: r,
|
|
8
11
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9
|
-
message:
|
|
10
|
-
...
|
|
12
|
+
message: i,
|
|
13
|
+
...a !== void 0 ? { context: a } : {}
|
|
11
14
|
};
|
|
12
|
-
process.stdout.write(JSON.stringify(
|
|
15
|
+
process.stdout.write(JSON.stringify(c) + `
|
|
13
16
|
`);
|
|
14
17
|
}
|
|
15
|
-
function
|
|
16
|
-
return (
|
|
17
|
-
const [
|
|
18
|
-
|
|
18
|
+
function s(r) {
|
|
19
|
+
return (e, ...t) => {
|
|
20
|
+
const [n = "", ...a] = t;
|
|
21
|
+
m(r, n, a);
|
|
19
22
|
};
|
|
20
23
|
}
|
|
21
|
-
function
|
|
22
|
-
const
|
|
23
|
-
log:
|
|
24
|
-
error:
|
|
25
|
-
warn:
|
|
26
|
-
debug:
|
|
27
|
-
verbose:
|
|
28
|
-
fatal:
|
|
24
|
+
function l() {
|
|
25
|
+
const r = u({
|
|
26
|
+
log: s("info"),
|
|
27
|
+
error: s("error"),
|
|
28
|
+
warn: s("warn"),
|
|
29
|
+
debug: s("debug"),
|
|
30
|
+
verbose: s("verbose"),
|
|
31
|
+
fatal: s("fatal")
|
|
29
32
|
});
|
|
30
33
|
return {
|
|
31
|
-
log(
|
|
32
|
-
|
|
34
|
+
log(e, ...t) {
|
|
35
|
+
r.log(e, ...t.map(o));
|
|
33
36
|
},
|
|
34
|
-
error(
|
|
35
|
-
|
|
37
|
+
error(e, ...t) {
|
|
38
|
+
r.error(e, ...t.map(o));
|
|
36
39
|
},
|
|
37
|
-
warn(
|
|
38
|
-
|
|
40
|
+
warn(e, ...t) {
|
|
41
|
+
r.warn(e, ...t.map(o));
|
|
39
42
|
},
|
|
40
|
-
debug(
|
|
41
|
-
|
|
43
|
+
debug(e, ...t) {
|
|
44
|
+
r.debug(e, ...t.map(o));
|
|
42
45
|
},
|
|
43
|
-
verbose(
|
|
44
|
-
|
|
46
|
+
verbose(e, ...t) {
|
|
47
|
+
r.verbose(e, ...t.map(o));
|
|
45
48
|
},
|
|
46
|
-
fatal(
|
|
47
|
-
|
|
49
|
+
fatal(e, ...t) {
|
|
50
|
+
r.fatal(e, ...t.map(o));
|
|
48
51
|
}
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
export {
|
|
52
|
-
|
|
55
|
+
l as createNestJsonLogger
|
|
53
56
|
};
|
package/package.json
CHANGED
package/dist/logger-CSPbXuiG.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function f(e){return typeof e=="function"}function g(e){return u({},e)}function u(e,a){const n={...a},r={};for(const t of Object.keys(n))Object.defineProperty(r,t,{value:(...o)=>{n[t](e,...o)},enumerable:!0,configurable:!0});return r.withMiddleware=t=>{const o={...n};for(const s of Object.keys(t)){const c=t[s],i=n[s];c&&i&&(o[s]=c(i))}return u(e,o)},r.withContext=t=>u({...e,...t},n),r}exports.createLogger=g;exports.isContextualMessage=f;
|