How to check syslog in Bash on Linux?

前端 未结 6 1733
执念已碎
执念已碎 2021-01-31 13:20

In C we log this way:

syslog( LOG_INFO, \"proxying %s\", url );

In Linux how can we check the log?

6条回答
  •  忘掉有多难
    2021-01-31 13:50

    By default it's logged into system log at /var/log/syslog, so it can be read by:

    tail -f /var/log/syslog
    

    If the file doesn't exist, check /etc/syslog.conf to see configuration file for syslogd. Note that the configuration file could be different, so check the running process if it's using different file:

    # ps wuax | grep syslog
    root      /sbin/syslogd -f /etc/syslog-knoppix.conf
    

    Note: In some distributions (such as Knoppix) all logged messages could be sent into different terminal (e.g. /dev/tty12), so to access e.g. tty12 try pressing Control+Alt+F12.

    You can also use lsof tool to find out which log file the syslogd process is using, e.g.

    sudo lsof -p $(pgrep syslog) | grep log$ 
    

    To send the test message to syslogd in shell, you may try:

    echo test | logger
    

    For troubleshooting use a trace tool (strace on Linux, dtruss on Unix), e.g.:

    sudo strace -fp $(cat /var/run/syslogd.pid)
    

提交回复
热议问题