pi-extension-utils 0.3.3 → 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/dist/src/index.d.ts +1 -1
- package/dist/src/logger/index.d.ts +6 -1
- package/dist/src/logger/index.js +2 -2
- package/docs/client.md +1 -1
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { connect, type FullscreenComponentFactory, type FullscreenLease, type RemindersClient, type UtilsClient, type UtilsClientOptions, type WidgetSetOptions } from "./client/index.ts";
|
|
2
2
|
export { defineConfig, type DeepPartial, type DefinedConfig, type DefineConfigOptions } from "./config/index.ts";
|
|
3
|
-
export { createLogger, LOG_LEVELS, loggerLevelSchema, loggingConfigSchema, type Logger, type LoggerLevel, type LoggerOptions, type LoggingConfig, type LogLevel } from "./logger/index.ts";
|
|
3
|
+
export { createLogger, LOG_LEVELS, loggerLevelSchema, loggingConfigSchema, type Logger, type LoggerLevel, type LoggerOptions, type LoggerRecord, type LoggingConfig, type LogLevel } from "./logger/index.ts";
|
|
4
4
|
export { utilsConfigSchema, type UtilsConfig } from "./utils-config.ts";
|
|
5
5
|
export * from "./pane/key-dispatch.ts";
|
|
6
6
|
export * from "./pane/state.ts";
|
|
@@ -3,7 +3,7 @@ export { LOG_LEVELS, loggerLevelSchema, loggingConfigSchema, type LoggerLevel, t
|
|
|
3
3
|
export interface LoggerOptions {
|
|
4
4
|
dir?: string;
|
|
5
5
|
maxBytes?: number;
|
|
6
|
-
/** Number of rotated files to retain: name.
|
|
6
|
+
/** Number of rotated files to retain: name.jsonl.1, name.jsonl.2, ... */
|
|
7
7
|
maxFiles?: number;
|
|
8
8
|
/** Minimum level to write. Defaults to utilsConfig.logging.level. */
|
|
9
9
|
level?: LoggerLevel;
|
|
@@ -17,4 +17,9 @@ export interface Logger {
|
|
|
17
17
|
setLevel(level: LoggerLevel): void;
|
|
18
18
|
isEnabled(level: LogLevel): boolean;
|
|
19
19
|
}
|
|
20
|
+
export interface LoggerRecord {
|
|
21
|
+
ts: string;
|
|
22
|
+
level: LogLevel;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
20
25
|
export declare function createLogger(name: string, opts?: LoggerOptions): Logger;
|
package/dist/src/logger/index.js
CHANGED
|
@@ -21,7 +21,7 @@ export function createLogger(name, opts = {}) {
|
|
|
21
21
|
const maxBytes = Math.max(0, Math.floor(opts.maxBytes ?? configured?.maxBytes ?? 1024 * 1024));
|
|
22
22
|
const maxFiles = Math.max(0, Math.floor(opts.maxFiles ?? configured?.maxFiles ?? 3));
|
|
23
23
|
let level = opts.level ?? configured?.level ?? "info";
|
|
24
|
-
const file = join(dir, `${name}.
|
|
24
|
+
const file = join(dir, `${name}.jsonl`);
|
|
25
25
|
mkdirSync(dirname(file), { recursive: true });
|
|
26
26
|
function rotateIfNeeded(nextBytes) {
|
|
27
27
|
if (maxBytes <= 0 || !existsSync(file))
|
|
@@ -49,7 +49,7 @@ export function createLogger(name, opts = {}) {
|
|
|
49
49
|
function log(candidate, message) {
|
|
50
50
|
if (!isEnabled(candidate))
|
|
51
51
|
return;
|
|
52
|
-
const line = `${new Date().toISOString()
|
|
52
|
+
const line = `${JSON.stringify({ ts: new Date().toISOString(), level: candidate, message })}\n`;
|
|
53
53
|
mkdirSync(dirname(file), { recursive: true });
|
|
54
54
|
rotateIfNeeded(Buffer.byteLength(line));
|
|
55
55
|
appendFileSync(file, line);
|
package/docs/client.md
CHANGED
|
@@ -82,7 +82,7 @@ log.warn("slow path");
|
|
|
82
82
|
log.error("failed");
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
`createLogger(name)` writes to `getAgentDir()/log/<name>.
|
|
85
|
+
`createLogger(name)` writes JSONL to `getAgentDir()/log/<name>.jsonl` by default. Each line is `{"ts":"...","level":"info","message":"started"}`. `level` is typed as `"debug" | "info" | "warn" | "error" | "silent"`; `maxFiles` controls retained rotations (`.1`, `.2`, ...). If `level`, `maxFiles`, or `maxBytes` are omitted, the value comes from `getAgentDir()/config/utils.jsonc` `logging` defaults. Explicit options always win.
|
|
86
86
|
|
|
87
87
|
Override when needed:
|
|
88
88
|
|