simple-node-logger
simple-node-logger copied to clipboard
Can I disable console output and only leave file output?
I am trying to create a system where in development mode I write errors to log files and also to the console, but in production I only want to write to log file.
This is how my logger looks like:
export const Log = simpleNodeLogger.createRollingFileLogger({
errorEventName: 'error',
logDirectory: 'logs',
fileNamePattern: 'log-<DATE>.log',
dateFormat: 'YYYY-MM-DD'
});
if (process.env.NODE_ENV === 'production') {
// disable console output, only leave file write
}
I haven't found any config parameters for disabling console logging. I also tried using appenders, but I don't understand them at all and I didn't have luck.
Yes, i need this too. Please anyone can solve this problem?
I started using this lib today and needed this function as well, and after a quick look through the source this can simply be accomplished by:
import SimpleLogger from 'simple-node-logger'; // const SimpleLogger = require('simple-node-logger');
function createLogger(enableConsole, opts) { // opts is the normal opts you'd pass in like logFilePath or timestampFormat
const manager = new SimpleLogger(opts);
if (enableConsole) {
manager.createConsoleAppender(opts);
}
if (opts.logFilePath) {
manager.createFileAppender(opts);
}
return manager.createLogger();
}
...
const myLogger = createLogger(false, {
logFilePath: path.join(__dirname, `logs/MyLog.log`),
timestampFormat: 'YY-MM-DD HH:mm:ss.SSS'
});
myLogger.info('Test log out string');
Hello, facing the same problem, no need to create a custom function, just use
createSimpleFileLogger
const logger = require('simple-node-logger').createSimpleFileLogger('./logs/success.log');
const logger2 = require('simple-node-logger').createSimpleFileLogger('./logs/errors.log');