Improve logging

This commit is contained in:
Isaac 2021-02-27 21:13:46 +00:00
parent ddba4e2482
commit e53427cb36
No known key found for this signature in database
GPG Key ID: 21C53B622E50E421
9 changed files with 261 additions and 53 deletions

View File

@ -1,5 +1,7 @@
DISCORD_TOKEN=
DISCORD_SECRET=
HTTP_PORT=8080
HTTP_HOST=http://example.com:8080
DB_TYPE=sqlite
DB_HOST=
DB_PORT=

View File

@ -33,9 +33,11 @@
"discord.js": "^12.5.1",
"dotenv": "^8.2.0",
"fastify": "^3.12.0",
"fastify-secure-session": "^2.3.1",
"fastify-static": "^4.0.1",
"fs-extra": "^9.1.0",
"leeks.js": "^0.0.9",
"leekslazylogger-fastify": "^0.0.5",
"leekslazylogger-fastify": "^0.0.6",
"node-fetch": "^2.6.1",
"semver": "^7.3.4",
"sequelize": "^6.5.0",

View File

@ -4,9 +4,11 @@ dependencies:
discord.js: 12.5.1
dotenv: 8.2.0
fastify: 3.12.0
fastify-secure-session: 2.3.1
fastify-static: 4.0.1
fs-extra: 9.1.0
leeks.js: 0.0.9
leekslazylogger-fastify: 0.0.5
leekslazylogger-fastify: 0.0.6
node-fetch: 2.6.1
semver: 7.3.4
sequelize: 6.5.0_fb66e8c649bde1be622cc06164c9e22d
@ -676,6 +678,20 @@ packages:
optional: true
resolution:
integrity: sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=
/content-disposition/0.5.3:
dependencies:
safe-buffer: 5.1.2
dev: false
engines:
node: '>= 0.6'
resolution:
integrity: sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==
/cookie-signature/1.1.0:
dev: false
engines:
node: '>=6.6.0'
resolution:
integrity: sha512-Alvs19Vgq07eunykd3Xy2jF0/qSNv2u7KDbAek9H5liV1UMijbqFs5cycZvv5dVsvseT/U4H8/7/w8Koh35C4A==
/cookie/0.4.1:
dev: false
engines:
@ -717,7 +733,6 @@ packages:
/debug/2.6.9:
dependencies:
ms: 2.0.0
dev: true
resolution:
integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
/debug/3.2.7:
@ -780,12 +795,22 @@ packages:
node: '>=0.10'
resolution:
integrity: sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==
/depd/1.1.2:
dev: false
engines:
node: '>= 0.6'
resolution:
integrity: sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=
/depd/2.0.0:
dev: true
engines:
node: '>= 0.8'
resolution:
integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==
/destroy/1.0.4:
dev: false
resolution:
integrity: sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=
/detect-libc/1.0.3:
dev: false
engines:
@ -861,6 +886,12 @@ packages:
/emoji-regex/8.0.0:
resolution:
integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
/encodeurl/1.0.2:
dev: false
engines:
node: '>= 0.8'
resolution:
integrity: sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=
/end-of-stream/1.4.4:
dependencies:
once: 1.4.0
@ -885,6 +916,10 @@ packages:
node: '>=8'
resolution:
integrity: sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==
/escape-html/1.0.3:
dev: false
resolution:
integrity: sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=
/escape-string-regexp/1.0.5:
dev: true
engines:
@ -1022,6 +1057,12 @@ packages:
node: '>=0.10.0'
resolution:
integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
/etag/1.8.1:
dev: false
engines:
node: '>= 0.6'
resolution:
integrity: sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
/event-target-shim/5.0.1:
engines:
node: '>=6'
@ -1069,6 +1110,14 @@ packages:
dev: false
resolution:
integrity: sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==
/fastify-cookie/5.1.0:
dependencies:
cookie: 0.4.1
cookie-signature: 1.1.0
fastify-plugin: 3.0.0
dev: false
resolution:
integrity: sha512-AN5C/p7YVSgnW1D9fcUL10yRIN+9lcOtyps3h4/5ZsxwrHVgdNH5T77CbnIrzfAx6qz7K/8NYQCTE8cxZIJcJg==
/fastify-error/0.3.0:
dev: false
resolution:
@ -1077,6 +1126,25 @@ packages:
dev: false
resolution:
integrity: sha512-ZdCvKEEd92DNLps5n0v231Bha8bkz1DjnPP/aEz37rz/q42Z5JVLmgnqR4DYuNn3NXAO3IDCPyRvgvxtJ4Ym4w==
/fastify-secure-session/2.3.1:
dependencies:
fastify-cookie: 5.1.0
fastify-plugin: 3.0.0
sodium-native: 3.2.1
dev: false
hasBin: true
resolution:
integrity: sha512-6XsatyRSiX0UQB0MOPlU/PC9yn3seImefS1yv8C0bAyjAJ876839eHKPrclwNKBVX+9SUX+LdJGJTBi8DSU63g==
/fastify-static/4.0.1:
dependencies:
content-disposition: 0.5.3
fastify-plugin: 3.0.0
glob: 7.1.6
readable-stream: 3.6.0
send: 0.17.1
dev: false
resolution:
integrity: sha512-Mjt0My8Gf/nzJqIDai9rz3HsxH4RAJeMGMIPmf40lGMFKAv4SbRiKJ2cmteXoKHrFGPeGxwMq0gXfixwueV8wA==
/fastify-warning/0.2.0:
dev: false
resolution:
@ -1196,6 +1264,12 @@ packages:
node: '>= 6'
resolution:
integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
/fresh/0.5.2:
dev: false
engines:
node: '>= 0.6'
resolution:
integrity: sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=
/fs-extra/9.1.0:
dependencies:
at-least-node: 1.0.0
@ -1378,6 +1452,18 @@ packages:
dev: true
resolution:
integrity: sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==
/http-errors/1.7.3:
dependencies:
depd: 1.1.2
inherits: 2.0.4
setprototypeof: 1.1.1
statuses: 1.5.0
toidentifier: 1.0.0
dev: false
engines:
node: '>= 0.6'
resolution:
integrity: sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==
/http-signature/1.2.0:
dependencies:
assert-plus: 1.0.0
@ -1709,22 +1795,25 @@ packages:
dev: false
resolution:
integrity: sha512-e6UVJ1fj8f2clpHy+KpXVWVxjzB3XYFGyKRJHDlT8Gy/75BT+9bYUacpHSCoXp7RTtyMSr4eBjZrp0nHyyQVbg==
/leekslazylogger-fastify/0.0.5:
/leeks.js/0.1.1:
dev: false
resolution:
integrity: sha512-axz4CyTYNcjmQc19S0I9HSC5ONGflLVm1N0uUz/MdYvuvC94yZUP/panEm9tLAj88DesBSo6D8cuyO/ctB9kYA==
/leekslazylogger-fastify/0.0.6:
dependencies:
fastify-plugin: 3.0.0
leekslazylogger: 2.1.1
leekslazylogger: 3.0.0
on-finished: 2.3.0
dev: false
resolution:
integrity: sha512-b6XoUuqeQTLeNPCRd6x4rl4f572cgAg/tfr10TGlwsCNjrkYOXlwk/L6Qv2HGlBJRhe4ZLZQn+YvVtLFZJ8IOw==
/leekslazylogger/2.1.1:
integrity: sha512-6qnAjMKEomfmjPNA4/rfH0yV9SR+ze+jTjIG5mBmOnL/LtyiLJHcBiZKY5N689zMBpRdXCb/QOvszgNkcZG7Og==
/leekslazylogger/3.0.0:
dependencies:
'@eartharoid/dtf': 1.0.8
leeks.js: 0.0.9
lodash.merge: 4.6.2
leeks.js: 0.1.1
dev: false
resolution:
integrity: sha512-5CnWiDW+vIH5R0cQfZK2TOaCXvaErF1inPjRuASqarwKCQjEssiUyK6QRUklv9oqqUr1Iq5eQzGIZapOD3GPRQ==
integrity: sha512-vk9I2qejv4B4xFPdLUFODnulMMJn3eLVtFq+JSfejU1yDBPNji+jermGm0I7YhF7ebNlU5AfdR+HbjkTPwaXlg==
/levn/0.4.1:
dependencies:
prelude-ls: 1.2.1
@ -1750,10 +1839,6 @@ packages:
dev: true
resolution:
integrity: sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==
/lodash.merge/4.6.2:
dev: false
resolution:
integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
/lodash/4.17.20:
resolution:
integrity: sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
@ -1855,6 +1940,13 @@ packages:
node: '>= 0.6'
resolution:
integrity: sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==
/mime/1.6.0:
dev: false
engines:
node: '>=4'
hasBin: true
resolution:
integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==
/mimic-response/1.0.1:
dev: true
engines:
@ -1908,9 +2000,12 @@ packages:
resolution:
integrity: sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
/ms/2.0.0:
dev: true
resolution:
integrity: sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=
/ms/2.1.1:
dev: false
resolution:
integrity: sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==
/ms/2.1.2:
resolution:
integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
@ -1974,6 +2069,11 @@ packages:
node: 4.x || >=6.0.0
resolution:
integrity: sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
/node-gyp-build/4.2.3:
dev: false
hasBin: true
resolution:
integrity: sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==
/node-gyp/3.8.0:
dependencies:
fstream: 1.0.12
@ -2413,6 +2513,12 @@ packages:
dev: false
resolution:
integrity: sha512-RyYpQ6Q5/drsJyOhrWHYMWTedvjTIat+FTwv0K4yoUxzvekw2aRHMQJLlnvt8UantkZg2++bEzD9EdxXqkWf4A==
/range-parser/1.2.1:
dev: false
engines:
node: '>= 0.6'
resolution:
integrity: sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==
/rc/1.2.8:
dependencies:
deep-extend: 0.6.0
@ -2565,7 +2671,6 @@ packages:
integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
/safe-buffer/5.1.2:
dev: false
optional: true
resolution:
integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
/safe-buffer/5.2.1:
@ -2626,6 +2731,26 @@ packages:
hasBin: true
resolution:
integrity: sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==
/send/0.17.1:
dependencies:
debug: 2.6.9
depd: 1.1.2
destroy: 1.0.4
encodeurl: 1.0.2
escape-html: 1.0.3
etag: 1.8.1
fresh: 0.5.2
http-errors: 1.7.3
mime: 1.6.0
ms: 2.1.1
on-finished: 2.3.0
range-parser: 1.2.1
statuses: 1.5.0
dev: false
engines:
node: '>= 0.8.0'
resolution:
integrity: sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==
/seq-queue/0.0.5:
dev: true
resolution:
@ -2695,6 +2820,10 @@ packages:
dev: false
resolution:
integrity: sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=
/setprototypeof/1.1.1:
dev: false
resolution:
integrity: sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==
/shebang-command/2.0.0:
dependencies:
shebang-regex: 3.0.0
@ -2722,6 +2851,14 @@ packages:
node: '>=10'
resolution:
integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==
/sodium-native/3.2.1:
dependencies:
ini: 1.3.8
node-gyp-build: 4.2.3
dev: false
requiresBuild: true
resolution:
integrity: sha512-EgDZ/Z7PxL2kCasKk7wnRkV8W9kvwuIlHuHXAxkQm3FF0MgVsjyLBXGjSRGhjE6u7rhSpk3KaMfFM23bfMysIQ==
/sonic-boom/1.3.2:
dependencies:
atomic-sleep: 1.0.0
@ -2779,6 +2916,12 @@ packages:
hasBin: true
resolution:
integrity: sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==
/statuses/1.5.0:
dev: false
engines:
node: '>= 0.6'
resolution:
integrity: sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=
/string-similarity/4.0.4:
dev: false
resolution:
@ -2979,6 +3122,12 @@ packages:
node: '>=8.0'
resolution:
integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==
/toidentifier/1.0.0:
dev: false
engines:
node: '>=0.6'
resolution:
integrity: sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
/toposort-class/1.0.1:
dev: false
resolution:
@ -3303,10 +3452,12 @@ specifiers:
dotenv: ^8.2.0
eslint: ^7.20.0
fastify: ^3.12.0
fastify-secure-session: ^2.3.1
fastify-static: ^4.0.1
fs-extra: ^9.1.0
jsdoc: ^3.6.6
leeks.js: ^0.0.9
leekslazylogger-fastify: ^0.0.5
leekslazylogger-fastify: ^0.0.6
mariadb: ^2.5.2
mysql2: ^2.2.5
node-fetch: ^2.6.1

View File

@ -60,32 +60,7 @@ const config = require('../user/config');
require('./banner')();
const Logger = require('leekslazylogger-fastify');
const log = new Logger({
name: 'DiscordTickets by eartharoid',
debug: config.debug,
logToFile: config.logs.enabled,
directory: path('./logs/'),
keepFor: config.logs.keep_for,
custom: {
commands: {
title: 'info',
prefix: 'commands'
},
http: {
title: 'info',
prefix: 'http'
},
plugins: {
title: 'info',
prefix: 'plugins'
},
tickets: {
title: 'info',
prefix: 'tickets'
}
}
});
const log = require('./logger');
const { selectPresence } = require('./utils/discord');
const I18n = require('@eartharoid/i18n');

View File

@ -1,7 +1,7 @@
module.exports = {
event: 'guildCreate',
execute: async (client, guild) => {
client.log.console(`Added to ${guild.name}`);
client.log.info(`Added to ${guild.name}`);
await guild.createSettings();
}
};

View File

@ -1,7 +1,7 @@
module.exports = {
event: 'guildDelete',
execute: async (client, guild) => {
client.log.console(`Removed from ${guild.name}`);
client.log.info(`Removed from ${guild.name}`);
await guild.deleteSettings();
}
};

56
src/logger.js Normal file
View File

@ -0,0 +1,56 @@
const { path } = require('./utils/fs');
const config = require('../user/config');
const Logger = require('leekslazylogger-fastify');
module.exports = new Logger({
name: 'DiscordTickets by eartharoid',
debug: config.debug,
logToFile: config.logs.enabled,
splitFile: true,
directory: path('./logs/'),
keepFor: config.logs.keep_for,
levels: {
_logger: {
format: '&7[{timestamp}]&r [LOGGER] {text}'
},
basic: {
format: '[{timestamp}] {text}'
},
console: {
format: '[{timestamp}] [INFO] {text}'
},
info: {
format: '&7[{timestamp}]&r &3[INFO] &b{text}'
},
success: {
format: '&7[{timestamp}]&r &2[SUCCESS] &a{text}'
},
debug: {
format: '&7[{timestamp}]&r &1[DEBUG] &9{text}'
},
notice: {
format: '&7[{timestamp}]&r &0&!6[NOTICE] {text}'
},
warn: {
format: '&7[{timestamp}]&r &6[WARN] &e{text}'
},
error: {
format: '&7[{timestamp}]&r &4[ERROR] &c{text}'
},
commands: {
type: 'info',
format: '&7[{timestamp}]&r &3[INFO] &d(COMMANDS)&r {text}'
},
http: {
type: 'info',
format: '&7[{timestamp}]&r &3[INFO] &d(HTTP)&r {text}'
},
plugins: {
type: 'info',
format: '&7[{timestamp}]&r &3[INFO] &d(PLUGINS)&r {text}'
},
tickets: {
type: 'info',
format: '&7[{timestamp}]&r &3[INFO] &d(TICKETS)&r {text}'
}
}
});

View File

@ -1,4 +1,7 @@
const { Plugin } = require('../modules/plugins');
const fastify = require('fastify');
const { randomBytes } = require('crypto');
const { path } = require('../utils/fs');
module.exports = class SettingsServer extends Plugin {
constructor(client) {
@ -9,7 +12,7 @@ module.exports = class SettingsServer extends Plugin {
commands: []
});
this.fastify = require('fastify')();
this.fastify = fastify();
this.client.plugins.plugins.set(this.id, this);
this.preload();
@ -17,19 +20,38 @@ module.exports = class SettingsServer extends Plugin {
async preload() {
this.fastify.register(this.client.log.fastify, {
type: 'http'
level: 'http',
format: '{method} {status-colour}{status} &7{route} {time-colour}({time})'
});
this.fastify.register(require('fastify-secure-session'), {
key: randomBytes(48).toString('hex')
});
this.fastify.register(require('fastify-static'), {
root: path('./src/server/public'),
prefix: '/public/',
});
}
async load() {
this.fastify.listen(process.env.HTTP_PORT || 8080, (err, address) => {
if (err) throw err;
this.client.log.info(`Settings server listening at ${address}`);
});
let host = process.env.HTTP_HOST;
if (!host.endsWith('/')) host = host + '/';
let redirect_url = encodeURI(`${host}auth/callback`);
let oauth2_url = `https://discord.com/api/oauth2/authorize?client_id=${this.client.user.id}&redirect_uri=${redirect_url}&response_type=code&scope=identify%20guilds&state=apollo`;
this.fastify.get('/', async (req, res) => {
res.type('application/json').code(200);
return { hello: 'world' };
// res.type('application/json').code(200);
// return { hello: 'world' };
res.code(200);
return 'Hello!';
});
this.fastify.listen(process.env.HTTP_PORT || 8080, (err, host) => {
if (err) throw err;
this.client.log.info(`Settings server listening at ${host}`);
});
}
};

View File