Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does linux store my syslog?

Tags:

c

linux

logging

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; } 
like image 280
opc0de Avatar asked Jun 11 '12 11:06

opc0de


People also ask

Where does syslog reside in Unix?

The file to configure syslogd is /etc/syslog. conf. This file will tell your where the messages are logged.

Where is the syslog server log file is stored?

Syslog is a standard logging facility. It collects messages of various programs and services including the kernel, and stores them, depending on setup, in a bunch of log files typically under /var/log . In some datacenter setups there are hundreds of devices each with its own log; syslog comes here handy too.

Where is syslog stored in Ubuntu?

The system log typically contains the greatest deal of information by default about your Ubuntu system. It is located at /var/log/syslog, and may contain information other logs do not.


2 Answers

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 with systemctl 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.

like image 147
TheCottonSilk Avatar answered Oct 18 '22 05:10

TheCottonSilk


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 syslog

$ man -k syslog logger (1)           - a shell command interface to the syslog(3) system l... rsyslog.conf (5)     - rsyslogd(8) configuration file rsyslogd (8)         - reliable and extended syslogd syslog (2)           - read and/or clear kernel message ring buffer; set c... syslog (3)           - send messages to the system logger vsyslog (3)          - send messages to the system logger 

You 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 :

The table below shows the section numbers of the manual followed  by the types of pages they contain.     1   Executable programs or shell commands    2   System calls (functions provided by the kernel)    3   Library calls (functions within program libraries)    4   Special files (usually found in /dev)    5   File formats and conventions eg /etc/passwd    6   Games    7   Miscellaneous  (including  macro  packages and conven‐        tions), e.g. man(7), groff(7)    8   System administration commands (usually only for root)    9   Kernel routines [Non standard] 

To read the above run

$man man  

So, if you run man 3 syslog you get a full manual page for the syslog function that you called in your code.

SYSLOG(3)                Linux Programmer's Manual                SYSLOG(3)  NAME    closelog,  openlog,  syslog,  vsyslog  - send messages to the system    logger  SYNOPSIS    #include <syslog.h>     void openlog(const char *ident, int option, int facility);    void syslog(int priority, const char *format, ...);    void closelog(void);     #include <stdarg.h>     void vsyslog(int priority, const char *format, va_list ap); 

Not a direct answer but hopefully you will find this useful.

like image 30
Rob Kielty Avatar answered Oct 18 '22 06:10

Rob Kielty