Skip to content

默认日志无轮转且写入当前工作目录,实测产生 764MB model.log #157

Description

@SongshGeo

现象

框架默认把模型日志写进当前工作目录,且不轮转、不清理。本仓库根目录实测:

-rw-r--r--  764M  model.log
-rw-r--r--  515K  experiment.log

证据

abses/conf/absespy.yaml 的默认值:

log:
  run:
    file:
      enabled: true        # ← 默认开
      name: model
      rotation: null       # ← 默认不轮转
      retention: null      # ← 默认不清理

输出目录在没有 outpath 时回落到 Path.cwd()abses/utils/exp_logging.py):

if outpath is None:
    outpath = Path.cwd()

体积主因是逐 tick 记录的 mesa INFO 日志:

[21:55:48][MESA.mesa.model][INFO] - calling model.step for timestep 1
[21:55:48][MESA.mesa.model][INFO] - calling model.step for timestep 2
...

轮转能力其实已经实现(abses/utils/log_config.pycreate_file_handler 支持 TimedRotatingFileHandler / RotatingFileHandler),只是默认关着。

仓库里追踪着的 remove-logs.sh(交互式删除所有 *.log)本质上就是这个问题的创可贴。

影响

  • 长时间批量实验会在用户的工作目录里堆出 GB 级文件,且没有任何提示。
  • 日志写到 CWD 而不是实验输出目录,多次实验的日志会互相追加混在一起。
  • mesa 的逐步 INFO 日志对绝大多数用户没有价值,却贡献了绝大部分体积。

建议方案(需要定夺,因为是默认值变更)

  1. rotation 一个默认值,例如 100 MB + retention: 5,让最坏情况有上界。
  2. 默认不捕获 mesa 的逐步日志:把 log.run.mesa.level 默认设为 WARNING,想看的人显式调低。
  3. 默认写到实验输出目录而非 CWDoutpath 为空时回落到 out/ 而不是 Path.cwd();至少在回落到 CWD 时打一条 warning 说明文件写到哪了。

三条里 (2) 收益最大、风险最小,(1) 是兜底,(3) 属于行为变更需要写进 changelog。

验收标准

  • 跑 100 万 tick 的模型,默认配置下日志总大小有明确上界。
  • 默认配置下 model.log 里不再有逐 tick 的 calling model.step 记录。
  • 文档里说明默认日志落在哪个目录、如何关闭、如何配置轮转。
  • 新增测试:rotation 生效时确实产生了轮转文件。

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions