@deployanyway/doggo-log 0.1.1 → 0.2.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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0 — 2026-10-08
4
+
5
+ - Scoped logs, optional barks: Use `logger.child("database")` to create an independent logger with a nested prefix. Enable `{ bark: true }` or CLI `--bark` for dog commentary. JSON preserves the original message and adds a separate `commentary` field. Filtering still suppresses output.
6
+ - Add npm and CI badges to the published README.
7
+
3
8
  ## 0.1.1 — 2026-10-08
4
9
 
5
10
  - Correct npm installation and npx documentation after the initial publication.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # doggo-log
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/%40deployanyway%2Fdoggo-log)](https://www.npmjs.com/package/@deployanyway/doggo-log)
4
+ [![CI](https://github.com/DeployAnyway/doggo-log/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/DeployAnyway/doggo-log/actions/workflows/ci.yml)
5
+
3
6
  A tiny Node.js console logger with JSON output, log levels, and dog emojis. Good logs. Very good logs.
4
7
 
5
8
  ```text
@@ -140,3 +143,19 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
140
143
  - [doggo-log](https://github.com/DeployAnyway/doggo-log)
141
144
  - [ship-it-meter](https://github.com/DeployAnyway/ship-it-meter)
142
145
  - [bro-say](https://github.com/DeployAnyway/bro-say)
146
+
147
+ ## Scoped logs, optional barks
148
+
149
+ Use `logger.child("database")` to create an independent logger with a nested prefix. Enable `{ bark: true }` or CLI `--bark` for dog commentary. JSON preserves the original message and adds a separate `commentary` field. Filtering still suppresses output.
150
+
151
+ ```sh
152
+ npx @deployanyway/doggo-log success "Migration complete" --bark --prefix database
153
+ ```
154
+
155
+ API (import the named functions from this package):
156
+
157
+ ```js
158
+ createDogLogger({ bark: true, prefix: "api" })
159
+ .child("database")
160
+ .success("Migration complete");
161
+ ```
package/bin/cli.js CHANGED
@@ -12,6 +12,7 @@ try {
12
12
  help: { type: "boolean", short: "h" },
13
13
  version: { type: "boolean", short: "v" },
14
14
  json: { type: "boolean" },
15
+ bark: { type: "boolean" },
15
16
  timestamp: { type: "boolean" },
16
17
  quiet: { type: "boolean" },
17
18
  color: { type: "boolean" },
@@ -22,7 +23,7 @@ try {
22
23
  });
23
24
  if (values.help) {
24
25
  console.log(
25
- "Usage: doggo-log <method> <message> [options]\n\nMethods: log, info, success, warn, error, debug\nOptions:\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.",
26
+ "Usage: doggo-log <method> <message> [options]\n\nMethods: log, info, success, warn, error, debug\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.",
26
27
  );
27
28
  } else if (values.version) {
28
29
  console.log(
@@ -36,6 +37,7 @@ try {
36
37
  throw new TypeError("Provide a valid method and nonempty message.");
37
38
  const logger = createDogLogger({
38
39
  emoji: !values["no-emoji"],
40
+ bark: values.bark ?? false,
39
41
  color: values.color ?? false,
40
42
  timestamp: values.timestamp ?? false,
41
43
  json: values.json ?? false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deployanyway/doggo-log",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "A tiny Node.js console logger with JSON output, log levels, and dog emojis. Good logs. Very good logs.",
5
5
  "type": "module",
6
6
  "exports": "./src/index.js",
package/src/index.js CHANGED
@@ -1,5 +1,13 @@
1
1
  import { format } from "node:util";
2
2
  import { levels } from "./levels.js";
3
+ const barks = {
4
+ debug: "Sniffing for clues.",
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
11
 
4
12
  /**
5
13
  * Create a small logger. Methods return the emitted line, or undefined if filtered.
@@ -10,6 +18,7 @@ export function createDogLogger(options = {}) {
10
18
  throw new TypeError("Options must be an object.");
11
19
  const config = {
12
20
  emoji: true,
21
+ bark: false,
13
22
  color: false,
14
23
  timestamp: false,
15
24
  json: false,
@@ -23,7 +32,7 @@ export function createDogLogger(options = {}) {
23
32
  clock: () => new Date(),
24
33
  ...options,
25
34
  };
26
- for (const key of ["emoji", "color", "timestamp", "json", "quiet"]) {
35
+ for (const key of ["emoji", "color", "timestamp", "json", "quiet", "bark"]) {
27
36
  if (typeof config[key] !== "boolean")
28
37
  throw new TypeError(`${key} must be a boolean.`);
29
38
  }
@@ -35,13 +44,14 @@ export function createDogLogger(options = {}) {
35
44
  );
36
45
  if (typeof config.write !== "function" || typeof config.clock !== "function")
37
46
  throw new TypeError("write and clock must be functions.");
38
- return Object.fromEntries(
47
+ const logger = Object.fromEntries(
39
48
  Object.entries(levels).map(([level, style]) => [
40
49
  level,
41
50
  (...args) => {
42
51
  if (config.quiet || style.rank < levels[config.level].rank)
43
52
  return undefined;
44
53
  const message = format(...args);
54
+ const commentary = config.bark ? barks[level] : undefined;
45
55
  let timestamp;
46
56
  if (config.timestamp) {
47
57
  const date = config.clock();
@@ -54,6 +64,7 @@ export function createDogLogger(options = {}) {
54
64
  line = JSON.stringify({
55
65
  level,
56
66
  message,
67
+ ...(commentary ? { commentary } : {}),
57
68
  ...(config.prefix ? { prefix: config.prefix } : {}),
58
69
  ...(timestamp ? { timestamp } : {}),
59
70
  });
@@ -64,6 +75,7 @@ export function createDogLogger(options = {}) {
64
75
  config.emoji ? style.emoji : undefined,
65
76
  level.toUpperCase().padEnd(7),
66
77
  message,
78
+ commentary,
67
79
  ]
68
80
  .filter((part) => part !== undefined && part !== "")
69
81
  .join(" ");
@@ -74,6 +86,15 @@ export function createDogLogger(options = {}) {
74
86
  },
75
87
  ]),
76
88
  );
89
+ logger.child = (prefix) => {
90
+ if (typeof prefix !== "string" || !prefix.trim())
91
+ throw new TypeError("Child prefix must be a nonempty string.");
92
+ return createDogLogger({
93
+ ...config,
94
+ prefix: [config.prefix, prefix.trim()].filter(Boolean).join(":"),
95
+ });
96
+ };
97
+ return logger;
77
98
  }
78
99
 
79
100
  /** Default logger: emoji enabled, no timestamp/color, info threshold. */