Pregunta

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 .

¿Fue útil?

Solución

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>

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top