Howto change syslog log level?

Hi there,

I wrote an application that writes logging messages using syslog() and I want to change the log level in order to see also messages at info and debug level.
Problem is that I cannot find the configuration file for syslog.
Does somebody know where this file is located and what the name is?

System is Leap 15.5.

Thanks.

It is up to your application to tell syslog what level to use.

@Teuniz:

Yes, the man 3 syslog() page is a little bit confusing but –

       #include <syslog.h>

       void openlog(const char *ident, int option, int facility);
       void syslog(int priority, const char *format, ...);

You have to OR the facility value and a level value to achieve an appropriate for the priority parameter value of each and every call to “syslog()” …

  • Values for level –
       LOG_INFO       informational message

       LOG_DEBUG      debug-level message

And, please, please please – DO NOT FORGET to close the connection to the system logger before your program exits!!

  • Assuming that, the thing doesn’t crash … :imp:
       void closelog(void);

“man 8 syslog” provides the following information relevant to openSUSE and SUSE systems –

       The /etc/sysconfig/syslog file contains several variables allowing to specify  additional  settings,  such  as
       start  parameters for the daemon or additional chroot log sockets.  The yast2 sysconfig module provides a com-
       fortable way to change these settings.

       Starting with openSUSE-12.3, the SYSLOG_DAEMON variable, which was used to select the daemon before, has  been
       removed.  Also  the  SYSLOG_REQUIRES_NETWORK  has  been  removed  and each daemon declares in its service file
       whether the network will be started before syslog or not.

I guess I expressed myself wrong…
I know how to use the function syslog().
The problem is that the rsyslog service which receives the messages,
filters them based on the logging level.
For example, in case of Leap, the rsyslog deamon only writes to the logfiles the messages with level error or worse (critical, etc) and not the messages with level debug or info.
This needs to be configured at system level with super privileges.

In the mean time, I found the configuration file, it’s /etc/rsyslog.conf and the files in /etc/rsyslog.d/

I simply created a new file /etc/rsyslog.d/myprog.conf

with the content:

if ($programname == 'myprog') \
then {
  -/var/log/myprog
  stop
}

This causes to write all messages coming from myprog to a separate file with no filtering.

I was confused because it appears that syslog has been replaced by rsyslog.

Thanks for trying to help.

Teuniz

This change was already introduced 2013 together with the change from deprecated sysvinit to systemd.

1 Like

I believe you but it’s the first time I’m using syslog() in my programs and when duckduckgoing for solutions I found mostly references to syslog instead of rsyslog.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.