SUMMARY : syslog(3) and openlog(3)

From: Steve Jones <Seve.Jones_at_softhome.net>
Date: Thu Feb 28 2002 - 06:58:47 EST
Thanks to Eric van de Meerakker for providing the clue to the answer,
which is:

embed control characters in the message text

In my case, embedding newlines achieves the desired result. So:

syslog(LOG_NOTICE, "%s\n%s\n%s", "test", "Test", "TEst");

produces:

Feb 28 11:31:13 mybox myprog[19621]: test
Feb 28 11:31:13 mybox Test
Feb 28 11:31:13 mybox TEst

Which is precisely what I wished to achieve.

Note, however, that this behaviour (of syslog(3) and logger(1))
appears to be peculiar to Solaris. If I run the same program
on Linux and AIX (or if I run an equivalent logger command
under these OS), the embedded newlines are NOT honoured,
and the message text appears as a single, continuous string
(syslog(3), on these OS, appears to convert the embedded
newlines to blanks). On the other hand, I haven't witnessed
multi-line messages in my Linux and AIX syslogd output ...

Thanks for listening ...

sj

====

Original query follows;

Does anyone know how to write 'non-standard' messages to syslogd? The
syslog(3) and openlog(3) routines force the 'message body' to be
prepended with an 'ident' string (which is usually set to the name of
the program or device driver [with a trailing colon appended] which
calls syslog(3), but can be set to anything (even to a null value) via
the openlog(3) routine). The userspace 'logger' command provides the
'-t' option for the same reason. However, even if the ident string is
set to null, syslog(3) still prepends the null string (including the
trailing colon) to the message body, making it impossible to generate
messages (at least via the standard library routines) like those
following;

Feb 18 08:03:38 mybox scsi: [ID 107833 kern.warning] WARNING:
/pci@4,4000/scsi@2/sd@1,0 (sd91):
Feb 18 08:03:38 mybox       disk not responding to selection
Feb 18 08:03:38 mybox

The above is a group of three related messages taken from a working
/var/adm/messages.
The first msg contains the ident string [scsi:], but the second and
third do not.

Now, the command;

    logger -t "" "     disk not respon ..."

produces;

    Feb 18 08:03:38 mybox :      disk not respon ...

Note the colon!  A compiled program using the syslog(3) and openlog(3)
routines produces exactly the same result. So, how do they do that?
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Thu Feb 28 18:38:49 2002

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:42:35 EST