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.
Constructors
new Logger()
new Logger(options?): Logger
Parameters
Parameter | Type |
---|---|
options ? | LoggerOptions |
Returns
Properties
Property | Modifier | Type |
---|---|---|
_customLevels | protected | Record <string , CustomLevel > |
_enabled | protected | boolean |
_level | protected | string |
_levelValues | protected | Record <string , number > |
_parent | protected | Logger |
_prefix | protected | string |
Methods
_log()
protected _log(
prefix,
level, ...
data): void
Parameters
Parameter | Type |
---|---|
prefix | string |
level | string |
...data | unknown [] |
Returns
void
custom()
custom(level, ...data): void
Parameters
Parameter | Type |
---|---|
level | string |
...data | unknown [] |
Returns
void
debug()
debug(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
Returns
void
error()
error(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
Returns
void
event()
event(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
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
Parameter | Type | Description |
---|---|---|
prefix | string | The prefix to add to the logger (e.g. 'my-plugin') |
Returns
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
Parameter | Type | Default value |
---|---|---|
count | number | 50 |
Returns
LogEntry
[]
info()
info(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
Returns
void
log()
log(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
Returns
void
ready()
ready(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
Returns
void
setDrain()
setDrain(drain): void
Parameters
Parameter | Type |
---|---|
drain | LogDrain |
Returns
void
setup()
setup(options?): void
Parameters
Parameter | Type |
---|---|
options ? | LoggerOptions |
Returns
void
trace()
trace(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
Returns
void
wait()
wait(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
Returns
void
warn()
warn(...data): void
Parameters
Parameter | Type |
---|---|
...data | unknown [] |
Returns
void