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;
}
On my Ubuntu machine, I can see the output at
/var/log/syslog
.On a RHEL/CentOS machine, the output is found in
/var/log/messages
.This is controlled by the
rsyslog
service, so if this is disabled for some reason you may need to start it withsystemctl start rsyslog
.As noted by others, your
syslog()
output would be logged by the/var/log/syslog
file.You can see system, user, and other logs at
/var/log
.For more details: here's an interesting link.