logosaur 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 0c71
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,164 @@
1
- # Temporary Holding Version
1
+ # logosaur 🦖
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/logosaur?color=af5fd7)](https://www.npmjs.com/package/logosaur)
4
+ [![CI](https://github.com/0c71/logosaur/actions/workflows/ci.yml/badge.svg)](https://github.com/0c71/logosaur/actions/workflows/ci.yml)
5
+ ![License: MIT](https://img.shields.io/badge/license-MIT-5fffd7)
6
+ ![Dependencies: zero](https://img.shields.io/badge/dependencies-zero-d7ff87)
7
+ ![Built for Bun](https://img.shields.io/badge/built%20for-bun-ff5f87)
8
+
9
+ A tiny, colorful, structured logger for Bun and TypeScript, with
10
+ **zero dependencies**. Short Go-style levels, `key=value` fields, and nothing
11
+ else dragged into your `node_modules`. Rawr.
12
+
13
+ ![logosaur output in a terminal](assets/demo.svg)
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ bun add logosaur
19
+ ```
20
+
21
+ It works in Node too: `npm install logosaur`.
22
+
23
+ That's the whole install. logosaur has **zero dependencies**, so it's one small
24
+ package (about 5 kB) and nothing else: no tree of transitive installs, nothing
25
+ to audit but the one file. 🦴
26
+
27
+ ## How it compares
28
+
29
+ | | logosaur | pino | winston | tslog | consola |
30
+ | --------------------- | --------- | -------- | -------- | -------- | -------- |
31
+ | Packages installed | **1** | 13 | 28 | 1 | 1 |
32
+ | Install size | **14 kB** | 1.2 MB | 1.9 MB | 980 kB | 310 kB |
33
+ | Import, Node / Bun | **4 / 6 ms** | 18 / 18 ms | 31 / 29 ms | 20 / 12 ms | 14 / 10 ms |
34
+ | JSON lines/s, Node / Bun | 1.1M / **2.6M** | **2.7M / 2.6M** | 290k / 530k | 550k / 700k | |
35
+ | Text lines/s, Node / Bun | **830k / 1.2M** | | | 280k / 320k | 100k / 120k |
36
+
37
+ logosaur is the smallest install by far and the quickest to import. It writes
38
+ text lines three times as fast as tslog and eight to ten times as fast as
39
+ consola. On Bun it writes JSON as fast as pino; on Node pino is about two and a
40
+ half times faster, so if raw JSON throughput on Node is what you need, pick pino.
41
+
42
+ Each line has a message and four fields, written to a sink that throws it away.
43
+ Every logger runs in its own process, on Node 24 and Bun 1.4, on one Windows
44
+ desktop. tslog's code-position lookup is off, so it's formatting against
45
+ formatting. Run it yourself:
46
+
47
+ ```bash
48
+ cd bench && bun install && bun run size && bun run import && bun run speed
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ ```ts
54
+ import { log } from "logosaur";
55
+
56
+ log.info("🦖 hatched", { name: "rex", mood: "very hungry" });
57
+ log.warn("meteor spotted", { distance: "very close" });
58
+ log.error("lunch escaped", { species: "raptor", speed: "fast" });
59
+ ```
60
+
61
+ ```
62
+ 14:02:03 INF 🦖 hatched name=rex mood="very hungry"
63
+ 14:02:05 WRN meteor spotted distance="very close"
64
+ 14:02:06 ERR lunch escaped species=raptor speed=fast
65
+ ```
66
+
67
+ ## Levels
68
+
69
+ Three letters each, like Go's loggers.
70
+
71
+ | Method | Label | Notes |
72
+ | ----------- | ----- | ------------------------------------------- |
73
+ | `log.debug` | `DBG` | hidden unless the level is `debug` |
74
+ | `log.info` | `INF` | the default level |
75
+ | `log.warn` | `WRN` | |
76
+ | `log.error` | `ERR` | |
77
+ | `log.fatal` | `FTL` | logs, then goes extinct (exits with code 1) 🦴 |
78
+
79
+ ```ts
80
+ log.setLevel("debug");
81
+ ```
82
+
83
+ ## Fields
84
+
85
+ Nested objects are flattened, empty values are skipped, and strings with
86
+ spaces get quotes.
87
+
88
+ ```ts
89
+ log.info("dinner served", {
90
+ pen: { id: 7, fence: "electric" },
91
+ guests: ["rex", "blue"],
92
+ note: null,
93
+ });
94
+ ```
95
+
96
+ ```
97
+ 14:02:03 INF dinner served pen.id=7 pen.fence=electric guests=[rex blue]
98
+ ```
99
+
100
+ Errors log as their message, and dates as ISO strings.
101
+
102
+ ## Hatchlings
103
+
104
+ Sub-loggers that carry fields or a prefix on every line:
105
+
106
+ ```ts
107
+ const pen = log.with({ pen: 7 });
108
+ pen.warn("fence flickering");
109
+ // 14:02:03 WRN fence flickering pen=7
110
+
111
+ const cave = log.withPrefix("cave");
112
+ cave.info("echo");
113
+ // 14:02:03 INF cave: echo
114
+ ```
115
+
116
+ ## Options
117
+
118
+ ```ts
119
+ import { createLogger } from "logosaur";
120
+
121
+ const log = createLogger({
122
+ level: "debug",
123
+ prefix: "park",
124
+ timeZone: "America/New_York",
125
+ file: (day) => `logs/${day}.log`,
126
+ });
127
+ ```
128
+
129
+ | Option | Default | What it does |
130
+ | ---------- | ---------------- | ------------------------------------------------------- |
131
+ | `level` | `"info"` | The quietest level that gets through |
132
+ | `prefix` | | Shown before every message, as `prefix:` |
133
+ | `fields` | `{}` | Fields added to every line |
134
+ | `time` | `true` | Show the time on text lines |
135
+ | `timeZone` | local | Any IANA time zone, like `"Europe/London"` |
136
+ | `format` | `"text"` | `"text"`, `"json"` or `"logfmt"` |
137
+ | `color` | auto | Force colors on or off |
138
+ | `output` | `process.stderr` | Anything with a `write(text)` method |
139
+ | `file` | | Also append plain lines to a file, or one file per day |
140
+ | `replacer` | | `(key, value) => value`, to reshape fields at any depth |
141
+
142
+ ## Formats
143
+
144
+ ```ts
145
+ createLogger({ format: "json" }).info("hatched", { egg: { size: "large" } });
146
+ // {"time":"2026-11-17T19:02:03.000Z","level":"info","msg":"hatched","egg":{"size":"large"}}
147
+
148
+ createLogger({ format: "logfmt" }).info("hatched", { name: "rex" });
149
+ // time=2026-11-17T19:02:03.000Z level=info msg=hatched name=rex
150
+ ```
151
+
152
+ ## Colors
153
+
154
+ Colors turn on by themselves in a terminal. `NO_COLOR` turns them off,
155
+ `FORCE_COLOR` turns them on, or pass `color: true` or `false`. Files never get
156
+ colors.
157
+
158
+ ## License
159
+
160
+ [MIT](LICENSE)
161
+
162
+ ---
163
+
164
+ Made with 🦴 and a very small brain. Rawr.
@@ -0,0 +1,64 @@
1
+ type Format = "text" | "json" | "logfmt";
2
+ interface Writer {
3
+ write(chunk: string): unknown;
4
+ isTTY?: boolean;
5
+ }
6
+ type Replacer = (key: string, value: unknown) => unknown;
7
+ interface Options {
8
+ level?: Level;
9
+ prefix?: string;
10
+ fields?: object;
11
+ time?: boolean;
12
+ timeZone?: string;
13
+ format?: Format;
14
+ color?: boolean;
15
+ output?: Writer;
16
+ file?: string | ((day: string) => string);
17
+ replacer?: Replacer;
18
+ now?: () => Date;
19
+ }
20
+ type Log = (msg: string, fields?: object) => void;
21
+ interface Logger {
22
+ debug: Log;
23
+ info: Log;
24
+ warn: Log;
25
+ error: Log;
26
+ fatal: (msg: string, fields?: object) => never;
27
+ with: (fields: object) => Logger;
28
+ withPrefix: (prefix: string) => Logger;
29
+ setLevel: (level: Level) => void;
30
+ readonly level: Level;
31
+ }
32
+ declare const levels: {
33
+ readonly debug: {
34
+ readonly rank: 0;
35
+ readonly label: "DBG";
36
+ readonly color: 63;
37
+ };
38
+ readonly info: {
39
+ readonly rank: 1;
40
+ readonly label: "INF";
41
+ readonly color: 86;
42
+ };
43
+ readonly warn: {
44
+ readonly rank: 2;
45
+ readonly label: "WRN";
46
+ readonly color: 192;
47
+ };
48
+ readonly error: {
49
+ readonly rank: 3;
50
+ readonly label: "ERR";
51
+ readonly color: 204;
52
+ };
53
+ readonly fatal: {
54
+ readonly rank: 4;
55
+ readonly label: "FTL";
56
+ readonly color: 134;
57
+ };
58
+ };
59
+ type Level = keyof typeof levels;
60
+ declare const formatValue: (value: unknown) => string;
61
+ declare const pairs: (fields: object, replacer?: Replacer) => [string, unknown][];
62
+ declare const createLogger: (options?: Options) => Logger;
63
+ declare const log: Logger;
64
+ export { createLogger, log, formatValue, pairs, type Format, type Level, type Logger, type Options, type Replacer, type Writer, };
package/dist/index.js ADDED
@@ -0,0 +1,221 @@
1
+ // src/index.ts
2
+ import { appendFileSync, mkdirSync } from "node:fs";
3
+ import { dirname } from "node:path";
4
+ var levels = {
5
+ debug: { rank: 0, label: "DBG", color: 63 },
6
+ info: { rank: 1, label: "INF", color: 86 },
7
+ warn: { rank: 2, label: "WRN", color: 192 },
8
+ error: { rank: 3, label: "ERR", color: 204 },
9
+ fatal: { rank: 4, label: "FTL", color: 134 }
10
+ };
11
+ var bold = "\x1B[1m";
12
+ var faint = "\x1B[2m";
13
+ var reset = "\x1B[0m";
14
+ var fg = (code) => `\x1B[38;5;${code}m`;
15
+ var paint = (on, text, ...styles) => on ? `${styles.join("")}${text}${reset}` : text;
16
+ var supportsColor = (output) => {
17
+ const { NO_COLOR, FORCE_COLOR } = process.env;
18
+ if (NO_COLOR)
19
+ return false;
20
+ if (FORCE_COLOR)
21
+ return FORCE_COLOR !== "0" && FORCE_COLOR !== "false";
22
+ return output.isTTY === true;
23
+ };
24
+ var normalize = (value) => {
25
+ if (value instanceof Error)
26
+ return value.message;
27
+ if (value instanceof Date)
28
+ return value.toISOString();
29
+ if (typeof value === "bigint")
30
+ return value.toString();
31
+ return value;
32
+ };
33
+ var shaper = (replacer) => (key, value) => normalize(replacer ? replacer(key, value) : value);
34
+ var formatValue = (value) => {
35
+ if (value === null || value === undefined)
36
+ return "<nil>";
37
+ if (Array.isArray(value))
38
+ return `[${value.map(formatValue).join(" ")}]`;
39
+ if (typeof value === "string") {
40
+ return value === "" || /[\s="]/.test(value) ? JSON.stringify(value) : value;
41
+ }
42
+ if (typeof value === "object") {
43
+ try {
44
+ return JSON.stringify(value);
45
+ } catch {
46
+ return "[unserializable]";
47
+ }
48
+ }
49
+ return String(value);
50
+ };
51
+ var plain = (value, depth = 0) => {
52
+ if (typeof value === "bigint")
53
+ return false;
54
+ if (typeof value !== "object" || value === null)
55
+ return true;
56
+ if (value instanceof Error || depth > 8)
57
+ return false;
58
+ for (const item of Object.values(value)) {
59
+ if (!plain(item, depth + 1))
60
+ return false;
61
+ }
62
+ return true;
63
+ };
64
+ var pairs = (fields, replacer) => {
65
+ const shape = shaper(replacer);
66
+ const out = [];
67
+ const parents = new Set;
68
+ const walk = (node, path) => {
69
+ parents.add(node);
70
+ for (const [key, raw] of Object.entries(node)) {
71
+ const value = shape(key, raw);
72
+ const name = `${path}${key}`;
73
+ if (value == null)
74
+ continue;
75
+ if (Array.isArray(value)) {
76
+ out.push([name, value.filter((v) => v != null).map(normalize)]);
77
+ } else if (typeof value !== "object") {
78
+ out.push([name, value]);
79
+ } else if (parents.has(value)) {
80
+ out.push([name, "[circular]"]);
81
+ } else {
82
+ walk(value, `${name}.`);
83
+ }
84
+ }
85
+ parents.delete(node);
86
+ };
87
+ walk(fields, "");
88
+ return out;
89
+ };
90
+ var makeClock = (timeZone) => {
91
+ let format;
92
+ let second = Number.NaN;
93
+ let last = { day: "", time: "" };
94
+ return (date) => {
95
+ const now = Math.floor(date.getTime() / 1000);
96
+ if (now === second)
97
+ return last;
98
+ format ??= new Intl.DateTimeFormat("en-US", {
99
+ timeZone,
100
+ hourCycle: "h23",
101
+ year: "numeric",
102
+ month: "2-digit",
103
+ day: "2-digit",
104
+ hour: "2-digit",
105
+ minute: "2-digit",
106
+ second: "2-digit"
107
+ });
108
+ const p = Object.fromEntries(format.formatToParts(date).map(({ type, value }) => [type, value]));
109
+ second = now;
110
+ last = {
111
+ day: `${p.year}-${p.month}-${p.day}`,
112
+ time: `${p.hour}:${p.minute}:${p.second}`
113
+ };
114
+ return last;
115
+ };
116
+ };
117
+ var createLogger = (options = {}) => {
118
+ const {
119
+ prefix,
120
+ fields = {},
121
+ time = true,
122
+ timeZone,
123
+ format = "text",
124
+ output = process.stderr,
125
+ file,
126
+ replacer,
127
+ now = () => new Date
128
+ } = options;
129
+ let threshold = options.level ?? "info";
130
+ const color = options.color ?? supportsColor(output);
131
+ const clock = makeClock(timeZone);
132
+ const shape = shaper(replacer);
133
+ const madeDirs = new Set;
134
+ const toJson = (meta, merged) => {
135
+ const line = { ...meta, ...merged };
136
+ if (!replacer && plain(merged))
137
+ return JSON.stringify(line);
138
+ try {
139
+ return JSON.stringify(line, function(key, value) {
140
+ const own = key === "" || this === line && Object.hasOwn(meta, key) && !Object.hasOwn(merged, key);
141
+ return own ? value : shape(key, value);
142
+ });
143
+ } catch {
144
+ return JSON.stringify({
145
+ ...meta,
146
+ ...Object.fromEntries(pairs(merged, replacer))
147
+ });
148
+ }
149
+ };
150
+ const render = (level, msg, extra, date, colored) => {
151
+ const merged = { ...fields, ...extra };
152
+ const meta = {
153
+ time: date.toISOString(),
154
+ level,
155
+ ...prefix ? { prefix } : {},
156
+ msg
157
+ };
158
+ if (format === "json") {
159
+ return toJson(meta, merged);
160
+ }
161
+ const context = pairs(merged, replacer);
162
+ if (format === "logfmt") {
163
+ return [...Object.entries(meta), ...context].map(([key, value]) => `${key}=${formatValue(value)}`).join(" ");
164
+ }
165
+ const { label, color: code } = levels[level];
166
+ return [
167
+ time && clock(date).time,
168
+ paint(colored, label, bold, fg(code)),
169
+ prefix && paint(colored, `${prefix}:`, bold),
170
+ msg,
171
+ ...context.map(([key, value]) => `${paint(colored, key, faint)}=${formatValue(value)}`)
172
+ ].filter(Boolean).join(" ");
173
+ };
174
+ const append = (path, line) => {
175
+ const dir = dirname(path);
176
+ if (!madeDirs.has(dir)) {
177
+ mkdirSync(dir, { recursive: true });
178
+ madeDirs.add(dir);
179
+ }
180
+ appendFileSync(path, `${line}
181
+ `);
182
+ };
183
+ const write = (level, msg, extra) => {
184
+ if (levels[level].rank < levels[threshold].rank)
185
+ return;
186
+ const date = now();
187
+ output.write(`${render(level, msg, extra, date, color)}
188
+ `);
189
+ if (file) {
190
+ const path = typeof file === "function" ? file(clock(date).day) : file;
191
+ append(path, render(level, msg, extra, date, false));
192
+ }
193
+ };
194
+ const at = (level) => (msg, extra) => write(level, msg, extra);
195
+ const child = (overrides) => createLogger({ ...options, level: threshold, ...overrides });
196
+ return {
197
+ debug: at("debug"),
198
+ info: at("info"),
199
+ warn: at("warn"),
200
+ error: at("error"),
201
+ fatal: (msg, extra) => {
202
+ write("fatal", msg, extra);
203
+ return process.exit(1);
204
+ },
205
+ with: (more) => child({ fields: { ...fields, ...more } }),
206
+ withPrefix: (next) => child({ prefix: next }),
207
+ setLevel: (level) => {
208
+ threshold = level;
209
+ },
210
+ get level() {
211
+ return threshold;
212
+ }
213
+ };
214
+ };
215
+ var log = createLogger();
216
+ export {
217
+ createLogger,
218
+ formatValue,
219
+ log,
220
+ pairs
221
+ };
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "logosaur",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "A tiny, colorful, zero-dependency structured logger for Bun and TypeScript. Rawr.",
5
+ "keywords": [
6
+ "log",
7
+ "logger",
8
+ "logging",
9
+ "structured",
10
+ "logfmt",
11
+ "bun",
12
+ "typescript",
13
+ "color"
14
+ ],
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/0c71/logosaur.git"
19
+ },
20
+ "homepage": "https://github.com/0c71/logosaur#readme",
21
+ "bugs": "https://github.com/0c71/logosaur/issues",
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "sideEffects": false,
35
+ "scripts": {
36
+ "build": "bun build src/index.ts --outdir dist --target node && tsc -p tsconfig.build.json",
37
+ "test": "bun test",
38
+ "typecheck": "tsc --noEmit",
39
+ "prepublishOnly": "bun run typecheck && bun test && bun run build"
40
+ },
41
+ "devDependencies": {
42
+ "@types/bun": "^1.4.4",
43
+ "typescript": "^7.0.2"
44
+ }
45
+ }