[server] update
This commit is contained in:
@@ -3,18 +3,29 @@ const through = require('through2');
|
||||
const colors = require('ansi-colors');
|
||||
const log = require('fancy-log');
|
||||
|
||||
const color = (level) => {
|
||||
return {
|
||||
'[DEBUG]': colors.white,
|
||||
'[INFO]': colors.cyan,
|
||||
'[ERROR]': colors.red,
|
||||
'[WARNING]': colors.yellow,
|
||||
}[level] || colors.reset;
|
||||
const _colors = {
|
||||
'[DEBUG]': colors.white,
|
||||
'[INFO]': colors.cyan,
|
||||
'[ERROR]': colors.red,
|
||||
'[WARNING]': colors.yellow,
|
||||
};
|
||||
|
||||
const _log = (line) => {
|
||||
const result = line.split(' ');
|
||||
console.log(colors.gray(result[0]) + ' ' + color(result[1])(result.slice(1).join(' ')));
|
||||
const getColor = (line) => {
|
||||
for (const [tag, color] of Object.entries(_colors)) {
|
||||
if (line.indexOf(tag) > -1) {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
return null;// colors.reset;
|
||||
};
|
||||
|
||||
const _log = (line, color) => {
|
||||
if (line[0] === '\t') {
|
||||
console.log(color(line))
|
||||
} else {
|
||||
const result = line.split(' ');
|
||||
console.log(colors.gray(result.slice(0, 4).join(' ')) + ' ' + color(result.slice(4).join(' ')));
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = () => {
|
||||
@@ -25,11 +36,14 @@ module.exports = () => {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
let color = null;
|
||||
const server = net.createServer((socket) => {
|
||||
socket.on("data", (data) => {
|
||||
const lines = data.toString().split('\n');
|
||||
for (let line of lines) if (line.length > 2) {
|
||||
_log(line);
|
||||
const newColor = getColor(line);
|
||||
if (newColor != null) color = newColor;
|
||||
_log(line, color);
|
||||
}
|
||||
});
|
||||
socket.on("close", () => {
|
||||
|
||||
Reference in New Issue
Block a user