mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Add http logging for express
This commit is contained in:
3 files changed
+14
-2
No files matched your search
@@ -30,6 +30,7 @@
|
|||||||
"set-blocking": "^2.0.0",
|
"set-blocking": "^2.0.0",
|
||||||
"webpack-cli": "^5.1.4",
|
"webpack-cli": "^5.1.4",
|
||||||
"winston": "^3.10.0",
|
"winston": "^3.10.0",
|
||||||
|
"express-winston": "^4.2.0",
|
||||||
"winston-daily-rotate-file": "^4.7.1",
|
"winston-daily-rotate-file": "^4.7.1",
|
||||||
"ws": "^8.13.0",
|
"ws": "^8.13.0",
|
||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { BlockList, type AddressInfo, isIPv4, isIPv6 } from "net";
|
|||||||
import type { ControllerArgs } from "../controller";
|
import type { ControllerArgs } from "../controller";
|
||||||
import express, { type Request, type Response, type NextFunction, type Application } from "express";
|
import express, { type Request, type Response, type NextFunction, type Application } from "express";
|
||||||
import type { Static } from "@sinclair/typebox";
|
import type { Static } from "@sinclair/typebox";
|
||||||
|
import * as expressWinston from "express-winston";
|
||||||
|
|
||||||
import compression from "compression";
|
import compression from "compression";
|
||||||
import events, { EventEmitter } from "events";
|
import events, { EventEmitter } from "events";
|
||||||
@@ -164,6 +165,10 @@ export default class Controller {
|
|||||||
this.app = express();
|
this.app = express();
|
||||||
this.app.locals.controller = this;
|
this.app.locals.controller = this;
|
||||||
this.app.locals.streams = new Map();
|
this.app.locals.streams = new Map();
|
||||||
|
this.app.use(expressWinston.logger({
|
||||||
|
winstonInstance: this.clusterLogger,
|
||||||
|
level: "http",
|
||||||
|
}));
|
||||||
|
|
||||||
this.trustedProxies = this.parseTrustedProxies();
|
this.trustedProxies = this.parseTrustedProxies();
|
||||||
this.wsServer = new WsServer(this);
|
this.wsServer = new WsServer(this);
|
||||||
@@ -283,6 +288,9 @@ export default class Controller {
|
|||||||
|
|
||||||
// Load plugins
|
// Load plugins
|
||||||
await this.loadPlugins();
|
await this.loadPlugins();
|
||||||
|
this.app.use(expressWinston.errorLogger({
|
||||||
|
winstonInstance: this.clusterLogger,
|
||||||
|
}));
|
||||||
|
|
||||||
this.wsServer = new WsServer(this);
|
this.wsServer = new WsServer(this);
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ export const levels = Object.freeze({
|
|||||||
audit: 3,
|
audit: 3,
|
||||||
info: 4,
|
info: 4,
|
||||||
server: 5,
|
server: 5,
|
||||||
verbose: 6,
|
http: 6,
|
||||||
|
verbose: 7,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const colors = {
|
export const colors = {
|
||||||
@@ -19,6 +20,7 @@ export const colors = {
|
|||||||
audit: "bold brightGreen",
|
audit: "bold brightGreen",
|
||||||
info: "bold brightBlue",
|
info: "bold brightBlue",
|
||||||
server: "bold",
|
server: "bold",
|
||||||
|
http: "bold grey",
|
||||||
verbose: "bold grey",
|
verbose: "bold grey",
|
||||||
} as const;
|
} as const;
|
||||||
winston.addColors(colors);
|
winston.addColors(colors);
|
||||||
@@ -163,7 +165,7 @@ export const logger = winston.createLogger({
|
|||||||
// Who in their right mind thought that log levels should be hard coded
|
// Who in their right mind thought that log levels should be hard coded
|
||||||
// into the type when you can define custom levels you want to support?
|
// into the type when you can define custom levels you want to support?
|
||||||
export type Logger = Omit<winston.Logger,
|
export type Logger = Omit<winston.Logger,
|
||||||
"error" | "warn" | "help" | "data" | "info" | "debug" | "prompt" | "http" | "verbose" | "input" | "silly" |
|
"error" | "warn" | "help" | "data" | "info" | "debug" | "prompt" | "verbose" | "input" | "silly" |
|
||||||
"emerg" | "alert" | "crit" | "warning" | "notice" |
|
"emerg" | "alert" | "crit" | "warning" | "notice" |
|
||||||
"child"
|
"child"
|
||||||
> & {
|
> & {
|
||||||
@@ -173,6 +175,7 @@ export type Logger = Omit<winston.Logger,
|
|||||||
audit: winston.LeveledLogMethod,
|
audit: winston.LeveledLogMethod,
|
||||||
info: winston.LeveledLogMethod,
|
info: winston.LeveledLogMethod,
|
||||||
server: winston.LeveledLogMethod,
|
server: winston.LeveledLogMethod,
|
||||||
|
http: winston.LeveledLogMethod,
|
||||||
verbose: winston.LeveledLogMethod,
|
verbose: winston.LeveledLogMethod,
|
||||||
child(options: object): Logger,
|
child(options: object): Logger,
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user