forked from psycho237-prog/Psychobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
26 lines (22 loc) · 1.01 KB
/
Copy pathlogger.js
File metadata and controls
26 lines (22 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// logger.js
const chalk = require('chalk');
const util = require('util'); // On importe l'outil d'inspection de Node.js
const path = require('path');
function getTimestamp() {
return `[${new Date().toLocaleTimeString('fr-FR')}]`;
}
module.exports = function (caller) {
const tag = caller?.filename ? caller.filename.split(/\\|\//).pop().replace('.js', '').toUpperCase() : 'LOG';
return function (...args) {
// --- LA CORRECTION EST ICI ---
const message = args.map(arg => {
if (typeof arg === 'object' && arg !== null) {
// Utilise util.inspect pour une conversion sûre des objets, même circulaires.
// depth: 4 montre 4 niveaux de l'objet, ce qui est suffisant pour le débogage.
return util.inspect(arg, { depth: 4, colors: true });
}
return arg;
}).join(' ');
console.log(`${chalk.gray.italic(getTimestamp())} ${chalk.cyan.bold(`[${tag}]`)} ${message}`);
};
};