Winston Logger - Exclude logging to syslog for console Transport

619 Views Asked by At

I have a node app running on EC2 Redhat. It's logging to syslog, and the logs are getting too big. However the configuration, has not defined any syslog transport.

const logger = createLogger({
  // change level if in dev environment versus production
  level: env === "development" ? "verbose" : "info",
  format: format.combine(
    format.timestamp({
      format: "YYYY-MM-DD HH:mm:ss",
    }),
    format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`)
  ),
  transports: [
    new transports.Console({
      level: "info",
      format: format.combine(
        format.colorize(),
        format.printf(
          (info) => `${info.timestamp} ${info.level}: ${info.message}`
        )
      ),
    }),
    dailyRotateFileTransport,
  ],
})

Is there a way to disable logging to syslog? Ideally from the node app. But if not, from syslog configuration itself.

2

There are 2 best solutions below

0
On BEST ANSWER

The following is what I did to resolve the space issue on my EC2.

Set StandardOutput=null (previously it was set to journald by default, not from service file ) now it's set to null.

enter image description here

server - Avoid systemd unit (service) to be logged in journal - Ask Ubuntu https://askubuntu.com/questions/1200680/avoid-systemd-unit-service-to-be-logged-in-journal

enter image description here

linux - how to disable systemd service start/stop notifications - Unix & Linux Stack Exchange https://unix.stackexchange.com/questions/547790/how-to-disable-systemd-service-start-stop-notifications#comment1016825_547817

0
On

Your app is logging to the console. I'm assuming the app is not being run by hand but via a systemd config and its directing stdout/stderr to journald or wherever its writing the outputs to.

This isn't a Node/Winston question really. You can either change where your app logs to (switch to a File transport with log rotation, and stop dumping to console), reduce the amount you log (actually use debug, etc... appropriately so the output doesn't get too big), or take a look at how your app is run in the first place and think it over (do you want systemd to clumsily hand your logging for you?)

Sure I'm assuming you're using systemd, but a console log transport doesn't log to syslog unless the app execution is directing stdout/stderr to it, like how systemd does.