mirror of
https://github.com/MCSManager/MCSManager.git
synced 2025-04-06 17:10:29 +08:00
Fix: log4js support to files
This commit is contained in:
parent
093140588f
commit
f6d158f819
@ -22,7 +22,7 @@ import koaStatic from "koa-static";
|
||||
import http from "http";
|
||||
import open from "open";
|
||||
|
||||
import { logger } from "./app/service/log";
|
||||
import { fileLogger, logger } from "./app/service/log";
|
||||
import { middleware as protocolMiddleware } from "./app/middleware/protocol";
|
||||
|
||||
// Routes
|
||||
@ -157,8 +157,8 @@ _ / / / / /___ ____/ /_ / / / / /_/ /_ / / / /_/ /_ /_/ // __/ /
|
||||
for (const iterator of ignoreUrls) {
|
||||
if (ctx.URL.pathname.includes(iterator)) return await next();
|
||||
}
|
||||
logger.info(`[HTTP] ${ctx.method}: ${ctx.URL.href}`);
|
||||
logger.info(`[HTTP] IP: ${ctx.ip} USER: ${ctx.session.userName} UUID: ${ctx.session.uuid}`);
|
||||
fileLogger.info(`[HTTP] ${ctx.method}: ${ctx.URL.href}`);
|
||||
fileLogger.info(`[HTTP] IP: ${ctx.ip} USER: ${ctx.session.userName} UUID: ${ctx.session.uuid}`);
|
||||
await next();
|
||||
});
|
||||
|
||||
|
@ -21,7 +21,7 @@ log4js.configure({
|
||||
pattern: "[%d{MM/dd hh:mm:ss}] [%[%p%]] %m"
|
||||
}
|
||||
},
|
||||
app: {
|
||||
file: {
|
||||
type: "file",
|
||||
filename: LOG_FILE_PATH,
|
||||
layout: {
|
||||
@ -32,13 +32,18 @@ log4js.configure({
|
||||
},
|
||||
categories: {
|
||||
default: {
|
||||
appenders: ["out", "app"],
|
||||
appenders: ["out", "file"],
|
||||
level: "info"
|
||||
},
|
||||
file: {
|
||||
appenders: ["file"],
|
||||
level: "info"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const logger = log4js.getLogger("default");
|
||||
const fileLogger = log4js.getLogger("file");
|
||||
|
||||
function fullTime(): string {
|
||||
const date = new Date();
|
||||
@ -49,4 +54,4 @@ function fullLocalTime(): string {
|
||||
return new Date().toLocaleTimeString();
|
||||
}
|
||||
|
||||
export { logger, fullTime, fullLocalTime };
|
||||
export { logger, fileLogger, fullTime, fullLocalTime };
|
||||
|
Loading…
x
Reference in New Issue
Block a user