2

I have a node.js server logging output to syslog. I am starting the server like this:

node app.js 2>&1 | logger -t app

I am using some node libraries to colorize the output (within the app code) and I can see all the colors fine in my laptop terminal running OSX but when ssh'ing into the machine and tailing /var/log/syslog I see no colors.

I am using rsyslog to send the logs to a third party logging service (Papertrail) but no colors there either.

I have tried adding

$IncludeConfig /etc/rsyslog.d/*.conf

to rsyslog.conf but no luck there as well.

Any ideas ? I'm starving for some log colors

  • "In my server I am using tools that colorize the logs outputs." What tools? "I can see all the colors fine in my laptop running OSX" you mean looking at some OSX logs, those are colored but ssh-ing to your server you don't? How you are viewing logs? Please clarify your question, I think it's very unclear as it is now. – Miroslav Koškár Apr 15 '15 at 13:45
  • @MiroslavKoskar Thanks, I tried focusing the question a little. Please let me know if you want further clarifications – Michael Apr 15 '15 at 13:58
3

Usually (I'm talking about standard tools with --color=auto), colors are echo-ed only on terminal. When STDOUT is NOT terminal you usually don't want colors. Skimming through library you linked, that's likely similar issue here (see FORCE_COLOR environment variable discussed there).

I think, what you are trying to accomplish is a bad idea. You really don't want logs to be written with colors. Subsequently, processing of such logs is very questionable.

You might consider some other coloring solution for viewing your logs like rainbow, (I'm not using it, just quickly searched through packages). Also feeding log into VIM, and creating syntax file would be an option.

But all of those will be an additional effort to specify patterns and all of that.

  • Adding colors to the log is a bad idea ? It will help me greatly focus on the important stuff vs the less important.PT also encourage it in their explanation and many other log services. Not talking about full blown double rainbow all the way. Just spice things up a little ;) – Michael Apr 15 '15 at 14:50
  • 1
    Well, it's a point of view. It's not black and white. Depends, on your use-case, what other systems process logs, etc. Consider, why your editor doesn't generate output of source file with ANSI escape sequences? Well, because we have syntax files for it. It would be nasty to deal with such file, and what if I have terminal which supports slightly different escape sequences? On the other hand, well written on-the-fly colorizer with clever generic patterns can be used anywhere consistently. On the other hand you can strip escape sequences easily. Well, you have to make compromise ;). – Miroslav Koškár Apr 15 '15 at 15:34
  • 1
    @Michael you probably want to run kibana+logstash which will present it how you're wanting and in a web browser. Writing colors to a plaintext file is a bad idea. vim does syntax highlighting but it doesn't sound like that's what you're wanting either. – Bratchley Apr 15 '15 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.