Skip to main content
Version: 2.3

Logger

TSCord includes a logger service that lets you efficiently log things towards different "locations" in a formatted way.

Configuration

To configure what should be logged and where, head over to this part of the documentation.

Usage

Log

The log() method of the Logger service is a little abstraction of the per location methods (listed just below) that will act as a shortcut to log to the console, and optionally to a file or a discord channel depending on params.

Params

NameTypeDefaultDescription
messagestringThe message to log
levelstringinfoinfo | warn | error
saveToFilebooleantrueIf the message should be saved in a file
channelIdstring | nullnullDiscord channel to log to (if null, nothing will be logged to Discord)

Usage

import { Logger } from '@/services'
const logger = container.resolve(Logger)

logger.log('hello world!')

Per location methods

Log a message in the console using the console() method.

Params

NameTypeDefaultDescription
messagestringThe message to log
levelstringinfoinfo | warn | error
ignoreTemplatebooleanfalseIf it should ignore the default timestamp-based template

Usage

import { Logger } from '@/services'
const logger = container.resolve(Logger)

logger.console('hello world!')

Auto-archiving

TSCord will automatically archive the logs every day at midnight. The logs will be moved to a folder named archive in the logs directory, and will be named logs-{date}.tar.gz (gzip format) where {date} is the date of the logs that were archived.

You can disable this feature by setting archive.enabled to false in the logs configuration.

Retention policy

The logs will be kept for a certain amount of days, and the rest will be deleted. You can configure this by setting archive.retention to the amount of days you want to keep the logs. By default, it's set to 30 days.