mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-19 08:02:16 +03:00
39 lines
997 B
JavaScript
39 lines
997 B
JavaScript
class Logger {
|
|
log(message, level = 'INFO') {
|
|
console.log(`[${this.generateTimestamp()}] [${level}] ${message}`)
|
|
}
|
|
|
|
generateTimestamp() {
|
|
const d = new Date();
|
|
|
|
// Date
|
|
const year = d.getFullYear();
|
|
const month = this.parseDate(d.getMonth() + 1);
|
|
const day = this.parseDate(d.getDate());
|
|
|
|
// Time
|
|
const hour = this.parseDate(d.getHours());
|
|
const minutes = this.parseDate(d.getMinutes());
|
|
const seconds = this.parseDate(d.getSeconds());
|
|
const miliseconds = this.parseDate(d.getMilliseconds(), true);
|
|
|
|
// Timezone
|
|
const tz = -d.getTimezoneOffset() / 60;
|
|
|
|
return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}.${miliseconds} UTC${tz >= 0 ? '+' + tz : tz}`;
|
|
}
|
|
|
|
parseDate(date, ms = false) {
|
|
if (ms) {
|
|
if (date >= 10 && date < 100) {
|
|
return `0${date}`;
|
|
} else if (date < 10) {
|
|
return `00${date}`;
|
|
}
|
|
}
|
|
|
|
return date < 10 ? `0${date}` : date.toString();
|
|
}
|
|
}
|
|
|
|
module.exports = Logger; |