mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(core): Reduce logging overhead for levels that do not output (#7479)
all current logging calls execute `callsites()` to figure out what code tried to log. This happens even for logging methods that aren't supposed to create any output. Under moderate load, this can take up quite a lot of resources. This PR changes the logger to make all ignorable logging methods a No-Op. In a small benchmark with a simple webhook, with log-level set to `warn`, and using `ab -c 50 -n 500 http://localhost:5678/webhook/testing`, these were the response times: ### Before  ### After 
This commit is contained in:
committed by
GitHub
parent
0b42d1aa71
commit
76c04815f7
@@ -9,22 +9,32 @@ import callsites from 'callsites';
|
||||
import { basename } from 'path';
|
||||
import config from '@/config';
|
||||
|
||||
const noOp = () => {};
|
||||
const levelNames = ['debug', 'verbose', 'info', 'warn', 'error'] as const;
|
||||
|
||||
export class Logger implements ILogger {
|
||||
private logger: winston.Logger;
|
||||
|
||||
constructor() {
|
||||
const level = config.getEnv('logs.level');
|
||||
|
||||
const output = config
|
||||
.getEnv('logs.output')
|
||||
.split(',')
|
||||
.map((output) => output.trim());
|
||||
|
||||
this.logger = winston.createLogger({
|
||||
level,
|
||||
silent: level === 'silent',
|
||||
});
|
||||
|
||||
// Change all methods with higher log-level to no-op
|
||||
for (const levelName of levelNames) {
|
||||
if (this.logger.levels[levelName] > this.logger.levels[level]) {
|
||||
Object.defineProperty(this, levelName, { value: noOp });
|
||||
}
|
||||
}
|
||||
|
||||
const output = config
|
||||
.getEnv('logs.output')
|
||||
.split(',')
|
||||
.map((output) => output.trim());
|
||||
|
||||
if (output.includes('console')) {
|
||||
let format: winston.Logform.Format;
|
||||
if (['debug', 'verbose'].includes(level)) {
|
||||
|
||||
Reference in New Issue
Block a user