I wrote a simple test application to log something in a log file. I am using linux mint and after the application executes I try to view the log using this command:
tail -n 100 /var/log/messages
but the file messages does not exist neither tested or something. Below you can find my code. Maybe I am doing something wrong, the file isn't stored there or I need to enable logging in linux mint.
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
void init_log()
{
setlogmask(LOG_UPTO(LOG_NOTICE));
openlog("testd",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
}
int main(void) {
init_log();
printf("Session started!");
syslog(LOG_NOTICE, "Session started!!");
closelog();
return EXIT_SUCCESS;
}
In addition to the accepted answer, it is useful to know the following ...
Each of those functions should have manual pages associated with them.
If you run
man -k syslog
(a keyword search of man pages) you will get a list of man pages that refer to, or are about syslogYou need to understand the manual sections in order to delve further.
Here's an excerpt from the man page for man, that explains man page sections :
To read the above run
So, if you run
man 3 syslog
you get a full manual page for thesyslog
function that you called in your code.Not a direct answer but hopefully you will find this useful.
syslog() generates a log message, which will be distributed by syslogd.
The file to configure syslogd is /etc/syslog.conf. This file will tell your where the messages are logged.
How to change options in this file ? Here you go http://www.bo.infn.it/alice/alice-doc/mll-doc/duix/admgde/node74.html
I'm running Ubuntu under WSL(Windows Subsystem for Linux) and
systemctl start rsyslog
didn't work for me.So what I did is this:
Now
syslog
file will appear at/var/log/
You have to tell the system what information to log and where to put the info. Logging is configured in the
/etc/rsyslog.conf
file, then restart rsyslog to load the new config. The default logging rules are usually in a/etc/rsyslog.d/50-default.conf
file.Logging is very configurable in Linux, and you might want to look into your
/etc/syslog.conf
(or perhaps under/etc/rsyslog.d/
). Details depend upon the logging subsystem, and the distribution.Look also into files under
/var/log/
(and perhaps rundmesg
for kernel logs).Default log location (rhel) are
General messages:
Authentication messages:
Mail events:
Check your
/etc/syslog.conf
or/etc/syslog-ng.conf
(it depends on which of syslog facility you have installed)Example: