Specify and override default log file options

const fileLogger = loggerRollingApp({
file: {
level: 'warn', // file will log `warn` and higher
path: '/my/cool/path/output.log', // output to log file at this path
frequency: 'daily', // rotate hourly
size: '20MB', // rotate if file size grows larger than 20MB
timestamp: 'unix' // use unix epoch timestamp instead of iso8601 in rolling file
}
});
interface FileOptions {
    size?: string | number;
    frequency?: number | "daily" | "hourly";
    timestamp?: "unix" | "iso" | "auto";
    path?: string | (() => string);
}

Hierarchy (view full)

Properties

size?: string | number

The maximum size of a given rolling log file.

Can be combined with frequency. Use k, m and g to express values in KB, MB or GB.

Numerical values will be considered as MB.

'10MB'
frequency?: number | "daily" | "hourly"

The amount of time a given rolling log file is used. Can be combined with size.

Use daily or hourly to rotate file every day (or every hour). Existing file within the current day (or hour) will be re-used.

Numerical values will be considered as a number of milliseconds. Using a numerical value will always create a new file upon startup.

'daily'
timestamp?: "unix" | "iso" | "auto"

For rolling log files

When

  • value passed to rolling destination is a string (path from LogOptions is a string) and
  • frequency is defined

This determines the format of the datetime inserted into the log file name:

  • unix - unix epoch timestamp in milliseconds
  • iso - Full ISO8601 datetime IE '2024-03-07T20:11:34Z'
  • auto
    • When frequency is daily only inserts date IE YYYY-MM-DD
    • Otherwise inserts full ISO8601 datetime
'auto'
path?: string | (() => string)

The path and filename to use for log files.

If using rolling files the filename will be appended with .N (a number) BEFORE the extension based on rolling status.

May also be specified using env LOG_PATH or a function that returns a string.

If path is relative the absolute path will be derived from logBaseDir (in LoggerAppExtras) which defaults to CWD

'./logs/app.log'

LoggerAppExtras