mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* WIP: initial logging changes add several transports in ~/config/winston omit messages in logs, truncate long strings add short blurb in dotenv for debug logging GoogleClient: using logger OpenAIClient: using logger, handleOpenAIErrors Adding typedef for payload message bumped winston and using winston-daily-rotate-file moved config for server paths to ~/config dir Added `DEBUG_LOGGING=true` to .env.example * WIP: Refactor logging statements in code * WIP: Refactor logging statements and import configurations * WIP: Refactor logging statements and import configurations * refactor: broadcast Redis initialization message with `info` not `debug` * refactor: complete Refactor logging statements and import configurations * chore: delete unused tools * fix: circular dependencies due to accessing logger * refactor(handleText): handle booleans and write tests * refactor: redact sensitive values, better formatting * chore: improve log formatting, avoid passing strings to 2nd arg * fix(ci): fix jest tests due to logger changes * refactor(getAvailablePluginsController): cache plugins as they are static and avoids async addOpenAPISpecs call every time * chore: update docs * chore: update docs * chore: create separate meiliSync logger, clean up logs to avoid being unnecessarily verbose * chore: spread objects where they are commonly logged to allow string truncation * chore: improve error log formatting
78 lines
1.7 KiB
JavaScript
78 lines
1.7 KiB
JavaScript
const path = require('path');
|
|
const winston = require('winston');
|
|
require('winston-daily-rotate-file');
|
|
|
|
const logDir = path.join(__dirname, '..', 'logs');
|
|
|
|
const { NODE_ENV } = process.env;
|
|
|
|
const levels = {
|
|
error: 0,
|
|
warn: 1,
|
|
info: 2,
|
|
http: 3,
|
|
verbose: 4,
|
|
debug: 5,
|
|
activity: 6,
|
|
silly: 7,
|
|
};
|
|
|
|
winston.addColors({
|
|
info: 'green', // fontStyle color
|
|
warn: 'italic yellow',
|
|
error: 'red',
|
|
debug: 'blue',
|
|
});
|
|
|
|
const level = () => {
|
|
const env = NODE_ENV || 'development';
|
|
const isDevelopment = env === 'development';
|
|
return isDevelopment ? 'debug' : 'warn';
|
|
};
|
|
|
|
const fileFormat = winston.format.combine(
|
|
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
winston.format.errors({ stack: true }),
|
|
winston.format.splat(),
|
|
);
|
|
|
|
const transports = [
|
|
new winston.transports.DailyRotateFile({
|
|
level: 'debug',
|
|
filename: `${logDir}/meiliSync-%DATE%.log`,
|
|
datePattern: 'YYYY-MM-DD',
|
|
zippedArchive: true,
|
|
maxSize: '20m',
|
|
maxFiles: '14d',
|
|
format: fileFormat,
|
|
}),
|
|
];
|
|
|
|
// if (NODE_ENV !== 'production') {
|
|
// transports.push(
|
|
// new winston.transports.Console({
|
|
// format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
|
|
// }),
|
|
// );
|
|
// }
|
|
|
|
const consoleFormat = winston.format.combine(
|
|
winston.format.colorize({ all: true }),
|
|
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`),
|
|
);
|
|
|
|
transports.push(
|
|
new winston.transports.Console({
|
|
level: 'info',
|
|
format: consoleFormat,
|
|
}),
|
|
);
|
|
|
|
const logger = winston.createLogger({
|
|
level: level(),
|
|
levels,
|
|
transports,
|
|
});
|
|
|
|
module.exports = logger;
|