@warlock.js/logger 4.0.174 → 4.1.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.
- package/README.md +145 -422
- package/cjs/index.cjs +1003 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/channels/console-log.d.mts +40 -0
- package/esm/channels/console-log.d.mts.map +1 -0
- package/esm/channels/console-log.mjs +51 -0
- package/esm/channels/console-log.mjs.map +1 -0
- package/esm/channels/file-log.d.mts +194 -0
- package/esm/channels/file-log.d.mts.map +1 -0
- package/esm/channels/file-log.mjs +267 -0
- package/esm/channels/file-log.mjs.map +1 -0
- package/esm/channels/index.mjs +5 -0
- package/esm/channels/json-file-log.d.mts +33 -0
- package/esm/channels/json-file-log.d.mts.map +1 -0
- package/esm/channels/json-file-log.mjs +137 -0
- package/esm/channels/json-file-log.mjs.map +1 -0
- package/esm/index.d.mts +11 -0
- package/esm/index.mjs +13 -0
- package/esm/log-channel.d.mts +78 -0
- package/esm/log-channel.d.mts.map +1 -0
- package/esm/log-channel.mjs +75 -0
- package/esm/log-channel.mjs.map +1 -0
- package/esm/logger.d.mts +184 -0
- package/esm/logger.d.mts.map +1 -0
- package/esm/logger.mjs +282 -0
- package/esm/logger.mjs.map +1 -0
- package/esm/redact/redact.d.mts +25 -0
- package/esm/redact/redact.d.mts.map +1 -0
- package/esm/redact/redact.mjs +109 -0
- package/esm/redact/redact.mjs.map +1 -0
- package/esm/types.d.mts +129 -0
- package/esm/types.d.mts.map +1 -0
- package/esm/utils/capture-unhandled-errors.d.mts +16 -0
- package/esm/utils/capture-unhandled-errors.d.mts.map +1 -0
- package/esm/utils/capture-unhandled-errors.mjs +26 -0
- package/esm/utils/capture-unhandled-errors.mjs.map +1 -0
- package/esm/utils/clear-message.d.mts +8 -0
- package/esm/utils/clear-message.d.mts.map +1 -0
- package/esm/utils/clear-message.mjs +12 -0
- package/esm/utils/clear-message.mjs.map +1 -0
- package/esm/utils/index.mjs +5 -0
- package/esm/utils/safe-json-stringify.d.mts +14 -0
- package/esm/utils/safe-json-stringify.d.mts.map +1 -0
- package/esm/utils/safe-json-stringify.mjs +35 -0
- package/esm/utils/safe-json-stringify.mjs.map +1 -0
- package/llms-full.txt +1296 -0
- package/llms.txt +19 -0
- package/package.json +39 -39
- package/skills/capture-unhandled-errors/SKILL.md +103 -0
- package/skills/configure-logger/SKILL.md +105 -0
- package/skills/filter-log-entries/SKILL.md +120 -0
- package/skills/flush-logs-on-shutdown/SKILL.md +91 -0
- package/skills/logger-basics/SKILL.md +85 -0
- package/skills/overview/SKILL.md +86 -0
- package/skills/pick-log-channel/SKILL.md +139 -0
- package/skills/redact-sensitive-log-fields/SKILL.md +122 -0
- package/skills/test-logging-code/SKILL.md +169 -0
- package/skills/use-log-helpers/SKILL.md +66 -0
- package/skills/write-custom-log-channel/SKILL.md +160 -0
- package/cjs/channels/console-log.d.ts +0 -17
- package/cjs/channels/console-log.d.ts.map +0 -1
- package/cjs/channels/console-log.js +0 -47
- package/cjs/channels/console-log.js.map +0 -1
- package/cjs/channels/file-log.d.ts +0 -171
- package/cjs/channels/file-log.d.ts.map +0 -1
- package/cjs/channels/file-log.js +0 -293
- package/cjs/channels/file-log.js.map +0 -1
- package/cjs/channels/index.d.ts +0 -4
- package/cjs/channels/index.d.ts.map +0 -1
- package/cjs/channels/json-file-log.d.ts +0 -33
- package/cjs/channels/json-file-log.d.ts.map +0 -1
- package/cjs/channels/json-file-log.js +0 -164
- package/cjs/channels/json-file-log.js.map +0 -1
- package/cjs/index.d.ts +0 -6
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/log-channel.d.ts +0 -67
- package/cjs/log-channel.d.ts.map +0 -1
- package/cjs/log-channel.js +0 -88
- package/cjs/log-channel.js.map +0 -1
- package/cjs/logger.d.ts +0 -62
- package/cjs/logger.d.ts.map +0 -1
- package/cjs/logger.js +0 -124
- package/cjs/logger.js.map +0 -1
- package/cjs/types.d.ts +0 -104
- package/cjs/types.d.ts.map +0 -1
- package/cjs/utils/capture-unhandled-errors.d.ts +0 -2
- package/cjs/utils/capture-unhandled-errors.d.ts.map +0 -1
- package/cjs/utils/capture-unhandled-errors.js +0 -12
- package/cjs/utils/capture-unhandled-errors.js.map +0 -1
- package/cjs/utils/clear-message.d.ts +0 -5
- package/cjs/utils/clear-message.d.ts.map +0 -1
- package/cjs/utils/clear-message.js +0 -9
- package/cjs/utils/clear-message.js.map +0 -1
- package/cjs/utils/index.d.ts +0 -3
- package/cjs/utils/index.d.ts.map +0 -1
- package/esm/channels/console-log.d.ts +0 -17
- package/esm/channels/console-log.d.ts.map +0 -1
- package/esm/channels/console-log.js +0 -47
- package/esm/channels/console-log.js.map +0 -1
- package/esm/channels/file-log.d.ts +0 -171
- package/esm/channels/file-log.d.ts.map +0 -1
- package/esm/channels/file-log.js +0 -293
- package/esm/channels/file-log.js.map +0 -1
- package/esm/channels/index.d.ts +0 -4
- package/esm/channels/index.d.ts.map +0 -1
- package/esm/channels/json-file-log.d.ts +0 -33
- package/esm/channels/json-file-log.d.ts.map +0 -1
- package/esm/channels/json-file-log.js +0 -164
- package/esm/channels/json-file-log.js.map +0 -1
- package/esm/index.d.ts +0 -6
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +0 -1
- package/esm/log-channel.d.ts +0 -67
- package/esm/log-channel.d.ts.map +0 -1
- package/esm/log-channel.js +0 -88
- package/esm/log-channel.js.map +0 -1
- package/esm/logger.d.ts +0 -62
- package/esm/logger.d.ts.map +0 -1
- package/esm/logger.js +0 -124
- package/esm/logger.js.map +0 -1
- package/esm/types.d.ts +0 -104
- package/esm/types.d.ts.map +0 -1
- package/esm/utils/capture-unhandled-errors.d.ts +0 -2
- package/esm/utils/capture-unhandled-errors.d.ts.map +0 -1
- package/esm/utils/capture-unhandled-errors.js +0 -12
- package/esm/utils/capture-unhandled-errors.js.map +0 -1
- package/esm/utils/clear-message.d.ts +0 -5
- package/esm/utils/clear-message.d.ts.map +0 -1
- package/esm/utils/clear-message.js +0 -9
- package/esm/utils/clear-message.js.map +0 -1
- package/esm/utils/index.d.ts +0 -3
- package/esm/utils/index.d.ts.map +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: write-custom-log-channel
|
|
3
|
+
description: 'Extend the abstract LogChannel class for custom sinks — Slack, database, HTTP endpoint, in-memory buffer. Triggers: `LogChannel`, `LogContract`, `LoggingData`, `shouldBeLogged`, `init`, `flushSync`, `terminal`; "log to slack", "log to a database", "send logs to datadog / loki HTTP api", "in-memory test capture channel", "build a custom log sink"; typical import `import { LogChannel, type LoggingData, type LogContract } from "@warlock.js/logger"`. Skip: built-in channels — `@warlock.js/logger/pick-log-channel/SKILL.md`; filtering — `@warlock.js/logger/filter-log-entries/SKILL.md`; competing libs `winston-transport`, `pino-transport`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Custom channels — extending `LogChannel`
|
|
7
|
+
|
|
8
|
+
Build a sink for any destination — Slack, a database, an HTTP endpoint — by extending the abstract `LogChannel` class.
|
|
9
|
+
|
|
10
|
+
## The 5-line minimum
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { LogChannel, type LoggingData } from "@warlock.js/logger";
|
|
14
|
+
|
|
15
|
+
export class NullChannel extends LogChannel {
|
|
16
|
+
public name = "null";
|
|
17
|
+
public log(_data: LoggingData) {}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then:
|
|
22
|
+
```ts
|
|
23
|
+
log.addChannel(new NullChannel());
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
That's a working channel. `LogChannel` provides the scaffolding; you only need to supply `name` and `log()`.
|
|
27
|
+
|
|
28
|
+
## What `LogChannel` gives you
|
|
29
|
+
|
|
30
|
+
| Thing | Who provides it |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `name`, `description`, `terminal` | You (fields on your subclass) |
|
|
33
|
+
| `log(data)` | **You must implement** — abstract |
|
|
34
|
+
| `flushSync()` | You (optional — only if you buffer) |
|
|
35
|
+
| `init()` | You (optional async hook — see below) |
|
|
36
|
+
| `shouldBeLogged(data)` | `LogChannel` — combines `levels` + `filter` |
|
|
37
|
+
| `config<K>(key)` | `LogChannel` — merges user config with `defaultConfigurations` |
|
|
38
|
+
| `getDateAndTimeFormat()` | `LogChannel` — returns resolved `dateFormat` |
|
|
39
|
+
|
|
40
|
+
## Complete example — SlackLog
|
|
41
|
+
|
|
42
|
+
```ts title="src/channels/slack-log.ts"
|
|
43
|
+
import { LogChannel, type BasicLogConfigurations, type LoggingData } from "@warlock.js/logger";
|
|
44
|
+
|
|
45
|
+
// `LogChannel<Options>` constrains `Options extends BasicLogConfigurations`,
|
|
46
|
+
// so extend the base to keep the inherited levels / filter / redact options.
|
|
47
|
+
type SlackConfig = BasicLogConfigurations & {
|
|
48
|
+
webhookUrl: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export class SlackLog extends LogChannel<SlackConfig> {
|
|
52
|
+
public name = "slack";
|
|
53
|
+
public description = "Posts errors + warnings to a Slack webhook";
|
|
54
|
+
|
|
55
|
+
public async log(data: LoggingData) {
|
|
56
|
+
if (!this.shouldBeLogged(data)) return; // ← inherit levels + filter
|
|
57
|
+
|
|
58
|
+
await fetch(this.config("webhookUrl"), {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: { "Content-Type": "application/json" },
|
|
61
|
+
body: JSON.stringify({
|
|
62
|
+
text: `[${data.type.toUpperCase()}] [${data.module}][${data.action}]: ${data.message}`,
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Register it alongside built-ins:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
log.setChannels([
|
|
73
|
+
new ConsoleLog(),
|
|
74
|
+
new FileLog({ chunk: "daily" }),
|
|
75
|
+
new SlackLog({
|
|
76
|
+
webhookUrl: process.env.SLACK_WEBHOOK_URL!,
|
|
77
|
+
levels: ["error", "warn"],
|
|
78
|
+
}),
|
|
79
|
+
]);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## The `init()` hook
|
|
83
|
+
|
|
84
|
+
Override `protected async init()` for one-time setup — open a socket, connect to a DB, prepare a write stream. Runs automatically after construction (inside a `setTimeout(0)`); `isInitialized` flips to `true` once resolved.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
export class DatabaseLog extends LogChannel<
|
|
88
|
+
BasicLogConfigurations & { connectionString: string }
|
|
89
|
+
> {
|
|
90
|
+
public name = "database";
|
|
91
|
+
private client!: SomeDbClient;
|
|
92
|
+
|
|
93
|
+
protected async init() {
|
|
94
|
+
this.client = await SomeDbClient.connect(this.config("connectionString"));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public async log(data: LoggingData) {
|
|
98
|
+
if (!this.shouldBeLogged(data)) return;
|
|
99
|
+
await this.client.insert("logs", data);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Implementing `flushSync()`
|
|
105
|
+
|
|
106
|
+
Only if your channel buffers. Signature: `flushSync?(): void`. Synchronous — no `await`, no promises.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
export class BatchHttpLog extends LogChannel<BasicLogConfigurations & { url: string }> {
|
|
110
|
+
public name = "batch-http";
|
|
111
|
+
private buffer: LoggingData[] = [];
|
|
112
|
+
|
|
113
|
+
public log(data: LoggingData) {
|
|
114
|
+
if (!this.shouldBeLogged(data)) return;
|
|
115
|
+
this.buffer.push(data);
|
|
116
|
+
if (this.buffer.length >= 100) void this.drain();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public flushSync() {
|
|
120
|
+
// Synchronous HTTP — use `node:http` or `XMLHttpRequest` polyfill.
|
|
121
|
+
// If sync HTTP isn't possible, at least dump the buffer to disk here
|
|
122
|
+
// so a follow-up async drain can recover it next boot.
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private async drain() { /* async post to this.config("url") */ }
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## The `terminal` property
|
|
130
|
+
|
|
131
|
+
- `terminal = true` (ConsoleLog default) → the logger passes the **original** message, ANSI codes intact.
|
|
132
|
+
- `terminal = false` (base default, all file channels) → the logger passes a shallow-cloned copy whose `message` has ANSI codes stripped.
|
|
133
|
+
|
|
134
|
+
Set `terminal = true` on a channel only if its output is a TTY that should render colors.
|
|
135
|
+
|
|
136
|
+
## `LogContract` — the minimal interface
|
|
137
|
+
|
|
138
|
+
If you don't want anything `LogChannel` provides (level filtering, config merging), implement `LogContract` directly:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import type { LogContract, LoggingData } from "@warlock.js/logger";
|
|
142
|
+
|
|
143
|
+
class MinimalSlack implements LogContract {
|
|
144
|
+
public name = "slack";
|
|
145
|
+
|
|
146
|
+
public async log(data: LoggingData) {
|
|
147
|
+
if (data.type !== "error") return;
|
|
148
|
+
await fetch(process.env.SLACK_WEBHOOK!, { /* ... */ });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Prefer extending `LogChannel` unless you have a concrete reason not to — the level/filter plumbing is worth keeping.
|
|
154
|
+
|
|
155
|
+
## Don't do
|
|
156
|
+
|
|
157
|
+
- Don't mutate `data` inside `log()`. Later channels see the mutation if the logger passes the same reference.
|
|
158
|
+
- Don't throw synchronously from `log()`. The logger fires it without awaiting; an unhandled rejection takes down the process (unless `captureAnyUnhandledRejection` is wired up — and then it's embarrassing to be the cause).
|
|
159
|
+
- Don't block the event loop. `log()` may be sync or async; if your work takes >100ms, make it async and return the promise.
|
|
160
|
+
- Don't forget `shouldBeLogged(data)` at the top of `log()` — or your channel silently ignores `levels` / `filter` config.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { LogChannel } from "../log-channel";
|
|
2
|
-
import type { BasicLogConfigurations, LoggingData } from "../types";
|
|
3
|
-
export declare class ConsoleLog extends LogChannel<BasicLogConfigurations> {
|
|
4
|
-
/**
|
|
5
|
-
* {@inheritdoc}
|
|
6
|
-
*/
|
|
7
|
-
name: string;
|
|
8
|
-
/**
|
|
9
|
-
* Determine if channel is logging in terminal
|
|
10
|
-
*/
|
|
11
|
-
terminal: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* {@inheritdoc}
|
|
14
|
-
*/
|
|
15
|
-
log(data: LoggingData): void;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=console-log.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"console-log.d.ts","sourceRoot":"","sources":["../../src/channels/console-log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEpE,qBAAa,UAAW,SAAQ,UAAU,CAAC,sBAAsB,CAAC;IAChE;;OAEG;IACI,IAAI,SAAa;IAExB;;OAEG;IACI,QAAQ,UAAQ;IAEvB;;OAEG;IACI,GAAG,CAAC,IAAI,EAAE,WAAW;CA0E7B"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use strict';var copper=require('@mongez/copper'),logChannel=require('../log-channel.js');class ConsoleLog extends logChannel.LogChannel {
|
|
2
|
-
/**
|
|
3
|
-
* {@inheritdoc}
|
|
4
|
-
*/
|
|
5
|
-
name = "console";
|
|
6
|
-
/**
|
|
7
|
-
* Determine if channel is logging in terminal
|
|
8
|
-
*/
|
|
9
|
-
terminal = true;
|
|
10
|
-
/**
|
|
11
|
-
* {@inheritdoc}
|
|
12
|
-
*/
|
|
13
|
-
log(data) {
|
|
14
|
-
const { module, action, message, type: level } = data;
|
|
15
|
-
if (!this.shouldBeLogged(data))
|
|
16
|
-
return;
|
|
17
|
-
// display date and time with milliseconds
|
|
18
|
-
const date = new Date().toISOString(); // i.e 2021-01-01T00:00:00.000Z
|
|
19
|
-
switch (level) {
|
|
20
|
-
case "debug":
|
|
21
|
-
// add a debug icon
|
|
22
|
-
console.log(copper.colors.magentaBright("⚙"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.magentaBright(message));
|
|
23
|
-
break;
|
|
24
|
-
case "info":
|
|
25
|
-
// add an info icon
|
|
26
|
-
console.log(copper.colors.blueBright("ℹ"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.blueBright(message));
|
|
27
|
-
break;
|
|
28
|
-
case "warn":
|
|
29
|
-
// add a warning icon
|
|
30
|
-
console.log(copper.colors.yellow("⚠"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.yellowBright(message));
|
|
31
|
-
break;
|
|
32
|
-
case "error":
|
|
33
|
-
// add an error icon
|
|
34
|
-
console.log(copper.colors.red("✗"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.redBright(message));
|
|
35
|
-
break;
|
|
36
|
-
case "success":
|
|
37
|
-
// add a success icon
|
|
38
|
-
console.log(copper.colors.green("✓"), copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), copper.colors.greenBright(message));
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
console.log("[log]", copper.colors.yellow(`(${date})`), copper.colors.cyan(`[${module}]`), copper.colors.magenta(`[${action}]`), message);
|
|
42
|
-
}
|
|
43
|
-
if (typeof message === "object") {
|
|
44
|
-
console.log(message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}exports.ConsoleLog=ConsoleLog;//# sourceMappingURL=console-log.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1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,CAAG,CAAC,EAC1BA,aAAM,CAAC,IAAI,CAAC,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA,CAAG,CAAC,EAC1BA,aAAM,CAAC,OAAO,CAAC,CAAA,CAAA,EAAI,MAAM,CAAG,CAAA,CAAA,CAAC,EAC7B,OAAO,CACR,CAAC;AACL,SAAA;AAED,QAAA,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;AAC/B,YAAA,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtB,SAAA;KACF;AACF"}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { LogChannel } from "../log-channel";
|
|
2
|
-
import type { BasicLogConfigurations, LogContract, LoggingData, LogLevel, LogMessage } from "../types";
|
|
3
|
-
export type FileLogConfig = BasicLogConfigurations & {
|
|
4
|
-
storagePath?: string;
|
|
5
|
-
/**
|
|
6
|
-
* File name, without extension
|
|
7
|
-
*/
|
|
8
|
-
name?: string;
|
|
9
|
-
/**
|
|
10
|
-
* chunk mode
|
|
11
|
-
* If set to `single`, the logs will be created in a single file, unless the rotate is set to true
|
|
12
|
-
* If set to `daily`, the logs will be created in a daily file, unless the rotate is set to true
|
|
13
|
-
* If set to `hourly`, the logs will be created in an hourly file, unless the rotate is set to true
|
|
14
|
-
* @default single
|
|
15
|
-
*/
|
|
16
|
-
chunk?: "single" | "daily" | "hourly";
|
|
17
|
-
/**
|
|
18
|
-
* Whether to rotate the file
|
|
19
|
-
*
|
|
20
|
-
* @default true
|
|
21
|
-
*/
|
|
22
|
-
rotate?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* File Extension
|
|
25
|
-
*
|
|
26
|
-
* @default log
|
|
27
|
-
*/
|
|
28
|
-
extension?: string;
|
|
29
|
-
/**
|
|
30
|
-
* If rotate is set, the rotate name will be added to the file name suffixed with `-`
|
|
31
|
-
*
|
|
32
|
-
* @default DD-MM-YYYY
|
|
33
|
-
*/
|
|
34
|
-
rotateFileName?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Max file size before rotating the file
|
|
37
|
-
*
|
|
38
|
-
* @default 10MB
|
|
39
|
-
*/
|
|
40
|
-
maxFileSize?: number;
|
|
41
|
-
/**
|
|
42
|
-
* Set the max messages that needs to be added before writing to the file
|
|
43
|
-
*
|
|
44
|
-
* @default 100
|
|
45
|
-
*/
|
|
46
|
-
maxMessagesToWrite?: number;
|
|
47
|
-
/**
|
|
48
|
-
* Group logs by
|
|
49
|
-
* Please note that the order matters here
|
|
50
|
-
* For example, if you set `groupBy: ['level', 'module']`, the logs will be added in level name first, then by module
|
|
51
|
-
*
|
|
52
|
-
* @default none
|
|
53
|
-
*/
|
|
54
|
-
groupBy?: ("level" | "module" | "action")[];
|
|
55
|
-
/**
|
|
56
|
-
* Define what levels should be logged
|
|
57
|
-
*
|
|
58
|
-
* @default all
|
|
59
|
-
*/
|
|
60
|
-
levels?: LogLevel[];
|
|
61
|
-
/**
|
|
62
|
-
* Date and time format
|
|
63
|
-
*/
|
|
64
|
-
dateFormat?: {
|
|
65
|
-
date?: string;
|
|
66
|
-
time?: string;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
export declare class FileLog extends LogChannel<FileLogConfig> implements LogContract {
|
|
70
|
-
/**
|
|
71
|
-
* {@inheritdoc}
|
|
72
|
-
*/
|
|
73
|
-
name: string;
|
|
74
|
-
/**
|
|
75
|
-
* Messages buffer
|
|
76
|
-
*/
|
|
77
|
-
protected messages: LogMessage[];
|
|
78
|
-
/**
|
|
79
|
-
* Grouped messages
|
|
80
|
-
*/
|
|
81
|
-
protected groupedMessages: Record<string, LogMessage[]>;
|
|
82
|
-
/**
|
|
83
|
-
* Default channel configurations
|
|
84
|
-
*/
|
|
85
|
-
protected defaultConfigurations: FileLogConfig;
|
|
86
|
-
/**
|
|
87
|
-
* Last write time
|
|
88
|
-
*/
|
|
89
|
-
protected lastWriteTime: number;
|
|
90
|
-
/**
|
|
91
|
-
* A flag to determine if the file is being written
|
|
92
|
-
*/
|
|
93
|
-
protected isWriting: boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Check file size for file rotation
|
|
96
|
-
*/
|
|
97
|
-
protected checkAndRotateFile(filePath?: string): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Rotate log file
|
|
100
|
-
*/
|
|
101
|
-
protected rotateLogFile(): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* Flush messages
|
|
104
|
-
*/
|
|
105
|
-
protected initMessageFlush(): void;
|
|
106
|
-
/**
|
|
107
|
-
* Get file path
|
|
108
|
-
*/
|
|
109
|
-
get filePath(): string;
|
|
110
|
-
/**
|
|
111
|
-
* Get max messages
|
|
112
|
-
*/
|
|
113
|
-
protected get maxMessagesToWrite(): number;
|
|
114
|
-
/**
|
|
115
|
-
* Get file name
|
|
116
|
-
*/
|
|
117
|
-
get fileName(): string;
|
|
118
|
-
/**
|
|
119
|
-
* Get file extension
|
|
120
|
-
*/
|
|
121
|
-
get extension(): string;
|
|
122
|
-
/**
|
|
123
|
-
* Get content
|
|
124
|
-
*/
|
|
125
|
-
protected get content(): string;
|
|
126
|
-
/**
|
|
127
|
-
* Get storage path
|
|
128
|
-
*/
|
|
129
|
-
get storagePath(): string;
|
|
130
|
-
/**
|
|
131
|
-
* {@inheritdoc}
|
|
132
|
-
*/
|
|
133
|
-
protected init(): Promise<void>;
|
|
134
|
-
/**
|
|
135
|
-
* Synchronously flush messages
|
|
136
|
-
*/
|
|
137
|
-
flushSync(): void;
|
|
138
|
-
/**
|
|
139
|
-
* {@inheritdoc}
|
|
140
|
-
*/
|
|
141
|
-
log(data: LoggingData): Promise<void>;
|
|
142
|
-
/**
|
|
143
|
-
* Check if messages should be written
|
|
144
|
-
*/
|
|
145
|
-
protected checkIfMessagesShouldBeWritten(): Promise<void>;
|
|
146
|
-
/**
|
|
147
|
-
* Should be called after messages are saved
|
|
148
|
-
*/
|
|
149
|
-
protected onSave(): void;
|
|
150
|
-
/**
|
|
151
|
-
* Check if messages should be grouped
|
|
152
|
-
*/
|
|
153
|
-
protected get messagedShouldBeGrouped(): boolean;
|
|
154
|
-
/**
|
|
155
|
-
* Write messages to the file
|
|
156
|
-
*/
|
|
157
|
-
protected writeMessagesToFile(): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Write grouped messages to the file
|
|
160
|
-
*/
|
|
161
|
-
protected writeGroupedMessagesToFile(): Promise<void>;
|
|
162
|
-
/**
|
|
163
|
-
* Prepare grouped messages
|
|
164
|
-
*/
|
|
165
|
-
protected prepareGroupedMessages(): void;
|
|
166
|
-
/**
|
|
167
|
-
* Start writing to the file
|
|
168
|
-
*/
|
|
169
|
-
protected write(filePath: string, content: string): Promise<unknown>;
|
|
170
|
-
}
|
|
171
|
-
//# sourceMappingURL=file-log.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-log.d.ts","sourceRoot":"","sources":["../../src/channels/file-log.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,QAAQ,EACR,UAAU,EACX,MAAM,UAAU,CAAC;AAIlB,MAAM,MAAM,aAAa,GAAG,sBAAsB,GAAG;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IACtC;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE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