Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to get a bash script to log to a custom log file using syslog on Centos release 6.5, but it always just logs to /var/log/messages like so:

Jan 12 09:54:47 localhost nbsp: Test message blah!

What am I doing wrong? Why isn't it logging to /var/log/my_prog_test.log? Here's are my configs and files.

/etc/rsyslog.conf (most of file omitted):

if $programname == 'my_prog_test' then {
   action(type="omfile" file="/var/log/my_prog_test.log")
}

After making the changes to rsyslog.conf I ran...

$ sudo /etc/rc.d/init.d/rsyslog restart
Shutting down system logger:                               [  OK  ]
Starting system logger:                                    [  OK  ]

... so rsyslog was restarted after the config change.

The bash script /home/nbsp/bin/my_prog_test looks like this:

#!/bin/bash

logger 'Test message blah!'

The log file listing:

$ ls -la /var/log/ | grep my_prog_test
-rw-------.  1 root root      0 Jan 11 09:23 my_prog_test.log

The symlink...

$ ls -la /usr/bin/my_prog_test
lrwxrwxrwx. 1 root root 29 Jan 12 08:54 /usr/bin/my_prog_test -> /home/nbsp/bin/my_prog_test

The program's listing:

$ ls -la bin/my_prog_test
-rwxrwxr-x. 1 nbsp nbsp 50 Jan 12 09:09 bin/my_prog_test
share|improve this question

1 Answer 1

Your script is calling logger(1) to write something to syslog. Thus rsyslog will see the program name "logger" doing the write and not "my_prog_test".

For what you want to achieve call logger(1) with "-p local0.notice" and in rsyslog.conf filter by the facility "local0" instead of program name "my_prog_test"..

According to the documentation for rsyslog on my system (Debian Wheezy with rsyslog 7.4.4 from backports) the latter would then be expressed as:

  if $syslogfacility-text == 'local0' then {
     action(type="omfile" file="/var/log/my_prog_test.log")
  }

This should also work and would be simpler for this case:

  local0.* /var/log/my_prog_test.log

If on your system the syslog facility local0 already gets used for such a purpose, you can instead use local1 up to local7 instead.

share|improve this answer
    
Using the above in the rsyslog.conf with the command logger -p local0.notice "hello world" it still logs to /etc/log/messages. –  nbsp Jan 16 at 1:48
    
On a machine setup for testing I tried both ways. The first one was giving me some error, which I didn't yet further investigate. The latter (simpler) way of configuring this worked as expected, though. –  Stefan Eggers Jan 26 at 15:20
    
If you also want to suppress logging to /var/log/messages you might want to also add a discard rule local0.* ~. And be careful with the ordering of the rules. –  Stefan Eggers Jan 26 at 15:31
    
What does your call the call to logger look like in your bash script? –  nbsp Jan 30 at 1:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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