mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
Add logging
This commit is contained in:
parent
11ec090ab6
commit
e65405c183
23
src/http.js
23
src/http.js
@ -1,8 +1,29 @@
|
|||||||
const fastify = require('fastify')();
|
const fastify = require('fastify')();
|
||||||
const { readFiles } = require('node-dir');
|
const { short } = require('leeks.js');
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
|
const { readFiles } = require('node-dir');
|
||||||
|
|
||||||
module.exports = client => {
|
module.exports = client => {
|
||||||
|
fastify.addHook('onResponse', (req, res, done) => {
|
||||||
|
done();
|
||||||
|
const status = (res.statusCode >= 500
|
||||||
|
? '&4'
|
||||||
|
: res.statusCode >= 400
|
||||||
|
? '&6'
|
||||||
|
: res.statusCode >= 300
|
||||||
|
? '&3'
|
||||||
|
: res.statusCode >= 200
|
||||||
|
? '&2'
|
||||||
|
: '&f') + res.statusCode;
|
||||||
|
let response_time = res.getResponseTime().toFixed(2);
|
||||||
|
response_time = (response_time >= 20
|
||||||
|
? '&c'
|
||||||
|
: response_time >= 5
|
||||||
|
? '&e'
|
||||||
|
: '&a') + response_time + 'ms';
|
||||||
|
client.log.info.http(short(`${req.ip} ${req.method} ${req.routerPath ?? '*'} &m-+>&r ${status}&b in ${response_time}`));
|
||||||
|
});
|
||||||
|
|
||||||
const dir = join(__dirname, '/routes');
|
const dir = join(__dirname, '/routes');
|
||||||
|
|
||||||
readFiles(dir,
|
readFiles(dir,
|
||||||
|
Loading…
Reference in New Issue
Block a user