Open happy-machine opened 4 years ago
Just for clarity, this is what i think i should be writing here!
import { createLogger, format, transports, addColors } from "winston";
var fluentLogger = require("fluent-logger");
const winstonTransportConfigFactory = type => {
addColors({
error: "red",
warn: "yellow",
info: "cyan",
debug: "green"
});
if (type === "file")
return {
//store warn and above locally
filename: "./logs/local.log",
level: "warn",
colorize: true
};
if (type === "console")
return {
format: format.combine(format.simple(), format.colorize()),
colorize: true
};
if (type === "fluentd")
return {
colorize: false
};
};
const fluent = new (fluentLogger.support.winstonTransport(
winstonTransportConfigFactory("fluentd")
))("agronomy-api.test", {
host: "localhost",
port: 24224,
timeout: 3.0,
requireAckResponse: true
});
const logger = createLogger({
level: "debug",
exitOnError: false,
format: format.simple(),
transports: [
new transports.Console(winstonTransportConfigFactory("console")),
new transports.File(winstonTransportConfigFactory("file")),
fluent
]
});
logger.on("flush", () => {
console.log("Flush");
});
logger.on("finish", () => {
console.log(`Finish: ${fluent.sender}`);
fluent.sender.end("end", {}, () => {});
});
export default logger;
Hey folks
I apologise in advance ive read previous issues and stack overflow about this and cant seem to find a resolution. Ive even tried resorting to injecting a fluend plugin to remove color formatting before logs are sent to elasticsearch, this is clearly not best practice, it shouldnt be necessary to send something and then remove it i think.
If i remove the loggers format property the transport formats dont have any effect See below (i am caching levels warn and above in a local directory)
I have used colorize as well as running the fomat.colorize function as there are mixed messages floating around about this i wasnt clear on how to do this and figured it wouldnt do any harm to overwrite this property if it did already exist?