Skip to content

feat: add log rotation support#7

Merged
devfeel merged 5 commits intoaicodefrom
aicode-rotator
Mar 16, 2026
Merged

feat: add log rotation support#7
devfeel merged 5 commits intoaicodefrom
aicode-rotator

Conversation

@devfeel
Copy link
Owner

@devfeel devfeel commented Mar 16, 2026

Summary

Add log rotation support for FileTarget and JSONTarget.

Changes

New Features

  • Add rotator.go with SizeRotator and TimeRotator implementations
  • Add rotation support to JSONTarget (was not implemented)
  • Add MaxBackups config option to control backup file cleanup
  • Add time-based rotation support (TimeRotator)

Bug Fixes

  • Fix FileTarget concurrency issue with sync.Mutex
  • Fix directory creation order (create dir before rotation check)

Configuration

Size-based Rotation (FileTarget)

targets:
  file:
    - name: FileLogger
      fileName: ./logs/app.log
      fileMaxSize: 10240  # KB
      maxBackups: 5        # keep 5 backup files

Size-based Rotation (JSONTarget)

targets:
  json:
    - name: JSONLogger
      fileName: ./logs/app.json
      fileMaxSize: 10240
      maxBackups: 5
      prettyPrint: true

Test Results

Item Status
Build ✅ Pass
Test ✅ Pass

Files Changed

  • targets/rotator.go (new)
  • targets/target_file.go
  • targets/target_json.go
  • config/config.go
  • config/json.go
  • config/yaml.go

🐾 Generated by OpenClaw AI Assistant

root added 5 commits March 16, 2026 10:15
- Update Version in const/const.go
- Add version history in version.md
- Add rotator.go with SizeRotator and TimeRotator
- Add rotation support to JSONTarget
- Fix FileTarget concurrency issue with mutex
- Add MaxBackups config option for file cleanup
- Add sync.Mutex to protect file write operations

Features:
- Size-based rotation with automatic backup cleanup
- Time-based rotation support
- Configurable max backup files to keep
- Check rotator.Rotate error return
- Check os.MkdirAll error return
- Add example/rotation/ with rotation demo
- Add rotation.yaml config with file rotation settings
- Demonstrate both FileTarget and JSONTarget rotation
- Update version in const/const.go
- Add version history in version.md
@devfeel devfeel merged commit e726604 into aicode Mar 16, 2026
2 checks passed
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.

1 participant