@vllnt/logger 0.1.2 → 0.1.3-canary.90f2d33
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 +36 -16
- package/dist/{chunk-5GDAMA7T.js → chunk-ZXUJ3U24.js} +55 -20
- package/dist/convex.d.ts +1 -1
- package/dist/convex.js +1 -1
- package/dist/{core-BKAGZb-m.d.ts → core-he_ASnDU.d.ts} +11 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/posthog.d.ts +6 -4
- package/dist/posthog.js +8 -1
- package/dist/testing.d.ts +3 -2
- package/package.json +39 -25
package/README.md
CHANGED
|
@@ -27,12 +27,12 @@ Set `LOG_LEVEL` env var to control verbosity (`debug`, `info`, `warn`, `error`).
|
|
|
27
27
|
|
|
28
28
|
## Subpath Exports
|
|
29
29
|
|
|
30
|
-
| Import
|
|
31
|
-
|
|
32
|
-
| `@vllnt/logger`
|
|
33
|
-
| `@vllnt/logger/convex`
|
|
34
|
-
| `@vllnt/logger/posthog` | PostHog output adapter
|
|
35
|
-
| `@vllnt/logger/testing` | In-memory test output for assertions
|
|
30
|
+
| Import | Use Case |
|
|
31
|
+
| ----------------------- | ------------------------------------- |
|
|
32
|
+
| `@vllnt/logger` | Core API + Node.js backend preset |
|
|
33
|
+
| `@vllnt/logger/convex` | Convex-safe logger (no `process.env`) |
|
|
34
|
+
| `@vllnt/logger/posthog` | PostHog output adapter |
|
|
35
|
+
| `@vllnt/logger/testing` | In-memory test output for assertions |
|
|
36
36
|
|
|
37
37
|
## API
|
|
38
38
|
|
|
@@ -97,7 +97,7 @@ logger.info("started");
|
|
|
97
97
|
|
|
98
98
|
### `createPostHogOutput(capture): LogOutput`
|
|
99
99
|
|
|
100
|
-
Wraps a PostHog-compatible `capture` function as a `LogOutput`. Swallows errors.
|
|
100
|
+
Wraps a PostHog-compatible `capture` function as a `LogOutput`. Swallows thrown errors and rejected promises.
|
|
101
101
|
|
|
102
102
|
```ts
|
|
103
103
|
import { createPostHogOutput } from "@vllnt/logger/posthog";
|
|
@@ -125,21 +125,29 @@ expect(entries[0].event).toBe("test.hello");
|
|
|
125
125
|
|
|
126
126
|
### Utilities
|
|
127
127
|
|
|
128
|
-
| Function
|
|
129
|
-
|
|
130
|
-
| `formatLogEntry(level, event, data?)` | Build a `LogEntry` manually
|
|
131
|
-
| `parseLogLevel(value, default?)`
|
|
132
|
-
| `consoleOutput(entry)`
|
|
128
|
+
| Function | Description |
|
|
129
|
+
| ------------------------------------- | ---------------------------------------------------- |
|
|
130
|
+
| `formatLogEntry(level, event, data?)` | Build a `LogEntry` manually |
|
|
131
|
+
| `parseLogLevel(value, default?)` | Safe `string` to `LogLevel` parsing |
|
|
132
|
+
| `consoleOutput(entry)` | JSON to `console.debug/info/warn/error` (crash-safe) |
|
|
133
133
|
|
|
134
134
|
## Types
|
|
135
135
|
|
|
136
136
|
```ts
|
|
137
137
|
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
138
138
|
type LogData = Record<string, unknown>;
|
|
139
|
-
type LogEntry = { event: string; level: LogLevel; timestamp: string } & Record<
|
|
139
|
+
type LogEntry = { event: string; level: LogLevel; timestamp: string } & Record<
|
|
140
|
+
string,
|
|
141
|
+
unknown
|
|
142
|
+
>;
|
|
140
143
|
type LogOutput = (entry: LogEntry) => void;
|
|
141
|
-
type Logger = {
|
|
142
|
-
|
|
144
|
+
type Logger = {
|
|
145
|
+
debug;
|
|
146
|
+
info;
|
|
147
|
+
warn;
|
|
148
|
+
error: (event: string, data?: LogData) => void;
|
|
149
|
+
};
|
|
150
|
+
type ExtendedLogger = Logger & { withTiming; withTimingSync };
|
|
143
151
|
type LoggerConfig = { getLogLevel: () => LogLevel; output: LogOutput };
|
|
144
152
|
```
|
|
145
153
|
|
|
@@ -147,11 +155,23 @@ type LoggerConfig = { getLogLevel: () => LogLevel; output: LogOutput };
|
|
|
147
155
|
|
|
148
156
|
- **Scoped events**: All events are prefixed with the logger scope (`auth.login`, `payments.charge`)
|
|
149
157
|
- **Reserved field protection**: User data cannot overwrite `event`, `level`, or `timestamp`
|
|
150
|
-
- **
|
|
158
|
+
- **Log calls never throw**: a failing `getLogLevel`, output, or data getter is swallowed; an invalid level falls back to `info`
|
|
159
|
+
- **Crash-safe serialization**: `consoleOutput` writes `BigInt` as a string, `Error` as `{ name, message, stack }`, and circular refs as `"[Circular]"`; a throwing `toJSON` degrades to a minimal `event`/`level` line
|
|
160
|
+
- **No built-in redaction**: pass only data you are willing to log. `withTiming` logs `error.message` verbatim, so sanitize sensitive errors before throwing them
|
|
151
161
|
- **Synchronous outputs**: `LogOutput` is synchronous by design — async adapters manage their own promises
|
|
152
162
|
- **Lazy level evaluation**: `getLogLevel()` is called per-emit, so env changes are picked up without restart
|
|
153
163
|
- **Zero side effects**: Core module has zero module-level side effects (`sideEffects: false`)
|
|
154
164
|
|
|
165
|
+
## Releases
|
|
166
|
+
|
|
167
|
+
Every publish runs in `.github/workflows/publish.yml` with npm trusted publishing and provenance;
|
|
168
|
+
nothing is published from a local machine. Maintainers only.
|
|
169
|
+
|
|
170
|
+
- Canary (`@canary`): every push to `main` that touches the package publishes one
|
|
171
|
+
(`pnpm add @vllnt/logger@canary`).
|
|
172
|
+
- Stable (`@latest`): merge a PR that sets `package.json` `version` and adds a matching
|
|
173
|
+
`## [X.Y.Z]` entry to `CHANGELOG.md`, then push the tag `vX.Y.Z` on that `main` commit.
|
|
174
|
+
|
|
155
175
|
## License
|
|
156
176
|
|
|
157
177
|
[MIT](LICENSE)
|
|
@@ -23,10 +23,20 @@ function formatLogEntry(level, event, data) {
|
|
|
23
23
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
function resolveLevel(config) {
|
|
27
|
+
try {
|
|
28
|
+
return parseLogLevel(config.getLogLevel(), "info");
|
|
29
|
+
} catch {
|
|
30
|
+
return "info";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
26
33
|
function createLogger(scope, config) {
|
|
27
34
|
const log = (level, event, data) => {
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
try {
|
|
36
|
+
if (shouldLog(level, resolveLevel(config))) {
|
|
37
|
+
config.output(formatLogEntry(level, `${scope}.${event}`, data));
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
30
40
|
}
|
|
31
41
|
};
|
|
32
42
|
return {
|
|
@@ -45,7 +55,11 @@ function createLogger(scope, config) {
|
|
|
45
55
|
};
|
|
46
56
|
}
|
|
47
57
|
function formatError(error) {
|
|
48
|
-
|
|
58
|
+
try {
|
|
59
|
+
return error instanceof Error ? error.message : String(error);
|
|
60
|
+
} catch {
|
|
61
|
+
return "[unprintable error]";
|
|
62
|
+
}
|
|
49
63
|
}
|
|
50
64
|
function createWithTiming(base) {
|
|
51
65
|
return async (label, execute, extraData) => {
|
|
@@ -97,29 +111,50 @@ function createExtendedLogger(scope, config) {
|
|
|
97
111
|
withTimingSync: createWithTimingSync(base)
|
|
98
112
|
};
|
|
99
113
|
}
|
|
114
|
+
function createReplacer() {
|
|
115
|
+
const ancestors = [];
|
|
116
|
+
return function replacer(_key, value) {
|
|
117
|
+
if (typeof value === "bigint") {
|
|
118
|
+
return value.toString();
|
|
119
|
+
}
|
|
120
|
+
const resolved = value instanceof Error ? { message: value.message, name: value.name, stack: value.stack } : value;
|
|
121
|
+
if (typeof resolved !== "object" || resolved === null) {
|
|
122
|
+
return resolved;
|
|
123
|
+
}
|
|
124
|
+
ancestors.splice(ancestors.indexOf(this) + 1);
|
|
125
|
+
if (ancestors.includes(resolved)) {
|
|
126
|
+
return "[Circular]";
|
|
127
|
+
}
|
|
128
|
+
ancestors.push(resolved);
|
|
129
|
+
return resolved;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
100
132
|
function consoleOutput(entry) {
|
|
101
133
|
let message;
|
|
102
134
|
try {
|
|
103
|
-
message = JSON.stringify(entry);
|
|
135
|
+
message = JSON.stringify(entry, createReplacer());
|
|
104
136
|
} catch {
|
|
105
137
|
message = `[logger:serialize-error] event=${entry.event} level=${entry.level}`;
|
|
106
138
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
139
|
+
try {
|
|
140
|
+
switch (entry.level) {
|
|
141
|
+
case "debug":
|
|
142
|
+
console.debug(message);
|
|
143
|
+
break;
|
|
144
|
+
case "error":
|
|
145
|
+
console.error(message);
|
|
146
|
+
break;
|
|
147
|
+
case "info":
|
|
148
|
+
console.info(message);
|
|
149
|
+
break;
|
|
150
|
+
case "warn":
|
|
151
|
+
console.warn(message);
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
console.info(message);
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
} catch {
|
|
123
158
|
}
|
|
124
159
|
}
|
|
125
160
|
function composeOutputs(...outputs) {
|
package/dist/convex.d.ts
CHANGED
package/dist/convex.js
CHANGED
|
@@ -41,7 +41,12 @@ declare function parseLogLevel(value: string | undefined, defaultLevel?: LogLeve
|
|
|
41
41
|
* This prevents user data from overwriting event/level/timestamp.
|
|
42
42
|
*/
|
|
43
43
|
declare function formatLogEntry(level: LogLevel, event: string, data?: LogData): LogEntry;
|
|
44
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Create a scoped logger with the given configuration.
|
|
46
|
+
*
|
|
47
|
+
* Log calls never throw: a failing `getLogLevel`, `output`, or data getter is
|
|
48
|
+
* swallowed so logging cannot break the host application.
|
|
49
|
+
*/
|
|
45
50
|
declare function createLogger(scope: string, config: LoggerConfig): Logger;
|
|
46
51
|
/**
|
|
47
52
|
* Create an extended logger with timing helpers.
|
|
@@ -51,11 +56,13 @@ declare function createLogger(scope: string, config: LoggerConfig): Logger;
|
|
|
51
56
|
*/
|
|
52
57
|
declare function createExtendedLogger(scope: string, config: LoggerConfig): ExtendedLogger;
|
|
53
58
|
/**
|
|
54
|
-
* Default console output handler.
|
|
55
|
-
*
|
|
59
|
+
* Default console output handler. Never throws. It handles BigInt, Error and
|
|
60
|
+
* circular values; anything still unserializable (throwing toJSON or getters)
|
|
61
|
+
* degrades to a minimal event/level line, and console failures disappear.
|
|
56
62
|
*/
|
|
57
63
|
declare function consoleOutput(entry: LogEntry): void;
|
|
58
64
|
/** Compose outputs into a single LogOutput. Each output runs in isolation. */
|
|
59
65
|
declare function composeOutputs(...outputs: LogOutput[]): LogOutput;
|
|
60
66
|
|
|
61
|
-
export {
|
|
67
|
+
export { composeOutputs as f, consoleOutput as g, createExtendedLogger as h, createLogger as i, formatLogEntry as j, parseLogLevel as p };
|
|
68
|
+
export type { ExtendedLogger as E, LogLevel as L, LogData as a, LogEntry as b, LogOutput as c, Logger as d, LoggerConfig as e };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as ExtendedLogger } from './core-
|
|
2
|
-
export {
|
|
1
|
+
import { E as ExtendedLogger } from './core-he_ASnDU.js';
|
|
2
|
+
export { a as LogData, b as LogEntry, L as LogLevel, c as LogOutput, d as Logger, e as LoggerConfig, f as composeOutputs, g as consoleOutput, h as createExtendedLogger, i as createLogger, j as formatLogEntry, p as parseLogLevel } from './core-he_ASnDU.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @vllnt/logger — Backend preset.
|
package/dist/index.js
CHANGED
package/dist/posthog.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogOutput } from './index.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @vllnt/logger — PostHog output adapter.
|
|
@@ -8,11 +8,13 @@ import { c as LogOutput } from './core-BKAGZb-m.js';
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/** PostHog-compatible capture function signature */
|
|
11
|
-
type PostHogCapture = (event: string, properties?: Record<string, unknown>) =>
|
|
11
|
+
type PostHogCapture = (event: string, properties?: Record<string, unknown>) => unknown;
|
|
12
12
|
/**
|
|
13
13
|
* Create a LogOutput that forwards entries to PostHog.
|
|
14
|
-
* Swallows errors from the capture function
|
|
14
|
+
* Swallows errors from the capture function, including rejected promises it
|
|
15
|
+
* returns — logging must not break the app.
|
|
15
16
|
*/
|
|
16
17
|
declare function createPostHogOutput(capture: PostHogCapture): LogOutput;
|
|
17
18
|
|
|
18
|
-
export {
|
|
19
|
+
export { createPostHogOutput };
|
|
20
|
+
export type { PostHogCapture };
|
package/dist/posthog.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
// src/posthog.ts
|
|
2
|
+
function isThenable(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
4
|
+
}
|
|
2
5
|
function createPostHogOutput(capture) {
|
|
3
6
|
return (entry) => {
|
|
4
7
|
try {
|
|
5
8
|
const { event, ...properties } = entry;
|
|
6
|
-
capture(event, properties);
|
|
9
|
+
const result = capture(event, properties);
|
|
10
|
+
if (isThenable(result)) {
|
|
11
|
+
Promise.resolve(result).catch(() => {
|
|
12
|
+
});
|
|
13
|
+
}
|
|
7
14
|
} catch {
|
|
8
15
|
}
|
|
9
16
|
};
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogEntry, LogOutput } from './index.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @vllnt/logger — Test utilities.
|
|
@@ -14,4 +14,5 @@ type TestOutput = {
|
|
|
14
14
|
/** Create a test output that captures entries into an array for assertion. */
|
|
15
15
|
declare function createTestOutput(): TestOutput;
|
|
16
16
|
|
|
17
|
-
export {
|
|
17
|
+
export { createTestOutput };
|
|
18
|
+
export type { TestOutput };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/logger",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3-canary.90f2d33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Structured logging for the @vllnt ecosystem",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,45 +12,59 @@
|
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
17
|
},
|
|
18
18
|
"./convex": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"types": "./dist/convex.d.ts",
|
|
20
|
+
"import": "./dist/convex.js"
|
|
21
21
|
},
|
|
22
22
|
"./posthog": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"types": "./dist/posthog.d.ts",
|
|
24
|
+
"import": "./dist/posthog.js"
|
|
25
25
|
},
|
|
26
26
|
"./testing": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"types": "./dist/testing.d.ts",
|
|
28
|
+
"import": "./dist/testing.js"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"check-types": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/check-types.tsbuildinfo",
|
|
37
|
+
"lint": "eslint --cache --cache-location node_modules/.cache/eslint/ --max-warnings 0",
|
|
38
|
+
"lint:fix": "eslint --cache --cache-location node_modules/.cache/eslint/ --fix",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:watch": "vitest"
|
|
41
|
+
},
|
|
34
42
|
"publishConfig": {
|
|
35
43
|
"access": "public",
|
|
36
44
|
"registry": "https://registry.npmjs.org/"
|
|
37
45
|
},
|
|
38
46
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"@vllnt/eslint-config": "^
|
|
41
|
-
"@vllnt/typescript": "^
|
|
42
|
-
"eslint": "^9.39.
|
|
43
|
-
"prettier": "^3.
|
|
44
|
-
"tsup": "^
|
|
45
|
-
"typescript": "^
|
|
46
|
-
"vitest": "^
|
|
47
|
+
"@types/node": "^26.6.5",
|
|
48
|
+
"@vllnt/eslint-config": "^2.0.0",
|
|
49
|
+
"@vllnt/typescript": "^2.0.0",
|
|
50
|
+
"eslint": "^9.39.5",
|
|
51
|
+
"prettier": "^3.9.10",
|
|
52
|
+
"tsup": "^9.0.0",
|
|
53
|
+
"typescript": "^6.0.3",
|
|
54
|
+
"vitest": "^5.0.5"
|
|
47
55
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
56
|
+
"packageManager": "pnpm@10.34.8",
|
|
57
|
+
"pnpm": {
|
|
58
|
+
"minimumReleaseAge": 10080,
|
|
59
|
+
"minimumReleaseAgeExclude": [
|
|
60
|
+
"@vllnt/*"
|
|
61
|
+
],
|
|
62
|
+
"ignoredBuiltDependencies": [
|
|
63
|
+
"esbuild"
|
|
64
|
+
],
|
|
65
|
+
"overrides": {
|
|
66
|
+
"deepmerge-ts@<8.0.0": "^8.0.0",
|
|
67
|
+
"handlebars@<4.7.10": "^4.7.10"
|
|
68
|
+
}
|
|
55
69
|
}
|
|
56
|
-
}
|
|
70
|
+
}
|