How to check syslog in Bash on Linux?

前端 未结 6 1436
执念已碎
执念已碎 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:31

    tail -f /var/log/syslog | grep process_name where process_name is the name of the process we are interested in

    0 讨论(0)
  • 2021-01-31 13:39

    How about less /var/log/syslog?

    0 讨论(0)
  • 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)
    
    0 讨论(0)
  • 2021-01-31 13:52

    If you like Vim, it has built-in syntax highlighting for the syslog file, e.g. it will highlight error messages in red.

    vi +'syntax on' /var/log/syslog
    
    0 讨论(0)
  • 2021-01-31 13:54

    A very cool util is journalctl.

    For example, to show syslog to console: journalctl -t <syslog-ident>, where <syslog-ident> is identity you gave to function openlog to initialize syslog.

    0 讨论(0)
  • 2021-01-31 13:56

    On Fedora 19, it looks like the answer is /var/log/messages. Although check /etc/rsyslog.conf if it has been changed.

    0 讨论(0)
提交回复
热议问题