Reputation: 10340
I have a fairly straight forward winston setup, where I add 3 transports to a custom logger:
import winston from 'winston';
import Logentries from 'winston-logentries';
const logger = new (winston.Logger)();
logger.add(winston.transports.Console, {
name: 'info-console',
level: 'info',
prettyPrint: true,
colorize: true,
silent: false,
timestamp: false,
});
logger.add(winston.transports.File, {
name: 'error-file',
prettyPrint: false,
level: 'warn',
silent: false,
colorize: false,
timestamp: true,
filename: `${__dirname}/../logs/error.log`,
maxsize: 40000,
maxFiles: 10,
json: false,
});
logger.add(winston.transports.Logentries, {
token: '--secret--',
level: 'warn',
});
export default logger;
Logging is really unreliable though. In the past, I had an issue with the file logger either logging only warnings or errors dending on the level I set for that transport (and not, as expected logging errors and warnings when I set my level to warn). Also sometimes it would just not log anything, but that seems to be a different story. Back then I did not have the third transport yet (Logentries
), now the file logger is better, apart from not logging anything sometimes, but Logentries
has the same behavior as the file logger back then, only logging the specific level set to it.
Upvotes: 2
Views: 1018