C / C ++ syslog for custom file (not / var / log / syslog, but / var / log / mylog) - ubuntu 12.04

I successfully tested the following hello world syslog example on ubuntu 12.04:

// gcc giuspexample.c -o giuspexample

#include <syslog.h>

int  main()
{
    setlogmask(LOG_UPTO (LOG_NOTICE));

    openlog("atm", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0);

    syslog(LOG_NOTICE, "Program started by User %d", getuid ());
    syslog(LOG_INFO, "A tree falls in a forest");

    closelog();
    return 0;
}

and I can read the entry in / var / log / syslog. I followed the instructions http://www.codealias.info/technotes/syslog_simple_example on how to change the path to the target file

echo "local0.*  /var/log/mylog" >> /etc/syslog.conf

but trying to run

sudo /etc/init.d/syslog restart

does not work (command not found) and restarting the computer in any case does not start writing to / var / log / mylog, but / var / log / syslog is still enabled. Does anyone know what happened? Thank.

+5
source share
1 answer

There /etc/rsyslog.dare two files in the directory :

  • 20-ufw.conf
  • 50-default.conf

I added a file /etc/rsyslog.d/30-mycustomname.confwith sudo nanothe following content:

# Log QSD Centro generated log messages to file
if $programname == 'centro' then /var/log/centro.log
# Uncomment the following to stop logging anything that matches the last rule.
& ~

, /var/log/centro.log

sudo rm -f /var/log/centro.log

sudo service rsyslog restart

, :

// gcc centro.c -o centro

#include <stdio.h>
#include <syslog.h>

int  main(int argc, char *argv[])
{
    openlog(NULL, 0, LOG_USER);

    syslog(LOG_INFO, "MORTACCI TUA!!!");

    closelog();
    return 0;
}
+8

All Articles