mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
refactor: changement de la philosophie de logging
This commit is contained in:
39
Front-End/src/utils/logger.js
Normal file
39
Front-End/src/utils/logger.js
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
const getCallerInfo = () => {
|
||||
const stackLine = new Error().stack?.split('\n')[3].trim();
|
||||
// Regex pour extraire le fichier, la ligne et la colonne
|
||||
const match = stackLine.match(/\(?([^)]+):(\d+):(\d+)\)?$/);
|
||||
|
||||
let callerInfo = '(unknown)';
|
||||
if (match) {
|
||||
const [ , filePath, line, column ] = match;
|
||||
const fileName = filePath.split('/').pop(); // Garde juste le nom du fichier
|
||||
callerInfo = `[${fileName}:${line}]`;
|
||||
}
|
||||
return callerInfo;
|
||||
}
|
||||
|
||||
const logger = {
|
||||
debug: (...args) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.log.apply(console, ['[DEBUG]',`${getCallerInfo()}`, ...args])
|
||||
}
|
||||
},
|
||||
error: (...args) => {
|
||||
// Les erreurs sont toujours loguées
|
||||
|
||||
console.error.apply(console,['[ERROR]',`${getCallerInfo()}`,...args]);
|
||||
},
|
||||
warn: (...args) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.warn.apply(console, ['[WARN]',`${getCallerInfo()}`, ...args]);
|
||||
}
|
||||
},
|
||||
info: (...args) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.info.apply(console, ['[INFO]',`${getCallerInfo()}`, ...args]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default logger;
|
||||
Reference in New Issue
Block a user