View Source RotatingFile (RotatingFile v0.1.2)

A GenServer that rotates a log file when it reaches a certain size. It creates a new compressed log file and deletes the oldest ones when the number of files exceeds the limit.

Summary

Functions

Returns a specification to start this module under a supervisor.

Deletes all log files.

Starts the rotating file server.

Ensures the log file is synced to disk.

Adds bytes to the log file. When no pid or name is provided, it will use the default module name.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

delete_all(pid \\ __MODULE__)

View Source

Deletes all log files.

Starts the rotating file server.

Options

  • :name - The name of the GenServer process. Defaults to RotatingFile.
  • :max_size - The maximum size of the log file in bytes. Defaults to 100 * 1024 * 1024.
  • :max_files - The maximum number of log files to keep. Defaults to 10.
  • :file - The path to the log file. Defaults to "output.log".

Example

RotatingFile.start_link(name: :rotating_file, max_size: 100 * 1024 * 1024, max_files: 10, file: "stdout.log")

Ensures the log file is synced to disk.

Link to this function

write(pid \\ __MODULE__, bytes)

View Source

Adds bytes to the log file. When no pid or name is provided, it will use the default module name.

Example

RotatingFile.write(:rotating_file, "Hello, world!
")