(L)ubuntu 12.04 syslog to custom file (not /var/log/syslog but /var/log/mylog) - ubuntu 12.04

I efficiently examined the adhering to syslog "hello world" instance on ubuntu 12.04:

// gcc giuspexample.c -o giuspexample

#include <syslog.h>

int  main(int argc, char *argv[])
{
    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 also I can read the access in/ var/log/syslog. I adhered to the guidelines on http://www.codealias.info/technotes/syslog_simple_example on just how to transform the location filepath

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

yet attempting to run

sudo /etc/init.d/syslog restart

does not function (command not located) and also restarting the computer anyhow does not start to write on/ var/log/mylog yet still on/ var/log/syslog. Does any person recognize what is incorrect? Many thanks.

6
2022-06-07 14:32:22
Source Share
Answers: 2

By default Ubuntu makes use of rsyslog. It is arrangement files remain in

/etc/rsyslog.conf

And

/etc/rsyslog.conf
2
2022-06-07 14:56:48
Source

Here is just how I did well.

In my folder/ etc/rsyslog. d there are 2 documents:

20 - ufw.conf and also 50 - default.conf

I included a documents:

sudo nano /etc/rsyslog.d/30-mycustomname.conf

With the adhering to web 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.
& ~

Then I examine that the documents/ var/log/centro. log does not exist

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

Then I reactivate the solution

sudo service rsyslog restart

Finally The adhering to code jobs:

// 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;
}
5
2022-06-07 14:50:40
Source