1819848 Members
2559 Online
109607 Solutions
New Discussion юеВ

Re: Dmesg and Syslog

 
SOLVED
Go to solution
rccmum
Super Advisor

Dmesg and Syslog

Hi All,

As I understand the dmesg command refers the system diagnostics message buffer. Syslog is destination of log messages for most of the system entities running on the system.

Does someone know, the difference between these two as far the logging of all kind messages are concerned? Is there something which only appears in dmesg but not in syslog or vice versa ?

If everything appears in syslog which dmesg can see, then why dmesg is used?
Is it possible to access the dmesg buffer and syslog buffer through a C code?

Thanks in advance
4 REPLIES 4
Pete Randall
Outstanding Contributor

Re: Dmesg and Syslog

You are correct that dmessage is for diagnostics. Those diagnostic messages do not go to syslog. Syslog receives messages according to how it is configured in /etc/syslog.conf.

Check the man pages for dmesg and syslogd for details.


Pete

Pete
James R. Ferguson
Acclaimed Contributor
Solution

Re: Dmesg and Syslog

Hi:

Yes, 'dmesg' is a finite (small!) circular buffer used to receive system diagnostic messages like LVM path switches, etc.

You will indeed see the contents of 'dmesg' within '/var/adm/syslog/syslog.log'. While the dmesg buffer is small and circular, its value lies in being quickly able to peek at "important" events.

Insofar as the 'syslog' is concerned, you can add to it from a shell script with 'logger'. From a C program your interface comes in the form of 'syslog()'. See the manpages for 'logger(1)' and 'syslog(3C)' for more information.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Dmesg and Syslog

The dmesg buffer which is a fixed-size circular buffer exists as kernel memory so that it is always available for error dumping even when other facilities such as syslogd are not available (e.g. before /var is mounted). You should really think of dmesg as a sort of weapon of last resort. The system will always have it but its size is limited. By logging to both syslog and dmesg there is a high proability that at least part of a critical message will be captured.

You can certainly use C to access dmesg with nothing more complicated than:

FILE *f = NULL;

f = popen("dmesg","r");

There is a function, syslog, to allow you to write to syslog. Man 3 syslog for details. Because syslog is simply a text file, you can fopen() /var/adm/syslog/syslog.log and read it to your heart's content.
If it ain't broke, I can fix that.
rccmum
Super Advisor

Re: Dmesg and Syslog

Thanks for the inside ACS!!!
Now I know where from "dmesg" pick up the data.