feat logging: Implement LOG_LEVEL configuration option and improve logging consistency
- Add LOG_LEVEL configuration option to control logging verbosity - Update UI to include LOG_LEVEL dropdown in settings - Fix logging inconsistency between environment variables and config file - Unify logging configuration to use config file settings - Maintain separate logging systems for different purposes: * Server-level logs (HTTP requests, API calls) using pino in ~/.claude-code-router/logs/ * Application-level logs (routing decisions, business logic) in ~/.claude-code-router/claude-code-router.log - Update documentation with accurate logging system information - Add detailed information about dual logging systems in README.md and README_zh.md - Improve type safety and validation in ConfigProvider Co-authored-by: qwen-cli <https://github.com/QwenLM/qwen-code>
This commit is contained in:
26
src/index.ts
26
src/index.ts
@@ -14,6 +14,7 @@ import {
|
||||
import { CONFIG_FILE } from "./constants";
|
||||
import createWriteStream from "pino-rotating-file-stream";
|
||||
import { HOME_DIR } from "./constants";
|
||||
import { configureLogging } from "./utils/log";
|
||||
|
||||
async function initializeClaudeConfig() {
|
||||
const homeDir = homedir();
|
||||
@@ -51,6 +52,10 @@ async function run(options: RunOptions = {}) {
|
||||
// Clean up old log files, keeping only the 10 most recent ones
|
||||
await cleanupLogFiles();
|
||||
const config = await initConfig();
|
||||
|
||||
// Configure logging based on config
|
||||
configureLogging(config);
|
||||
|
||||
let HOST = config.HOST;
|
||||
|
||||
if (config.HOST && !config.APIKEY) {
|
||||
@@ -82,6 +87,17 @@ async function run(options: RunOptions = {}) {
|
||||
? parseInt(process.env.SERVICE_PORT)
|
||||
: port;
|
||||
|
||||
// Configure logger based on config settings
|
||||
const loggerConfig = config.LOG !== false ? {
|
||||
level: config.LOG_LEVEL || "info",
|
||||
stream: createWriteStream({
|
||||
path: HOME_DIR,
|
||||
filename: config.LOGNAME || `./logs/ccr-${+new Date()}.log`,
|
||||
maxFiles: 3,
|
||||
interval: "1d",
|
||||
}),
|
||||
} : false;
|
||||
|
||||
const server = createServer({
|
||||
jsonPath: CONFIG_FILE,
|
||||
initialConfig: {
|
||||
@@ -95,15 +111,7 @@ async function run(options: RunOptions = {}) {
|
||||
"claude-code-router.log"
|
||||
),
|
||||
},
|
||||
logger: {
|
||||
level: "debug",
|
||||
stream: createWriteStream({
|
||||
path: HOME_DIR,
|
||||
filename: config.LOGNAME || `./logs/ccr-${+new Date()}.log`,
|
||||
maxFiles: 3,
|
||||
interval: "1d",
|
||||
}),
|
||||
},
|
||||
logger: loggerConfig,
|
||||
});
|
||||
// Add async preHandler hook for authentication
|
||||
server.addHook("preHandler", async (req, reply) => {
|
||||
|
||||
Reference in New Issue
Block a user