6

I m using syslog in myprograme to generate log messages.

Is there a way to send the syslog output of my program to stdout ?

I do not want to use the tail command to see my program log, I would like to see it directly on the console

MOHAMED
  • 41,599
  • 58
  • 163
  • 268
  • 1
    It's a matter of configuring the `syslog` daemon. However, you cannot really predict what "standard output" means in any given context, so running `tail` on a file is probably the simplest. For example, if you have `root` logged in to `/dev/ttyS0` and yourself on `/dev/pts/17` and `/dev/pts/42`, should it write to all three, or just a subset? What if one of them is a `screen` session or something? A crucial interactive dialog? There are a *lot* of complications. – tripleee Mar 07 '14 at 14:21

2 Answers2

6

You'll want to edit your /etc/syslog.conf file.

depending on exactly what facility you're sending to syslogd, you'll need to add a line something like this:

<facility>.debug    /dev/console

be sure to check out man 5 syslog.conf for all the details..

problemPotato
  • 589
  • 3
  • 8
  • 1
    I needed to run `cron` in a `docker` container (`php:7.4-fpm`), which doesn't seem to log to anything but `rsyslog` (`/dev/log`). And what worked for me is `*.* /dev/stdout` (`/dev/console` didn't exist, specifying `/dev/tty` made no difference). – x-yuri Nov 06 '20 at 21:48
  • Also using Docker here -- my container is debian-based, so I needed to `apt-get install rsyslog`, add `cron.* /dev/console` to `/etc/rsyslog.conf`, and `service rsyslog start` -- then I could `cron -f` to run it in the foreground and see output on stdout. – NReilingh Dec 13 '22 at 17:47
  • Correction -- `/dev/console` only seemed to work when I was in an interactive session. I realized that these targets were relative to `rsyslogd`, not `cron`, so I ended up running `rsyslogd` in the foreground (`-n`) and targeting `/dev/stdout`. – NReilingh Dec 13 '22 at 18:43
3

To continuously clone file output to a console/shell use the following command in that console/shell:

tail -f <logfile> &

-f makes tail continue printing whatever gets written to the file

& puts the process in the background so you can do other stuff in the window. Omit the & if you want the console to block until you press ctrl+c.

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
  • Hi Klas, In case I am debugging application with eclipse, can I use your suggested method for directing the output to stdout, or do I need to do it in some other way ? Thanks. – ransh Oct 01 '15 at 18:47
  • If your application logs to file you can always use my suggested method. Just make sure the log function flushes the output buffer, because file I/O is ususally block buffered (and not line buffered like console I/O). – Klas Lindbäck Oct 06 '15 at 07:13