7 /* report diagnostics to VSTREAM
9 /* #include <msg_vstream.h>
11 /* void msg_vstream_init(progname, stream)
12 /* const char *progname;
15 /* This module implements support to report msg(3) diagnostics
18 /* msg_vstream_init() sets the program name that appears in each output
19 /* record, and directs diagnostics (see msg(3)) to the specified
20 /* VSTREAM. The \fIprogname\fR argument is not copied.
24 /* No guarantee that long records are written atomically.
25 /* Only the last msg_vstream_init() call takes effect.
29 /* The Secure Mailer license must be distributed with this software.
32 /* IBM T.J. Watson Research
34 /* Yorktown Heights, NY 10598, USA
37 /* System libraries. */
41 #include <stdlib.h> /* 44BSD stdarg.h uses abort() */
44 /* Utility library. */
48 #include "msg_output.h"
49 #include "msg_vstream.h"
54 static const char *msg_tag
;
55 static VSTREAM
*msg_stream
;
57 /* msg_vstream_print - log diagnostic to VSTREAM */
59 static void msg_vstream_print(int level
, const char *text
)
61 static const char *level_text
[] = {
62 "info", "warning", "error", "fatal", "panic",
65 if (level
< 0 || level
>= (int) (sizeof(level_text
) / sizeof(level_text
[0])))
66 msg_panic("invalid severity level: %d", level
);
67 if (level
== MSG_INFO
) {
68 vstream_fprintf(msg_stream
, "%s: %s\n",
71 vstream_fprintf(msg_stream
, "%s: %s: %s\n",
72 msg_tag
, level_text
[level
], text
);
74 vstream_fflush(msg_stream
);
77 /* msg_vstream_init - initialize */
79 void msg_vstream_init(const char *name
, VSTREAM
*vp
)
81 static int first_call
= 1;
87 msg_output(msg_vstream_print
);