Skip to main content

Class: Logger

The logger class provides a simple and flexible logging system.

import { logger } from 'robo.js'

// Can be used instead of console.log
logger.info('Hello, world!')
logger.debug('This is a debug message')
logger.warn('Warning: something is not right')
logger.error('An error occurred')

// To make your own Logger instance
import { Logger } from 'robo.js'

const customLogger = new Logger({
level: 'debug'
})

Use logger whenever possible instead of console.log to take advantage of Robo drains and log levels.

Learn more: Logger

Constructors

new Logger()

new Logger(options?): Logger

Parameters

ParameterType
options?LoggerOptions

Returns

Logger

Properties

PropertyModifierType
_customLevelsprotectedRecord<string, CustomLevel>
_enabledprotectedboolean
_levelprotectedstring
_levelValuesprotectedRecord<string, number>
_parentprotectedLogger
_prefixprotectedstring

Methods

_log()

protected _log(
prefix,
level, ...
data): void

Parameters

ParameterType
prefixstring
levelstring
...dataunknown[]

Returns

void


custom()

custom(level, ...data): void

Parameters

ParameterType
levelstring
...dataunknown[]

Returns

void


debug()

debug(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void


error()

error(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void


event()

event(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void


flush()

flush(): Promise<void>

Waits for all pending log writes to complete.

Returns

Promise<void>


fork()

fork(prefix): Logger

Creates a new logger instance with the specified prefix. This is useful for creating a logger for a specific plugin, big features, or modules.

All writes and cached logs will be delegated to the parent logger, so debugging will still work.

Parameters

ParameterTypeDescription
prefixstringThe prefix to add to the logger (e.g. 'my-plugin')

Returns

Logger

A new logger instance with the specified prefix


getLevel()

getLevel(): string

Returns

string


getLevelValues()

getLevelValues(): Record<string, number>

Returns

Record<string, number>


getRecentLogs()

getRecentLogs(count): LogEntry[]

Parameters

ParameterTypeDefault value
countnumber50

Returns

LogEntry[]


info()

info(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void


log()

log(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void


ready()

ready(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void


setDrain()

setDrain(drain): void

Parameters

ParameterType
drainLogDrain

Returns

void


setup()

setup(options?): void

Parameters

ParameterType
options?LoggerOptions

Returns

void


trace()

trace(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void


wait()

wait(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void


warn()

warn(...data): void

Parameters

ParameterType
...dataunknown[]

Returns

void