Skip to content

Conversation

@Miss-you
Copy link
Contributor

@Miss-you Miss-you commented Nov 11, 2025

Logging 功能方案概述

在配置层新增 logging.levels:Config 增加 LoggingConfig,允许用户在 ~/.kimi/config.json 中声明 模块前缀 -> 日志级别 映射。模块名会被裁剪+小写化,级别在载入时校验,保证默认行为兼容。
CLI 提供 -L/--log-level:Typer 入口接受重复参数,支持 LEVEL(默认域)和 module=LEVEL(大小写不敏感)。CLI 启动时合并配置和命令行覆盖,--debug 仍然把默认级别提升到 TRACE。
日志初始化重写:configure_file_logging 创建单一 loguru sink,并挂上 _ModuleLevelFilter。过滤器根据源码路径推导模块名,按最长前缀匹配决定阈值,未命中时落在 default;还会自动创建 ~/.kimi/logs。
Runtime 复用配置:KimiCLI.create 接受外部传入的 Config,避免重复加载,确保日志设置贯穿 CLI 生命周期。
文档与校验:README 新增 “Logging configuration” 章节说明 CLI/配置用法,任务文档写明验证步骤。新增 tests/test_logging_levels.py 验证解析与过滤逻辑,tests/test_config.py 更新默认配置快照;make check/test 融合新行为。

代码改动位置

src/kimi_cli/config.py: 添加 LoggingConfig 与验证逻辑,Config 默认值包含 logging。
src/kimi_cli/utils/logging.py: 新增 configure_file_logging、_ModuleLevelFilter 等核心实现,支持大小写无关和前缀匹配。
src/kimi_cli/cli.py: Typer 入口插入 --log-level 选项、合并配置、调用 configure_file_logging,并在错误时抛出 typer.BadParameter。
src/kimi_cli/app.py: KimiCLI.create 允许传入已有 Config。
文档、任务说明、测试文件等同步更新,确保功能可见且覆盖完整。


Logging function solution overview

Added logging.levels:Config in the configuration layer. Added LoggingConfig to allow users to declare module prefix -> log level mapping in ~/.kimi/config.json. The module name will be truncated + lowercase, and the level will be verified when loading to ensure that the default behavior is compatible.
CLI provides -L/--log-level: Typer entry accepts repeated parameters and supports LEVEL (default domain) and module=LEVEL (case-insensitive). CLI startup merges configuration and command line overrides, --debug still raises the default level to TRACE.
Log initialization rewrite: configure_file_logging creates a single loguru sink and mounts _ModuleLevelFilter. The filter deduces the module name based on the source code path, and determines the threshold based on the longest prefix match. If it misses, it falls to default; ~/.kimi/logs will also be automatically created.
Runtime reuse configuration: KimiCLI.create accepts external incoming Config to avoid repeated loading and ensure that log settings last throughout the CLI life cycle.
Documentation and verification: README adds a new "Logging configuration" chapter to explain CLI/configuration usage, and the task document describes verification steps. Added tests/test_logging_levels.py to verify parsing and filtering logic, tests/test_config.py to update the default configuration snapshot; make check/test to integrate new behaviors.

Code change location

src/kimi_cli/config.py: Add LoggingConfig and verification logic. The default value of Config includes logging.
src/kimi_cli/utils/logging.py: Added core implementations such as configure_file_logging and _ModuleLevelFilter to support case-independence and prefix matching.
src/kimi_cli/cli.py: Typer entry inserts the --log-level option, merges configurations, calls configure_file_logging, and throws typer.BadParameter on error.
src/kimi_cli/app.py: KimiCLI.create allows passing in existing Config.
Documents, task descriptions, test files, etc. are updated simultaneously to ensure that functions are visible and fully covered.

- add logging schema/config validation so ~/.kimi/config.json can persist levels
- introduce -L/--log-level CLI overrides and share loaded config with runtime
- implement loguru filter for per-module thresholds, update docs/tests
Copilot AI review requested due to automatic review settings November 11, 2025 15:53
Copilot finished reviewing on behalf of Miss-you November 11, 2025 15:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements configurable logging levels for the Kimi CLI, allowing users to set different log levels for different modules through both configuration files and command-line options.

  • Adds support for per-module log level configuration via ~/.kimi/config.json and CLI flags
  • Implements a filtering mechanism that respects module hierarchies (more specific prefixes override general ones)
  • Provides comprehensive test coverage for the new logging functionality

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/kimi_cli/utils/logging.py Implements core logging configuration functionality including file logging setup, level normalization, and module-based filtering
src/kimi_cli/config.py Adds LoggingConfig class with validation for log level configuration in the config file
src/kimi_cli/cli.py Adds --log-level/-L CLI option, merges config and CLI logging settings, and passes configuration to the app
src/kimi_cli/app.py Updates KimiCLI.create() to accept an optional preloaded Config parameter to avoid double-loading
tests/test_logging_levels.py Adds comprehensive tests for log level parsing and module-based filtering behavior
tests/test_config.py Updates config tests to include the new LoggingConfig field in expected outputs
README.md Documents the new logging configuration feature with examples for both CLI and config file usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Miss-you Miss-you changed the title WIP: Fixme logging levels feat: allow per-module log level overrides Nov 12, 2025
@stdrc
Copy link
Collaborator

stdrc commented Nov 18, 2025

This solution looks too complex to me😱

@stdrc
Copy link
Collaborator

stdrc commented Nov 18, 2025

Let's use the least lines of code to accomplish similar level of functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants