bare-logger
Low-level logger for Bare
bare-logger — Low-level logger for Bare. It is a native addon.
npm i bare-loggerUsage
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
| Parameter | Type | Default | Description |
|---|---|---|---|
options? | LogOptions | — | Logger 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
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | 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
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | 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
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | 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
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | 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
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | 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
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | 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
| Parameter | Type | Default | Description |
|---|---|---|---|
logs | Log[] | — | 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
- Builds on
bare-format. - Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.