@deployanyway/doggo-log 0.3.0 → 0.4.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 +8 -0
- package/MIGRATION.md +6 -0
- package/README.md +26 -1
- package/dist/index.cjs +96 -9
- package/index.d.cts +4 -0
- package/index.d.ts +4 -0
- package/package.json +1 -1
- package/src/cli.js +5 -1
- package/src/commentary.js +77 -0
- package/src/index.js +27 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
48 original lines: eight per log level. Default `barkMode: 'classic'` preserves the existing first-line commentary. Opt into `barkMode: 'rotate'` for variation without repeats until that level's eight lines have been emitted. A seed selects a repeatable starting point by prefix and level; omitted seed starts with the first line. Filtering and quiet mode do not consume rotation. Each child logger owns its own sequence.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
## 0.3.0 — 2026-10-08
|
|
4
11
|
|
|
5
12
|
- Useful structured API/CLI additions described in README.
|
|
@@ -22,3 +29,4 @@
|
|
|
22
29
|
- Six logging methods, level filtering, quiet mode, and custom prefixes.
|
|
23
30
|
- Optional emojis, ANSI colors, timestamps, and JSON output.
|
|
24
31
|
- CLI, tests, documentation, and Node 22/24 CI.
|
|
32
|
+
```
|
package/MIGRATION.md
CHANGED
|
@@ -3,3 +3,9 @@
|
|
|
3
3
|
Node 22.13+ is required. Existing core APIs remain available; TypeScript declarations and CommonJS exports are new. The CLI now lives in src/cli.js behind the same executable path. Input/stdout behavior for new options is documented in README.
|
|
4
4
|
|
|
5
5
|
Install 0.3.0 with npm. Seeds and exact humorous wording are version-specific. Do not treat jokes or heuristic scores as production evidence.
|
|
6
|
+
|
|
7
|
+
## 0.3.0 to 0.4.0
|
|
8
|
+
|
|
9
|
+
48 original commentary lines across six levels; opt-in seeded rotation; independent child sequences, no advancement on filtering or failed writes; barkLines catalog API and CLI controls. Classic commentary remains default.
|
|
10
|
+
|
|
11
|
+
Existing defaults and entry points remain available. The new commentary rotation is opt-in; classic first-line commentary remains the default.
|
package/README.md
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
# doggo-log
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Commentary that stays useful (0.4.0)
|
|
4
|
+
|
|
5
|
+
48 original lines: eight per log level. Default `barkMode: 'classic'` preserves the existing first-line commentary. Opt into `barkMode: 'rotate'` for variation without repeats until that level's eight lines have been emitted. A seed selects a repeatable starting point by prefix and level; omitted seed starts with the first line. Filtering and quiet mode do not consume rotation. Each child logger owns its own sequence.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx @deployanyway/doggo-log warn 'Retry budget almost exhausted' --bark --bark-mode rotate --seed demo --json
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { createDogLogger, barkLines } from "@deployanyway/doggo-log";
|
|
13
|
+
const log = createDogLogger({
|
|
14
|
+
bark: true,
|
|
15
|
+
barkMode: "rotate",
|
|
16
|
+
seed: "job-42",
|
|
17
|
+
json: true,
|
|
18
|
+
});
|
|
19
|
+
const job = log.child("worker", { jobId: "42" });
|
|
20
|
+
job.info("Job accepted");
|
|
21
|
+
job.warn("Retry budget almost exhausted");
|
|
22
|
+
job.success("Job complete");
|
|
23
|
+
console.log(barkLines("warn"));
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Caller messages and JSON context remain separate from commentary. `barkLines(level)` returns a fresh catalog copy. The logger is intentionally small: it does not provide persistence, transport, redaction or a production observability backend.
|
|
27
|
+
|
|
28
|
+
> **Version 0.4.0:** install from npm with Node 22.13+ or Node 24. See MIGRATION.md for changes from 0.2.0.
|
|
4
29
|
|
|
5
30
|
[](https://www.npmjs.com/package/@deployanyway/doggo-log)
|
|
6
31
|
[](https://github.com/DeployAnyway/doggo-log/actions/workflows/ci.yml)
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.js
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
barkLines: () => barkLines,
|
|
23
24
|
createDogLogger: () => createDogLogger,
|
|
24
25
|
doglog: () => doglog
|
|
25
26
|
});
|
|
@@ -36,21 +37,93 @@ var levels = {
|
|
|
36
37
|
error: { rank: 40, emoji: "\u{1F6A8}", color: 31 }
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
// src/
|
|
40
|
-
var
|
|
41
|
-
debug:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
// src/commentary.js
|
|
41
|
+
var lines = {
|
|
42
|
+
debug: [
|
|
43
|
+
"Sniffing for clues.",
|
|
44
|
+
"Follow the trace, not the squirrel.",
|
|
45
|
+
"One breakpoint. Two ears. Maximum attention.",
|
|
46
|
+
"The missing value has left a scent trail.",
|
|
47
|
+
"Logging the evidence before chasing the theory.",
|
|
48
|
+
"The stack trace is our walking route.",
|
|
49
|
+
"Small reproduction, big detective energy.",
|
|
50
|
+
"Dallas found a clue. Benji would like to inspect the keyboard."
|
|
51
|
+
],
|
|
52
|
+
log: [
|
|
53
|
+
"Filed under things I sniffed.",
|
|
54
|
+
"Fetch complete. Filing the interesting bit.",
|
|
55
|
+
"Another breadcrumb for future-us.",
|
|
56
|
+
"This line has been approved by the tail department.",
|
|
57
|
+
"A small update with excellent ears.",
|
|
58
|
+
"Evidence delivered without chewing it.",
|
|
59
|
+
"Keeping a trail through the code forest.",
|
|
60
|
+
"Benji brought the log. Dallas brought enthusiasm."
|
|
61
|
+
],
|
|
62
|
+
info: [
|
|
63
|
+
"Good to know. Good dog to tell you.",
|
|
64
|
+
"A useful update, delivered at husky speed.",
|
|
65
|
+
"The facts have arrived wearing sensible paws.",
|
|
66
|
+
"Worth knowing before the next zoomie.",
|
|
67
|
+
"No alarm. Just a well-timed nose boop.",
|
|
68
|
+
"Status fetched. Tail at a responsible speed.",
|
|
69
|
+
"A little context saves a lot of barking.",
|
|
70
|
+
"Dallas and Benji have entered the observability business."
|
|
71
|
+
],
|
|
72
|
+
success: [
|
|
73
|
+
"Treat budget approved.",
|
|
74
|
+
"Good result. Better evidence. Best dog.",
|
|
75
|
+
"The check passed. Save some applause for monitoring.",
|
|
76
|
+
"One fewer problem between us and the walk.",
|
|
77
|
+
"Tail deployment successful.",
|
|
78
|
+
"The happy path has receipts today.",
|
|
79
|
+
"Achievement unlocked: boring, repeatable success.",
|
|
80
|
+
"Dallas celebrates. Benji is already planning the victory lap."
|
|
81
|
+
],
|
|
82
|
+
warn: [
|
|
83
|
+
"Suspicious squirrel detected.",
|
|
84
|
+
"Ears up. This deserves a closer look.",
|
|
85
|
+
"Something smells odd; inspect before retrying.",
|
|
86
|
+
"A warning is a breadcrumb, not a dare.",
|
|
87
|
+
"The tail slowed down for a reason.",
|
|
88
|
+
"Check the evidence before this becomes an incident.",
|
|
89
|
+
"Potential trouble has arrived with muddy paws.",
|
|
90
|
+
"Benji heard something. Dallas recommends checking the logs."
|
|
91
|
+
],
|
|
92
|
+
error: [
|
|
93
|
+
"The dog has fetched the incident report.",
|
|
94
|
+
"Read the first failure before chasing the pack.",
|
|
95
|
+
"The red light is evidence, not a personality review.",
|
|
96
|
+
"Pause the zoomies. Find the cause and the rollback.",
|
|
97
|
+
"This needs a fix, not louder barking.",
|
|
98
|
+
"Capture the reproduction while the scent is fresh.",
|
|
99
|
+
"The operation failed. The team still gets kindness.",
|
|
100
|
+
"Dallas and Benji are standing by with emotional support."
|
|
101
|
+
]
|
|
47
102
|
};
|
|
103
|
+
function barkLines(level) {
|
|
104
|
+
if (typeof level !== "string" || !Object.hasOwn(lines, level))
|
|
105
|
+
throw new RangeError("Choose debug, log, info, success, warn or error.");
|
|
106
|
+
return [...lines[level]];
|
|
107
|
+
}
|
|
108
|
+
function commentaryIndex(seed, salt, length) {
|
|
109
|
+
if (seed === void 0) return 0;
|
|
110
|
+
let hash = 2166136261;
|
|
111
|
+
for (const char of salt + ":" + typeof seed + ":" + seed) {
|
|
112
|
+
hash ^= char.codePointAt(0);
|
|
113
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
114
|
+
}
|
|
115
|
+
return hash % length;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/index.js
|
|
48
119
|
function createDogLogger(options = {}) {
|
|
49
120
|
if (!options || typeof options !== "object" || Array.isArray(options))
|
|
50
121
|
throw new TypeError("Options must be an object.");
|
|
51
122
|
const config = {
|
|
52
123
|
emoji: true,
|
|
53
124
|
bark: false,
|
|
125
|
+
barkMode: "classic",
|
|
126
|
+
seed: void 0,
|
|
54
127
|
color: false,
|
|
55
128
|
timestamp: false,
|
|
56
129
|
json: false,
|
|
@@ -82,6 +155,11 @@ function createDogLogger(options = {}) {
|
|
|
82
155
|
);
|
|
83
156
|
if (typeof config.write !== "function" || typeof config.clock !== "function")
|
|
84
157
|
throw new TypeError("write and clock must be functions.");
|
|
158
|
+
if (!["classic", "rotate"].includes(config.barkMode))
|
|
159
|
+
throw new RangeError("barkMode must be classic or rotate.");
|
|
160
|
+
if (config.seed !== void 0 && typeof config.seed !== "string" && !(typeof config.seed === "number" && Number.isFinite(config.seed)))
|
|
161
|
+
throw new TypeError("seed must be a string or finite number.");
|
|
162
|
+
const counters = {};
|
|
85
163
|
const logger = Object.fromEntries(
|
|
86
164
|
Object.entries(levels).map(([level, style]) => [
|
|
87
165
|
level,
|
|
@@ -89,7 +167,13 @@ function createDogLogger(options = {}) {
|
|
|
89
167
|
if (config.quiet || style.rank < levels[config.level].rank)
|
|
90
168
|
return void 0;
|
|
91
169
|
const message = (0, import_node_util.format)(...args);
|
|
92
|
-
const
|
|
170
|
+
const pool = config.bark ? barkLines(level) : void 0;
|
|
171
|
+
const index = config.barkMode === "rotate" ? (commentaryIndex(
|
|
172
|
+
config.seed,
|
|
173
|
+
config.prefix + ":" + level,
|
|
174
|
+
pool?.length ?? 1
|
|
175
|
+
) + (counters[level] ?? 0)) % (pool?.length ?? 1) : 0;
|
|
176
|
+
const commentary = pool?.[index];
|
|
93
177
|
let timestamp;
|
|
94
178
|
if (config.timestamp) {
|
|
95
179
|
const date = config.clock();
|
|
@@ -119,6 +203,8 @@ function createDogLogger(options = {}) {
|
|
|
119
203
|
if (config.color) line = `\x1B[${style.color}m${line}\x1B[0m`;
|
|
120
204
|
}
|
|
121
205
|
config.write(line, level);
|
|
206
|
+
if (config.bark)
|
|
207
|
+
counters[level] = ((counters[level] ?? 0) + 1) % pool.length;
|
|
122
208
|
return line;
|
|
123
209
|
}
|
|
124
210
|
])
|
|
@@ -147,6 +233,7 @@ function createDogLogger(options = {}) {
|
|
|
147
233
|
var doglog = createDogLogger();
|
|
148
234
|
// Annotate the CommonJS export names for ESM import in node:
|
|
149
235
|
0 && (module.exports = {
|
|
236
|
+
barkLines,
|
|
150
237
|
createDogLogger,
|
|
151
238
|
doglog
|
|
152
239
|
});
|
package/index.d.cts
CHANGED
|
@@ -3,6 +3,8 @@ export type LogContext = Record<string, string | number | boolean | null>;
|
|
|
3
3
|
export interface DogOptions {
|
|
4
4
|
emoji?: boolean;
|
|
5
5
|
bark?: boolean;
|
|
6
|
+
barkMode?: "classic" | "rotate";
|
|
7
|
+
seed?: string | number;
|
|
6
8
|
color?: boolean;
|
|
7
9
|
timestamp?: boolean;
|
|
8
10
|
json?: boolean;
|
|
@@ -20,3 +22,5 @@ export type DogLogger = Record<Level, LogMethod> & {
|
|
|
20
22
|
};
|
|
21
23
|
export function createDogLogger(options?: DogOptions): DogLogger;
|
|
22
24
|
export const doglog: DogLogger;
|
|
25
|
+
|
|
26
|
+
export function barkLines(level: Level): string[];
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export type LogContext = Record<string, string | number | boolean | null>;
|
|
|
3
3
|
export interface DogOptions {
|
|
4
4
|
emoji?: boolean;
|
|
5
5
|
bark?: boolean;
|
|
6
|
+
barkMode?: "classic" | "rotate";
|
|
7
|
+
seed?: string | number;
|
|
6
8
|
color?: boolean;
|
|
7
9
|
timestamp?: boolean;
|
|
8
10
|
json?: boolean;
|
|
@@ -20,3 +22,5 @@ export type DogLogger = Record<Level, LogMethod> & {
|
|
|
20
22
|
};
|
|
21
23
|
export function createDogLogger(options?: DogOptions): DogLogger;
|
|
22
24
|
export const doglog: DogLogger;
|
|
25
|
+
|
|
26
|
+
export function barkLines(level: Level): string[];
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -17,6 +17,8 @@ try {
|
|
|
17
17
|
context: { type: "string" },
|
|
18
18
|
"no-color": { type: "boolean" },
|
|
19
19
|
bark: { type: "boolean" },
|
|
20
|
+
"bark-mode": { type: "string" },
|
|
21
|
+
seed: { type: "string" },
|
|
20
22
|
timestamp: { type: "boolean" },
|
|
21
23
|
quiet: { type: "boolean" },
|
|
22
24
|
color: { type: "boolean" },
|
|
@@ -27,7 +29,7 @@ try {
|
|
|
27
29
|
});
|
|
28
30
|
if (values.help) {
|
|
29
31
|
console.log(
|
|
30
|
-
"Usage: doggo-log <method> <message> [options]\n\nMethods: log, info, success, warn, error, debug. --stdin reads a bounded message; arguments win. --context accepts JSON scalar fields for JSON logs; --no-color and NO_COLOR disable ANSI.\nOptions:\n --bark Add useful dog commentary\n --json Emit JSON\n --timestamp Include an ISO timestamp\n --no-emoji Disable emojis\n --color Enable ANSI colors\n --prefix text Add a prefix\n --level name Minimum level (CLI default: debug)\n --quiet Suppress output\n -h, --help Show help\n -v, --version Show version\n\nExit codes: 0 success; 2 invalid arguments. Logging an error exits 0.",
|
|
32
|
+
"Usage: doggo-log <method> <message> [options]\n\nMethods: log, info, success, warn, error, debug. --stdin reads a bounded message; arguments win. --context accepts JSON scalar fields for JSON logs; --no-color and NO_COLOR disable ANSI.\nOptions:\n --bark Add useful dog commentary\n --bark-mode classic|rotate Classic line or varied commentary\n --seed text Repeatable rotation starting point\n --json Emit JSON\n --timestamp Include an ISO timestamp\n --no-emoji Disable emojis\n --color Enable ANSI colors\n --prefix text Add a prefix\n --level name Minimum level (CLI default: debug)\n --quiet Suppress output\n -h, --help Show help\n -v, --version Show version\n\nExit codes: 0 success; 2 invalid arguments. Logging an error exits 0.",
|
|
31
33
|
);
|
|
32
34
|
} else if (values.version) {
|
|
33
35
|
console.log(
|
|
@@ -47,6 +49,8 @@ try {
|
|
|
47
49
|
const logger = createDogLogger({
|
|
48
50
|
emoji: !values["no-emoji"],
|
|
49
51
|
bark: values.bark ?? false,
|
|
52
|
+
barkMode: values["bark-mode"] ?? "classic",
|
|
53
|
+
seed: values.seed,
|
|
50
54
|
color:
|
|
51
55
|
!values["no-color"] &&
|
|
52
56
|
!Object.hasOwn(process.env, "NO_COLOR") &&
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Original commentary; never replaces the caller's message.
|
|
2
|
+
const lines = {
|
|
3
|
+
debug: [
|
|
4
|
+
"Sniffing for clues.",
|
|
5
|
+
"Follow the trace, not the squirrel.",
|
|
6
|
+
"One breakpoint. Two ears. Maximum attention.",
|
|
7
|
+
"The missing value has left a scent trail.",
|
|
8
|
+
"Logging the evidence before chasing the theory.",
|
|
9
|
+
"The stack trace is our walking route.",
|
|
10
|
+
"Small reproduction, big detective energy.",
|
|
11
|
+
"Dallas found a clue. Benji would like to inspect the keyboard.",
|
|
12
|
+
],
|
|
13
|
+
log: [
|
|
14
|
+
"Filed under things I sniffed.",
|
|
15
|
+
"Fetch complete. Filing the interesting bit.",
|
|
16
|
+
"Another breadcrumb for future-us.",
|
|
17
|
+
"This line has been approved by the tail department.",
|
|
18
|
+
"A small update with excellent ears.",
|
|
19
|
+
"Evidence delivered without chewing it.",
|
|
20
|
+
"Keeping a trail through the code forest.",
|
|
21
|
+
"Benji brought the log. Dallas brought enthusiasm.",
|
|
22
|
+
],
|
|
23
|
+
info: [
|
|
24
|
+
"Good to know. Good dog to tell you.",
|
|
25
|
+
"A useful update, delivered at husky speed.",
|
|
26
|
+
"The facts have arrived wearing sensible paws.",
|
|
27
|
+
"Worth knowing before the next zoomie.",
|
|
28
|
+
"No alarm. Just a well-timed nose boop.",
|
|
29
|
+
"Status fetched. Tail at a responsible speed.",
|
|
30
|
+
"A little context saves a lot of barking.",
|
|
31
|
+
"Dallas and Benji have entered the observability business.",
|
|
32
|
+
],
|
|
33
|
+
success: [
|
|
34
|
+
"Treat budget approved.",
|
|
35
|
+
"Good result. Better evidence. Best dog.",
|
|
36
|
+
"The check passed. Save some applause for monitoring.",
|
|
37
|
+
"One fewer problem between us and the walk.",
|
|
38
|
+
"Tail deployment successful.",
|
|
39
|
+
"The happy path has receipts today.",
|
|
40
|
+
"Achievement unlocked: boring, repeatable success.",
|
|
41
|
+
"Dallas celebrates. Benji is already planning the victory lap.",
|
|
42
|
+
],
|
|
43
|
+
warn: [
|
|
44
|
+
"Suspicious squirrel detected.",
|
|
45
|
+
"Ears up. This deserves a closer look.",
|
|
46
|
+
"Something smells odd; inspect before retrying.",
|
|
47
|
+
"A warning is a breadcrumb, not a dare.",
|
|
48
|
+
"The tail slowed down for a reason.",
|
|
49
|
+
"Check the evidence before this becomes an incident.",
|
|
50
|
+
"Potential trouble has arrived with muddy paws.",
|
|
51
|
+
"Benji heard something. Dallas recommends checking the logs.",
|
|
52
|
+
],
|
|
53
|
+
error: [
|
|
54
|
+
"The dog has fetched the incident report.",
|
|
55
|
+
"Read the first failure before chasing the pack.",
|
|
56
|
+
"The red light is evidence, not a personality review.",
|
|
57
|
+
"Pause the zoomies. Find the cause and the rollback.",
|
|
58
|
+
"This needs a fix, not louder barking.",
|
|
59
|
+
"Capture the reproduction while the scent is fresh.",
|
|
60
|
+
"The operation failed. The team still gets kindness.",
|
|
61
|
+
"Dallas and Benji are standing by with emotional support.",
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
export function barkLines(level) {
|
|
65
|
+
if (typeof level !== "string" || !Object.hasOwn(lines, level))
|
|
66
|
+
throw new RangeError("Choose debug, log, info, success, warn or error.");
|
|
67
|
+
return [...lines[level]];
|
|
68
|
+
}
|
|
69
|
+
export function commentaryIndex(seed, salt, length) {
|
|
70
|
+
if (seed === undefined) return 0;
|
|
71
|
+
let hash = 2166136261;
|
|
72
|
+
for (const char of salt + ":" + typeof seed + ":" + seed) {
|
|
73
|
+
hash ^= char.codePointAt(0);
|
|
74
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
75
|
+
}
|
|
76
|
+
return hash % length;
|
|
77
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { format } from "node:util";
|
|
2
2
|
import { levels } from "./levels.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
log: "Filed under things I sniffed.",
|
|
6
|
-
info: "Good to know. Good dog to tell you.",
|
|
7
|
-
success: "Treat budget approved.",
|
|
8
|
-
warn: "Suspicious squirrel detected.",
|
|
9
|
-
error: "The dog has fetched the incident report.",
|
|
10
|
-
};
|
|
3
|
+
import { barkLines, commentaryIndex } from "./commentary.js";
|
|
4
|
+
export { barkLines };
|
|
11
5
|
|
|
12
6
|
/**
|
|
13
7
|
* Create a small logger. Methods return the emitted line, or undefined if filtered.
|
|
@@ -19,6 +13,8 @@ export function createDogLogger(options = {}) {
|
|
|
19
13
|
const config = {
|
|
20
14
|
emoji: true,
|
|
21
15
|
bark: false,
|
|
16
|
+
barkMode: "classic",
|
|
17
|
+
seed: undefined,
|
|
22
18
|
color: false,
|
|
23
19
|
timestamp: false,
|
|
24
20
|
json: false,
|
|
@@ -62,6 +58,15 @@ export function createDogLogger(options = {}) {
|
|
|
62
58
|
);
|
|
63
59
|
if (typeof config.write !== "function" || typeof config.clock !== "function")
|
|
64
60
|
throw new TypeError("write and clock must be functions.");
|
|
61
|
+
if (!["classic", "rotate"].includes(config.barkMode))
|
|
62
|
+
throw new RangeError("barkMode must be classic or rotate.");
|
|
63
|
+
if (
|
|
64
|
+
config.seed !== undefined &&
|
|
65
|
+
typeof config.seed !== "string" &&
|
|
66
|
+
!(typeof config.seed === "number" && Number.isFinite(config.seed))
|
|
67
|
+
)
|
|
68
|
+
throw new TypeError("seed must be a string or finite number.");
|
|
69
|
+
const counters = {};
|
|
65
70
|
const logger = Object.fromEntries(
|
|
66
71
|
Object.entries(levels).map(([level, style]) => [
|
|
67
72
|
level,
|
|
@@ -69,7 +74,18 @@ export function createDogLogger(options = {}) {
|
|
|
69
74
|
if (config.quiet || style.rank < levels[config.level].rank)
|
|
70
75
|
return undefined;
|
|
71
76
|
const message = format(...args);
|
|
72
|
-
const
|
|
77
|
+
const pool = config.bark ? barkLines(level) : undefined;
|
|
78
|
+
const index =
|
|
79
|
+
config.barkMode === "rotate"
|
|
80
|
+
? (commentaryIndex(
|
|
81
|
+
config.seed,
|
|
82
|
+
config.prefix + ":" + level,
|
|
83
|
+
pool?.length ?? 1,
|
|
84
|
+
) +
|
|
85
|
+
(counters[level] ?? 0)) %
|
|
86
|
+
(pool?.length ?? 1)
|
|
87
|
+
: 0;
|
|
88
|
+
const commentary = pool?.[index];
|
|
73
89
|
let timestamp;
|
|
74
90
|
if (config.timestamp) {
|
|
75
91
|
const date = config.clock();
|
|
@@ -103,6 +119,8 @@ export function createDogLogger(options = {}) {
|
|
|
103
119
|
if (config.color) line = `\u001b[${style.color}m${line}\u001b[0m`;
|
|
104
120
|
}
|
|
105
121
|
config.write(line, level);
|
|
122
|
+
if (config.bark)
|
|
123
|
+
counters[level] = ((counters[level] ?? 0) + 1) % pool.length;
|
|
106
124
|
return line;
|
|
107
125
|
},
|
|
108
126
|
]),
|