I override methods ('info', 'debug', 'error') of console to save logs in db, but when I try to save log with level 'debug', it isn`t saved.
Pino config:
import { pino } from 'pino';
export const getPinoLogger = (connectionMongoString) => {
const transport = pino.transport({
target: 'pino-mongodb',
options: {
uri: connectionMongoString,
database: 'my_db',
collection: 'my_collection',
},
levels: null
});
return pino(
{
base: null,
timestamp: false,
formatters: {
level: (label) => {
return { level: label };
}
}
},
transport
);
};
Code of overriding methods of console
['info', 'error', 'debug'].forEach((methodName) => {
console[methodName] = (...args) => {
const pinoLogger = getPinoLogger(configService.get<string>('connection_string'));
try {
throw new Error();
} catch(ex) {
const callPlace = parse(ex.stack)[1];
const logObject = {
message: (args[0] ?? '') + ` (${callPlace?.methodName} at ${callPlace?.lineNumber})`,
timestamp: Date.now(),
userName: '',
};
switch (methodName) {
case 'info':
Logger.log(args[0]);
pinoLogger.info(logObject);
break;
case 'error':
Logger.error(args[0]);
pinoLogger.error(logObject);
break;
case 'debug':
Logger.debug(args[0]);
pinoLogger.debug(logObject)
break;
}
}
};
});
Ive tried to set level 'trace' to save any logs, but it hasn
t helped me.
const transport = pino.transport({
target: 'pino-mongodb',
options: {
uri: connectionMongoString,
database: 'my_db',
collection: 'my_collection',
level: 'trace'
},
levels: null
});