Skip to content

Logging & Log Rotation

Ontheia uses a structured logging system (based on pino) that supports both the console (stdout) and rotating files on the file system.

Logging is controlled via environment variables in the .env file.

VariableDescriptionDefault
LOG_LEVELLogging detail level (debug, info, warn, error).info
PINO_PRETTYSet to true for colorized, human-readable log output on the console (recommended for development only).false
LOG_FILEPath to the log file on the host/container.<cwd>/host_server.log
LOG_MAX_BYTESMaximum size of a log file in bytes before rotation.10485760 (10 MB)
LOG_MAX_FILESNumber of rotated log files to keep (older ones will be deleted).5

Ontheia implements its own log rotation (log-rotate.ts) to ensure that the disk does not fill up with infinitely growing log files.

  1. Writing: All logs are continuously appended to the end of the file defined in LOG_FILE.
  2. Checking: With every write operation, the system checks whether the current file size has exceeded LOG_MAX_BYTES.
  3. Rotation: Once the limit is reached:
    • The current file is closed.
    • The file is renamed to LOG_FILE.YYYY-MM-DDTHH-mm-ss-SSSZ (with the current timestamp).
    • A new, empty LOG_FILE is opened.
  4. Cleanup: The system checks the directory for older rotated files. It keeps only the latest LOG_MAX_FILES files and permanently deletes any additional archives.

When Ontheia is running in Docker, the standard logs (console) can be viewed as usual:

Terminal window
docker compose logs -f host

The rotating files are located inside the container at the path specified in LOG_FILE (defaulting to the app’s root directory). To store these persistently, the directory should be mounted as a volume.

The logs are written directly to the file:

Terminal window
tail -f host_server.log

Without PINO_PRETTY=true, logs are output in JSON format, which is ideal for external log aggregators (such as ELK Stack or Loki).

Example:

{"level":30,"time":1710775000000,"pid":1,"hostname":"ontheia-host","msg":"Server started on port 8080"}
  • level: 30 corresponds to info.
  • time is a Unix timestamp in milliseconds.