LogoPear Docs

bare-file-logger

File system logger for Bare

stable

bare-file-logger — File system logger for Bare.

npm i bare-file-logger

Usage

const FileLog = require('bare-file-logger')

const log = new FileLog('my-logs.txt')

log.info('Hello %s', 'world!')

API

FileLog

new FileLog(path: string, options?: FileLogOptions)

Source

Construct a new FileLog that writes to the file at path.

Parameters

ParameterTypeDefaultDescription
pathstringPath to the log file; opened for appending, and created if it does not exist.
options?FileLogOptionsOptions controlling log rotation; see FileLogOptions.

append(label: string, ...data: unknown[]): void

Source

Writes a single log line: the padded label, an ISO-8601 timestamp, and the formatted data, terminated by a newline.

Parameters

ParameterTypeDefaultDescription
labelstringA short severity label, right-padded to five characters (e.g. info, error), prefixed to the line ahead of an ISO-8601 timestamp.
dataunknown[]Values to format into the log message, using the same formatting as console.log.

close(): void

Source

Closes the underlying file descriptor and stops the rotation timer. Safe to call more than once.

Types

FileLogOptions

interface FileLogOptions {
  maxSize?: number
  rotate?: (path: string) => string
  rotateInterval?: number
}
Source

FileLogEvents

interface FileLogEvents extends EventMap {
  rotate: [path: string, archived: string | null]
}
Source

See also

On this page