@discordjs-mvc/logger
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Logger plugin for Discordjs MVC

This plugin adds a logger to your bot. The logger is based on winston. The loggerConstructor function returns a plugin, a middleware function and the logger object itself. The plugin adds the logger to the context object and the middleware automatically logs all interactions. For using the logger in your own code, you can use the logger object.

Installation

npm i @discordjs-mvc/logger
# or
yarn add @discordjs-mvc/logger

Usage

It's recommended to create a separate file for the logger, for example logger.ts:

// logger.ts
import { loggerConstructor } from '@discordjs-mvc/logger'

const allLoggers = loggerConstructor({
  // Winston options
})

export default {
  loggerPlugin: allLoggers.plugin,
  loggerMiddleware: allLoggers.middleware,
  logger: allLoggers.logger
}

Now you can import the logger in your router file:

// router.ts
import { Router } from 'discordjs-mvc'
import { loggerPlugin, loggerMiddleware } from './logger'

const router = new Router()
  .plugin(loggerPlugin) // adds the plugin to the context object
  .use(loggerMiddleware) // automatically logs all interactions

For using the logger in your own code, you can import the logger object from the logger.ts file:

// myFile.ts
import { logger } from './logger'

logger.info('Hello World!')

Extend your context with the logger flavor

To safely extend your context with the logger flavor, you can use the following code:

import { BaseContext } from 'discordjs-mvc'
import { LoggerFlavor } from '@discordjs-mvc/logger'

export type Context = BaseContext & LoggerFlavor

Package Sidebar

Install

npm i @discordjs-mvc/logger

Weekly Downloads

1

Version

1.0.5

License

ISC

Unpacked Size

7.18 kB

Total Files

13

Last publish

Collaborators

  • 3h04m1