[+] 格式化
This commit is contained in:
@@ -10,8 +10,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ws": "^8.12.0",
|
"ws": "^8.12.0",
|
||||||
|
"moment": "^2.29.4",
|
||||||
"mediasoup": "file:./mediasoup"
|
"mediasoup": "file:./mediasoup"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ module.exports = {
|
|||||||
name: "taoyao-media-server",
|
name: "taoyao-media-server",
|
||||||
// 交互式命令行
|
// 交互式命令行
|
||||||
command: true,
|
command: true,
|
||||||
|
// 日志级别
|
||||||
|
logLevel: 'DEBUG',
|
||||||
// 信令服务
|
// 信令服务
|
||||||
https: {
|
https: {
|
||||||
listenIp: "0.0.0.0",
|
listenIp: "0.0.0.0",
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* 日志
|
* 日志
|
||||||
*/
|
*/
|
||||||
|
const moment = require('moment')
|
||||||
const config = require("./Config");
|
const config = require("./Config");
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
|
|
||||||
//
|
// 名称
|
||||||
name = config.name;
|
name = config.name;
|
||||||
|
// 级别
|
||||||
|
level = [ "DEBUG", "INFO", "WARN", "ERROR", "OFF" ];
|
||||||
|
// 级别索引
|
||||||
|
levelIndex = this.level.indexOf(config.logLevel.toUpperCase());
|
||||||
|
|
||||||
constructor(prefix) {
|
constructor(prefix) {
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
@@ -15,32 +20,33 @@ class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug(...args) {
|
debug(...args) {
|
||||||
this.log(console.debug, 'DEBUG', args);
|
return this.log(console.debug, '37m', 'DEBUG', args);
|
||||||
}
|
}
|
||||||
|
|
||||||
info(...args) {
|
info(...args) {
|
||||||
this.log(console.info, 'INFO', args);
|
return this.log(console.info, '32m', 'INFO', args);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn(...args) {
|
warn(...args) {
|
||||||
this.log(console.warn, 'WARN', args);
|
return this.log(console.warn, '33m', 'WARN', args);
|
||||||
}
|
}
|
||||||
|
|
||||||
error(...args) {
|
error(...args) {
|
||||||
this.log(console.error, 'ERROR', args);
|
return this.log(console.error, '31m', 'ERROR', args);
|
||||||
}
|
}
|
||||||
|
|
||||||
log(out, level, args) {
|
log(out, color, level, args) {
|
||||||
if(!args) {
|
if(!args || this.level.indexOf(level) < this.levelIndex) {
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
if(args.length > 1 && args[0].length > 0) {
|
if(args.length > 1 && args[0].length > 0) {
|
||||||
out(`${this.name}:${level}:${args[0]}`, ...args.slice(1));
|
out(`\x1B[${color}${this.name} ${moment().format('yyyy-MM-DD HH:mm:ss')} : [${level.padEnd(5, ' ')}] : ${args[0]}\x1B[0m`, ...args.slice(1));
|
||||||
} else if(args.length === 1 && args[0].length > 0) {
|
} else if(args.length === 1 && args[0].length > 0) {
|
||||||
out(`${this.name}:${level}:${args[0]}`);
|
out(`\x1B[${color}${this.name} ${moment().format('yyyy-MM-DD HH:mm:ss')} : [${level.padEnd(5, ' ')}] : ${args[0]}\x1B[0m`);
|
||||||
} else {
|
} else {
|
||||||
out("");
|
out("");
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ let webSocketServer;
|
|||||||
const mediasoupWorkers = [];
|
const mediasoupWorkers = [];
|
||||||
|
|
||||||
process.title = config.name;
|
process.title = config.name;
|
||||||
process.env.DEBUG = process.env.DEBUG || "*mediasoup* *INFO* *WARN* *ERROR*";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动Mediasoup Worker
|
* 启动Mediasoup Worker
|
||||||
@@ -123,6 +122,7 @@ async function buildSignalServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
logger.debug("DEBUG").info("INFO").warn("WARN").error("ERROR");
|
||||||
logger.info("开始启动:%s", config.name);
|
logger.info("开始启动:%s", config.name);
|
||||||
// 启动Mediasoup服务
|
// 启动Mediasoup服务
|
||||||
// await buildMediasoupWorkers();
|
// await buildMediasoupWorkers();
|
||||||
|
|||||||
Reference in New Issue
Block a user