54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Server_1 = require("../../Server");
|
|
const LOG_SYSTEM_TITLE = 'SYSTEM';
|
|
const CONSOLE_COLOR = {
|
|
DEFAULT: '\x1B[0m',
|
|
SYSTEM: '\x1B[32m',
|
|
WARN: '\x1B[33m',
|
|
ERROR: '\x1B[35m',
|
|
LOG: '\x1B[36m',
|
|
};
|
|
class LogPrint {
|
|
constructor() {
|
|
}
|
|
onServerStart() {
|
|
this.logSystem(`onServerStart`);
|
|
}
|
|
onServerStop() {
|
|
this.logSystem(`onServerStop`);
|
|
}
|
|
onClientConnected(id) {
|
|
this.logSystem(`onClientConnected: ${id}`);
|
|
}
|
|
onClientLogMessage(id, logs) {
|
|
// this.logSystem(`onClientLogMessage: ${id}`);
|
|
logs.forEach(log => {
|
|
const date = new Date(log.time);
|
|
const timeString = `${date.getHours()}:${('0' + date.getMinutes()).slice(-2)}:${('0' + date.getSeconds()).slice(-2)}`;
|
|
switch (log.level) {
|
|
case Server_1.LogLevel.Log:
|
|
console.log(`${CONSOLE_COLOR.LOG}[${timeString}][LOG] ${log.text}${CONSOLE_COLOR.DEFAULT}`);
|
|
break;
|
|
case Server_1.LogLevel.Warn:
|
|
console.log(`${CONSOLE_COLOR.WARN}[${timeString}][WARN] ${log.text}${CONSOLE_COLOR.DEFAULT}`);
|
|
break;
|
|
case Server_1.LogLevel.Error:
|
|
console.log(`${CONSOLE_COLOR.ERROR}[${timeString}][ERROR] ${log.text}${CONSOLE_COLOR.DEFAULT}`);
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
onClientErrorMessage(id, error) {
|
|
}
|
|
onClientDisconnect(id) {
|
|
this.logSystem(`onClientDisconnect: ${id}`);
|
|
}
|
|
logSystem(text) {
|
|
const date = new Date();
|
|
const timeString = `${date.getHours()}:${('0' + date.getMinutes()).slice(-2)}:${('0' + date.getSeconds()).slice(-2)}`;
|
|
console.log(`${CONSOLE_COLOR.SYSTEM}[${timeString}][${LOG_SYSTEM_TITLE}] ${text}${CONSOLE_COLOR.DEFAULT}`);
|
|
}
|
|
}
|
|
exports.default = LogPrint;
|