mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-30 23:55:49 +02:00
bootstrapped
This commit is contained in:
parent
b7c1716fa7
commit
d2e35b4a1f
24 changed files with 15511 additions and 5203 deletions
67
server/logger.ts
Normal file
67
server/logger.ts
Normal file
|
@ -0,0 +1,67 @@
|
|||
import "winston-daily-rotate-file";
|
||||
|
||||
import environment from "@server/environment";
|
||||
import * as winston from "winston";
|
||||
|
||||
const hformat = winston.format.printf(
|
||||
({ level, label, message, timestamp, ...metadata }) => {
|
||||
let msg = `${timestamp} [${level}]${label ? `[${label}]` : ""}: ${message} `;
|
||||
if (Object.keys(metadata).length > 0) {
|
||||
msg += JSON.stringify(metadata);
|
||||
}
|
||||
return msg;
|
||||
},
|
||||
);
|
||||
|
||||
const transports: any = [
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.splat(),
|
||||
winston.format.timestamp(),
|
||||
hformat,
|
||||
),
|
||||
}),
|
||||
];
|
||||
|
||||
if (environment.SAVE_LOGS) {
|
||||
transports.push(
|
||||
new winston.transports.DailyRotateFile({
|
||||
filename: `${environment.CONFIG_PATH}/logs/pangolin-%DATE%.log`,
|
||||
datePattern: "YYYY-MM-DD",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "7d",
|
||||
createSymlink: true,
|
||||
symlinkName: "pangolin.log",
|
||||
}),
|
||||
);
|
||||
transports.push(
|
||||
new winston.transports.DailyRotateFile({
|
||||
filename: `${environment.CONFIG_PATH}/logs/.machinelogs-%DATE%.json`,
|
||||
datePattern: "YYYY-MM-DD",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "1d",
|
||||
createSymlink: true,
|
||||
symlinkName: ".machinelogs.json",
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.splat(),
|
||||
winston.format.json(),
|
||||
),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const logger = winston.createLogger({
|
||||
level: environment.LOG_LEVEL.toLowerCase(),
|
||||
format: winston.format.combine(
|
||||
winston.format.splat(),
|
||||
winston.format.timestamp(),
|
||||
hformat,
|
||||
),
|
||||
transports,
|
||||
});
|
||||
|
||||
export default logger;
|
Loading…
Add table
Add a link
Reference in a new issue