This doesn't print to the console in color. Everything is white. I've been Googling for hours. I'm running Ubuntu 17.
// Logging with Winston
const os = require('os')
const fs = require('fs')
const path = require('path')
const config = require('../data/config/config')
const winston = require('winston')
const { createLogger, format, transports } = winston
const tsFormat = () => (new Date()).toLocaleTimeString()
const logDir = path.resolve(os.homedir(), '.test-logs')
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir)
}
const logger = createLogger({
format: format.combine(
format.splat(),
format.simple()
),
transports: [
new transports.Console({ timestamp: tsFormat, level: config.logLevel, colorize: true }),
new transports.File({ filename: path.resolve(logDir, 'info.log'), level: 'info' }),
new transports.File({ filename: path.resolve(logDir, 'error.log'), level: 'error' })
]
})
module.exports = logger
I don't get any error messages or anything. It's just white.
Original Answer
You have to add colorize to the format when instantiating the logger. There was no example of this in their documentation. Their reference to a repo called
logForm
is done exactly as I just did. It should be a hyperlink instead. I might do a PR. The repo is hereI had to go to their examples directory to find this example.