Skip to content
GitHub

Logger

class in meocord/common Since 4.0.0

class Logger

Prints timestamped lines to the console, each named with the app and a context, at a level the config can hide.

Use it in controllers and services instead of console, so the bot's lines share one format and meocord.config.ts's logLevel, or MEOCORD_LOG_LEVEL for one run, decides which print.

Examples

TypeScript
@Service()
export class ReminderService {
  private readonly logger = new Logger(ReminderService.name)

  remind(userId: string) {
    this.logger.log(`Reminding ${userId}`)
  }
}

Members

constructor

new Logger(context?: string | undefined)

Parameters

NameTypeDescription
context?string | undefined

What the lines are about, shown on each, such as a class's name.

debug

debug(...args: any[]): void

Prints a line at the debug level, shown only when the level is debug.

Parameters

NameTypeDescription
...argsany[]

What to print, separated by spaces.

error

error(...args: any[]): void

Prints an error, shown unless the level is silent.

Parameters

NameTypeDescription
...argsany[]

What to print, separated by spaces.

info

info(...args: any[]): void

Prints a line tagged [INFO], shown at the log level as log is.

Parameters

NameTypeDescription
...argsany[]

What to print, separated by spaces.

log

log(...args: any[]): void

Prints a line at the log level.

Parameters

NameTypeDescription
...argsany[]

What to print, separated by spaces.

verbose

verbose(...args: any[]): void

Prints a line tagged [VERBOSE], shown at the log level as log is.

Parameters

NameTypeDescription
...argsany[]

What to print, separated by spaces.

warn

warn(...args: any[]): void

Prints a warning, shown unless the level is error or silent.

Parameters

NameTypeDescription
...argsany[]

What to print, separated by spaces.

See also

  • MeoCordConfig