mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
32 lines
883 B
TypeScript
32 lines
883 B
TypeScript
|
import path from "path";
|
||
|
import { format } from "util";
|
||
|
import winston from "winston";
|
||
|
import { getWaveDataDir, isDev } from "./platform";
|
||
|
|
||
|
const oldConsoleLog = console.log;
|
||
|
|
||
|
const loggerTransports: winston.transport[] = [
|
||
|
new winston.transports.File({ filename: path.join(getWaveDataDir(), "waveapp.log"), level: "info" }),
|
||
|
];
|
||
|
if (isDev) {
|
||
|
loggerTransports.push(new winston.transports.Console());
|
||
|
}
|
||
|
const loggerConfig = {
|
||
|
level: "info",
|
||
|
format: winston.format.combine(
|
||
|
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }),
|
||
|
winston.format.printf((info) => `${info.timestamp} ${info.message}`)
|
||
|
),
|
||
|
transports: loggerTransports,
|
||
|
};
|
||
|
const logger = winston.createLogger(loggerConfig);
|
||
|
function log(...msg: any[]) {
|
||
|
try {
|
||
|
logger.info(format(...msg));
|
||
|
} catch (e) {
|
||
|
oldConsoleLog(...msg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export { log };
|