-
Notifications
You must be signed in to change notification settings - Fork 3
File Rotation
This page explains how logme keeps file logs manageable in long-running applications.
There are two related but separate mechanisms:
-
FileBackendrotation and part cleanup - home directory size monitoring through
DirectorySizeWatchdog
They solve different problems and can be used together.
FileBackend writes log records to disk using an internal queue and a file-manager thread.
It supports file naming, append mode, size control, daily rotation, and cleanup of old parts.
A typical file backend entry looks like this:
{
"type": "FileBackend",
"file": "logs/app.log",
"append": true,
"rotation": "daily",
"max-parts": 14
}The file value is processed through logme path/template handling.
If the resulting path is relative, it is resolved relative to the logger home directory.
See File Backend and Configuration JSON.
max-size limits the physical size of the log file:
{
"type": "FileBackend",
"file": "logs/app.log",
"max-size": "100MB"
}This is a file backend setting. It is not the same thing as limiting the total size of a log directory.
Daily rotation creates a new part when the day changes:
{
"type": "FileBackend",
"file": "logs/app.log",
"rotation": "daily"
}When daily rotation is enabled, the backend forces append mode internally.
This avoids overwriting existing log content when a new process starts during the same day.
max-parts limits how many matching rotated parts are kept:
{
"type": "FileBackend",
"file": "logs/app.log",
"rotation": "daily",
"max-parts": 7
}Cleanup is applied after a part change or rotation.
The backend matches files produced from the same file-name template and removes older parts beyond the configured limit.
Use this when you want to keep a fixed number of rotated log files.
DirectorySizeWatchdog works at the logger home directory level.
It is configured through the home-directory section:
{
"home-directory": {
"path": "logs",
"watch-dog": {
"enable": true,
"max-size": "10GB",
"check-periodicity": "30s",
"file-extension": [".log"]
}
}
}The watchdog monitors total directory size and removes old files when the configured limit is exceeded.
This is different from max-parts:
-
max-partskeeps only a fixed number of parts for one file backend pattern - the watchdog controls total disk usage in the logging directory
The watchdog consults the file manager before deleting files, so active files used by registered file backends are not removed.
Use daily rotation when log files should naturally split by date.
Use max-parts when each backend should retain only a fixed number of generated files.
Use the directory watchdog when total disk usage matters more than the number of files.
In production, it is common to combine them:
{
"home-directory": {
"path": "logs",
"watch-dog": {
"enable": true,
"max-size": "20GB",
"check-periodicity": "1m",
"file-extension": [".log"]
}
},
"channels": [
{
"name": "app",
"backends": [
{
"type": "FileBackend",
"file": "app.log",
"rotation": "daily",
"max-parts": 14
}
]
}
]
}This keeps per-backend history under control and also protects the whole log directory from growing without limit.
logme — flexible runtime logging system
Home · Getting Started · Architecture · Output · Backends · Configuration
GitHub: https://github.com/efmsoft/logme
- Home
- Getting Started
- Why logme?
- Core Concepts
- Logging Macros
- Fatal Handling
- Crash Logging
- glog Compatibility
- C API
- Choosing Logging Macros
- Function tracing
- Trace Points
- Override Scopes
- Advanced Features
- Collapse Logging
- Feature Map
- Overview
- Console Backend
- Debugger Backend
- File Backend
- File Rotation & Retention
- Buffer Backend
- Ring Buffer Backend
- SharedFile Backend
- Callback Backend
- Windows Event Log Backend
- Custom Backends
- Runtime Control
- Configuration
- Configuration JSON
- Control Server
- Environment Control
- Control Policies
- Trace Points
- Message Filtering