mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 08:45:50 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,77 +1,81 @@
|
||||
import pino from "pino";
|
||||
import { join } from "node:path";
|
||||
import { mkdirSync, existsSync } from "node:fs";
|
||||
import pino from 'pino'
|
||||
import { join } from 'node:path'
|
||||
import { mkdirSync, existsSync } from 'node:fs'
|
||||
|
||||
let rootLogger: pino.Logger;
|
||||
let rootLogger: pino.Logger
|
||||
|
||||
export interface LoggerConfig {
|
||||
debug: boolean;
|
||||
logDir?: string;
|
||||
debug: boolean
|
||||
logDir?: string
|
||||
}
|
||||
|
||||
/** Pretty-print config for console output */
|
||||
const PRETTY_CONFIG = {
|
||||
colorize: true,
|
||||
translateTime: "SYS:HH:MM:ss.l",
|
||||
ignore: "pid,hostname",
|
||||
} as const;
|
||||
translateTime: 'SYS:HH:MM:ss.l',
|
||||
ignore: 'pid,hostname',
|
||||
} as const
|
||||
|
||||
export function initLogger(config: LoggerConfig): pino.Logger {
|
||||
const { debug, logDir } = config;
|
||||
const { debug, logDir } = config
|
||||
|
||||
if (debug) {
|
||||
const dir = logDir || join(process.cwd(), ".acp-proxy");
|
||||
const dir = logDir || join(process.cwd(), '.acp-proxy')
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const timestamp = now.toISOString()
|
||||
.replace(/T/, "_")
|
||||
.replace(/:/g, "-")
|
||||
.replace(/\..+/, "");
|
||||
const logFile = join(dir, `acp-proxy-${timestamp}.log`);
|
||||
const now = new Date()
|
||||
const timestamp = now
|
||||
.toISOString()
|
||||
.replace(/T/, '_')
|
||||
.replace(/:/g, '-')
|
||||
.replace(/\..+/, '')
|
||||
const logFile = join(dir, `acp-proxy-${timestamp}.log`)
|
||||
|
||||
// Debug mode: JSON to file + pretty to console (multistream)
|
||||
rootLogger = pino(
|
||||
{
|
||||
level: "trace",
|
||||
level: 'trace',
|
||||
timestamp: pino.stdTimeFunctions.isoTime,
|
||||
},
|
||||
pino.transport({
|
||||
targets: [
|
||||
{ target: "pino/file", options: { destination: logFile } },
|
||||
{ target: "pino-pretty", options: { ...PRETTY_CONFIG, destination: 1 } },
|
||||
{ target: 'pino/file', options: { destination: logFile } },
|
||||
{
|
||||
target: 'pino-pretty',
|
||||
options: { ...PRETTY_CONFIG, destination: 1 },
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
)
|
||||
|
||||
console.log(`📝 Debug logging enabled: ${logFile}`);
|
||||
console.log(`📝 Debug logging enabled: ${logFile}`)
|
||||
} else {
|
||||
rootLogger = pino(
|
||||
{ level: "info", timestamp: pino.stdTimeFunctions.isoTime },
|
||||
{ level: 'info', timestamp: pino.stdTimeFunctions.isoTime },
|
||||
pino.transport({
|
||||
target: "pino-pretty",
|
||||
target: 'pino-pretty',
|
||||
options: { ...PRETTY_CONFIG, destination: 1 },
|
||||
}),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
return rootLogger;
|
||||
return rootLogger
|
||||
}
|
||||
|
||||
/** Get the root logger (auto-creates a default one if not initialized). */
|
||||
export function getLogger(): pino.Logger {
|
||||
if (!rootLogger) {
|
||||
rootLogger = pino(
|
||||
{ level: "info" },
|
||||
{ level: 'info' },
|
||||
pino.transport({
|
||||
target: "pino-pretty",
|
||||
target: 'pino-pretty',
|
||||
options: { ...PRETTY_CONFIG, destination: 1 },
|
||||
}),
|
||||
);
|
||||
)
|
||||
}
|
||||
return rootLogger;
|
||||
return rootLogger
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,5 +83,5 @@ export function getLogger(): pino.Logger {
|
||||
* Usage: `const log = createLogger("agent"); log.info({ pid }, "spawned")`
|
||||
*/
|
||||
export function createLogger(module: string): pino.Logger {
|
||||
return getLogger().child({ module });
|
||||
return getLogger().child({ module })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user