From e105f0c34cebb482bc0c7f450ab6dd9bcca07f94 Mon Sep 17 00:00:00 2001 From: Isaac Date: Tue, 1 Nov 2022 21:10:57 +0000 Subject: [PATCH] update logger --- package.json | 2 +- src/lib/logger.js | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 8443ed0..7735814 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "fs-extra": "^10.1.0", "keyv": "^4.5.0", "leeks.js": "^0.2.4", - "leekslazylogger": "^4.1.7", + "leekslazylogger": "^5.0.0", "ms": "^2.1.3", "mustache": "^4.2.0", "node-dir": "^0.1.17", diff --git a/src/lib/logger.js b/src/lib/logger.js index a0af18a..701aa41 100644 --- a/src/lib/logger.js +++ b/src/lib/logger.js @@ -1,4 +1,8 @@ -const Logger = require('leekslazylogger'); +const { + ConsoleTransport, + FileTransport, + Logger, +} = require('leekslazylogger'); const DTF = require('@eartharoid/dtf'); const { short } = require('leeks.js'); @@ -16,11 +20,11 @@ const colours = { module.exports = config => { const transports = [ - new Logger.transports.ConsoleTransport({ + new ConsoleTransport({ format: log => { const timestamp = dtf.fill('DD/MM/YY HH:mm:ss', log.timestamp); const colour = colours[log.level.name]; - return short(`&f&!7${timestamp}&r ${colour[0]}[${log.level.name.toUpperCase()}]&r ${log.namespace ? `&d(${log.namespace.toUpperCase()})&r ` : ''}${colour[1]}${log.content}`); + return short(`&f&!7 ${timestamp} &r ${colour[0]}[${log.level.name.toUpperCase()}]&r ${log.namespace ? `&d(${log.namespace.toUpperCase()})&r ` : ''}${colour[1]}${log.content}`); }, level: config.logs.level, }), @@ -28,9 +32,10 @@ module.exports = config => { if (config.logs.files.enabled) { transports.push( - new Logger.transports.FileTransport({ + new FileTransport({ clean_directory: config.logs.files.keepFor, directory: config.logs.files.directory, + format: '[{timestamp}] [{LEVEL}] ({NAMESPACE}) @{file}:{line}:{column} {content}', level: config.logs.level, name: 'Discord Tickets by eartharoid', }), @@ -38,7 +43,17 @@ module.exports = config => { } return new Logger({ - namespaces: ['autocomplete', 'buttons', 'commands', 'http', 'listeners', 'menus', 'modals', 'settings', 'tickets'], + namespaces: [ + 'autocomplete', + 'buttons', + 'commands', + 'http', + 'listeners', + 'menus', + 'modals', + 'settings', + 'tickets', + ], transports, }); };