Unix Programming - Syslog() prints the msg to the console????

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > September 2006 > Syslog() prints the msg to the console????





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Syslog() prints the msg to the console????
fazlin

2006-09-12, 7:26 am

Hi all,

I wrote a simple program that uses syslog() to print the message to the
log file. My problem is when i run my prog., the message i gave is sent
to the corresponding log file and also to the console. Does syslog
prints the messages in the console by default??? Or is there any other
way to avoid it???

My prog is:

#include <syslog.h>
#include <stdio.h>

void
main(int argc, char** argv)
{
openlog("TEST",LOG_PID, LOG_MAIL);

syslog(LOG_INFO,"Hai hello...");

closelog();
}

My syslog.conf file is shown below:

# cat /etc/syslog.conf
mail.debug /var/log/mail
user.debug /var/adm/usererr/error.09-12
#

The message "hai hello..." was printed in console and also appended to
/var/log/mail file.

Thanks,
Fazlin

David Schwartz

2006-09-12, 7:26 am


fazlin wrote:

> I wrote a simple program that uses syslog() to print the message to the
> log file. My problem is when i run my prog., the message i gave is sent
> to the corresponding log file and also to the console. Does syslog
> prints the messages in the console by default??? Or is there any other
> way to avoid it???


Read the manual or man pages for your 'syslog' program. You should be
able to set your syslog daemon to not send debug or info messages to
the console.

DS

fazlin

2006-09-12, 7:26 am


> David Schwartz wrote:
>
> Read the manual or man pages for your 'syslog' program. You should be
> able to set your syslog daemon to not send debug or info messages to
> the console.
>
> DS


I did go thro the man pages of syslog, syslogd, syslog.conf but couldnt
find anything useful

fazlin

2006-09-12, 7:26 am


> David Schwartz wrote:
>
> Read the manual or man pages for your 'syslog' program. You should be
> able to set your syslog daemon to not send debug or info messages to
> the console.
>
> DS


I did go thro the man pages of syslog, syslogd, syslog.conf but couldnt
find anything useful

David Schwartz

2006-09-12, 1:26 pm


fazlin wrote:

[vbcol=seagreen]
> I did go thro the man pages of syslog, syslogd, syslog.conf but couldnt
> find anything useful


Sorry, it's not standardized. Your operating system and particular
syslogd will determine how you control what messages are sent to the
console.

'man -k console' might find the right command for you.

DS

fazlin

2006-09-16, 1:43 pm

David Schwartz wrote:
> Sorry, it's not standardized. Your operating system and particular
> syslogd will determine how you control what messages are sent to the
> console.
>
> 'man -k console' might find the right command for you.
>
> DS


I did a little more investigation on this and here are the results:

I ran the program that uses syslog(shown in my first post) with "truss"
and i could see that the program opens and writes into /dev/conslog.
This is shown below:

# truss ./test
.....
.....
.....
open("/dev/conslog", O_WRONLY, 0) = 3
fcntl(3, F_SETFD, 0x00000001) = 0
fxstat(2, 3, 0x080473D4) = 0
time() = 1158174507
getpid() = 8862 [ 8861 ]
putmsg(3, 0x08047534, 0x08047544, 0) = 0
close(3) = 0
_exit(0)
#

and i turned on the debugging mode of syslogd and could see that
syslogd reads the message from /dev/log using "getmsg".

Now i m at a conclusion that the message is written to console
(/dev/conslog) even before syslogd reads the message and forwards it to
the appropriate file(as per syslog.conf).

Can anyone suggest me how i can proceed??

Fazlin

David Schwartz

2006-09-16, 1:43 pm


fazlin wrote:

> # truss ./test
> ....
> ....
> ....
> open("/dev/conslog", O_WRONLY, 0) = 3
> fcntl(3, F_SETFD, 0x00000001) = 0
> fxstat(2, 3, 0x080473D4) = 0
> time() = 1158174507
> getpid() = 8862 [ 8861 ]
> putmsg(3, 0x08047534, 0x08047544, 0) = 0
> close(3) = 0
> _exit(0)
> #
>
> and i turned on the debugging mode of syslogd and could see that
> syslogd reads the message from /dev/log using "getmsg".
>
> Now i m at a conclusion that the message is written to console
> (/dev/conslog) even before syslogd reads the message and forwards it to
> the appropriate file(as per syslog.conf).


On most operating systems that I know of, an attempt to log a message
will only write directly to the console if the normal logging mechanism
fails. Perhaps something is wrong with the way you are running syslogd.
Check if it tries anything else before wrinting to /dev/conslog,
something that fails to work property.

There may also be some kind of flag to 'openlog' to prevent console
logging. Check the man page.

DS

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com