Module Message_templates.File_sink

File sink - outputs log events to a file with optional rolling

The file sink writes log events to files on disk with support for automatic log rotation based on time intervals.

Rolling intervals:

type rolling_interval =
  1. | Infinite
    (*

    Never roll, single log file

    *)
  2. | Daily
    (*

    Roll daily at midnight UTC

    *)
  3. | Hourly
    (*

    Roll at the start of each hour

    *)
type t

File sink type (opaque)

val default_template : string

Default file output template: "{timestamp} [{level}] {message}"

val create : ?output_template:string -> ?rolling:rolling_interval -> string -> t

Create a file sink.

  • parameter output_template

    Output template with placeholders

  • parameter rolling

    Rolling interval for log rotation (default: Infinite)

  • parameter path

    Base file path for log files

val emit : t -> Log_event.t -> unit

Emit a log event to the file

val flush : t -> unit

Flush the file buffer

val close : t -> unit

Close the file sink and underlying channel