LogoPear Docs
ReferencesBareModules

bare-logger

Low-level logger for Bare

Documented against v2.0.3
stable

bare-logger — Low-level logger for Bare. It is a native addon.

npm i bare-logger

Usage

const Log = require('bare-logger')

const log = new Log()

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

API

Log

new Log(options?: LogOptions)

Create a logger. colors defaults to whether the current stream is a TTY.

Parameters

ParameterTypeDefaultDescription
options?LogOptionsLogger options; colors forces ANSI color styling on or off, defaulting to whether the output stream is a TTY.

clear(): void

Clears the log output. A no-op on the base Log.

colors: boolean

Whether this logger applies ANSI color styling to formatted output. Read-only.

debug(...data: unknown[]): void

Logs data at debug level.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to format and log; the first may be a printf-style format string (for example %s, %d, %o) with the remaining values as substitutions.

error(...data: unknown[]): void

Logs data at error level.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to format and log; the first may be a printf-style format string (for example %s, %d, %o) with the remaining values as substitutions.

fatal(...data: unknown[]): void

Logs data at fatal level.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to format and log; the first may be a printf-style format string (for example %s, %d, %o) with the remaining values as substitutions.

format(...data: unknown[]): string

Formats data the same way debug, info, warn, error, and fatal do, and returns the resulting string without logging it.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to format and log; the first may be a printf-style format string (for example %s, %d, %o) with the remaining values as substitutions.

info(...data: unknown[]): void

Logs data at info level.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to format and log; the first may be a printf-style format string (for example %s, %d, %o) with the remaining values as substitutions.

warn(...data: unknown[]): void

Logs data at warn level.

Parameters

ParameterTypeDefaultDescription
dataunknown[]Values to format and log; the first may be a printf-style format string (for example %s, %d, %o) with the remaining values as substitutions.

CompositeLog

new CompositeLog(logs: Log[])

Create a logger that forwards every call to each logger in logs, so a single log call can write to, for example, both the console and a file.

Parameters

ParameterTypeDefaultDescription
logsLog[]The loggers to forward every call to, in order.

Types

LogOptions

interface LogOptions {
  colors?: boolean
}

Options for Log. colors forces ANSI color styling on or off in formatted output.

Multiple loggers

CompositeLog can be used to output to multiple loggers. Such as console and file loggers.

const { Log, CompositeLog } = require('bare-logger')

const log1 = new Log()
const log2 = new Log()
const log = new CompositeLog([log1, log2])

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

See also

On this page