0

i have a c program the code is

 setlogmask (LOG_UPTO (LOG_NOTICE));
 openlog ("thelog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
 syslog (LOG_NOTICE, "thelog : started by User %d", getuid ());
 syslog (LOG_INFO, "thelog: an info is logging");
 closelog();

the code is working properly BUT the issue is the log is being logged to the file /var/log/messages , i have /etc/rsyslog.conf no and syslog.conf

I want the logs to be logged to a new file /var/log/thelog.log file

how to fix this issue .

Kajal
  • 223
  • 4
  • 15

2 Answers2

3

If you want LOCAL1 to be logged to a separate file you

  1. tell syslog so by properly editing its config file
  2. have syslogd reload its config by sending a kill -HUP.

Configuration

Add a specific line for local1, like this one

local1.*                -/var/log/thelog.log

Before

*.*;mail.none;news.none    -/var/log/messages

and remove local1 from the configuration for local?.*

local0.*              -/var/log/localmessages
local2,local3.*       -/var/log/localmessages

Once the configuration file is ready

kill -HUP <pid-of-syslogd>
fvu
  • 32,488
  • 6
  • 61
  • 79
  • here local1 means ?? openlog ("thelog", >>>>>> openlog ("local1", – Kajal Jul 08 '13 at 13:04
  • These are actual lines from syslog's config file, `/etc/rsyslog.conf`. Open the file, read it and you'll see what I mean. – fvu Jul 08 '13 at 13:07
  • 2
    It seems that kill -HUP is not valid anymore. `man rsyslogd` reports that since v5, a "real restart" (e.g. /etc/rc.d/rsyslogd restart) is needed. – nephewtom Oct 07 '14 at 16:14
  • This does not work for me. I have a local1.* -/var/log/myfile.log BEFORE the *.*.;mail........ -/var/log/messages line, and have restarted rsyslog service to no avail. I still don't see /var/log/myfile.log file growing in size for example. Any other clues? – Chris F Mar 18 '16 at 20:26
0

You need to put this like -

local1.*                        -/var/log/myfile.log
*.*;auth,authpriv.none              -/var/log/syslog

restart syslogd service as
sudo service rsyslog restart

GSammy
  • 1
  • 1