xref: /titanic_41/usr/src/cmd/drd/drd_log.c (revision f9e2a31fcb74a362a725343aea080a7e5b858b70)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Logging support for the DR Daemon
31  */
32 
33 #include <stdio.h>
34 #include <stdarg.h>
35 #include <syslog.h>
36 
37 #include "drd.h"
38 
39 #define	DRD_MAX_MSG_LEN		512
40 
41 static char *log_prio_str[] = {
42 	"EMERG: ",	/* LOG_EMERG */
43 	"ALERT: ",	/* LOG_ALERT */
44 	"CRIT: ",	/* LOG_CRIT */
45 	"ERROR: ",	/* LOG_ERR */
46 	"WARNING: ",	/* LOG_WARNING */
47 	"NOTICE: ",	/* LOG_NOTICE */
48 	"INFO: ",	/* LOG_INFO */
49 	""		/* LOG_DEBUG */
50 };
51 
52 static void
53 drd_log_msg(int priority, char *fmt, va_list vap)
54 {
55 	char	msg_str[DRD_MAX_MSG_LEN];
56 
57 	(void) vsnprintf(msg_str, DRD_MAX_MSG_LEN, fmt, vap);
58 
59 	if (!drd_daemonized) {
60 		fprintf(stderr, "%s%s\n", log_prio_str[priority], msg_str);
61 		return;
62 	}
63 
64 	syslog(priority, msg_str);
65 }
66 
67 void
68 drd_err(char *fmt, ...)
69 {
70 	va_list vap;
71 
72 	va_start(vap, fmt);
73 	drd_log_msg(LOG_ERR, fmt, vap);
74 	va_end(vap);
75 }
76 
77 void
78 drd_info(char *fmt, ...)
79 {
80 	va_list vap;
81 
82 	va_start(vap, fmt);
83 	drd_log_msg(LOG_INFO, fmt, vap);
84 	va_end(vap);
85 }
86 
87 void
88 drd_dbg(char *fmt, ...)
89 {
90 	va_list vap;
91 
92 	if (!drd_debug) {
93 		/* not debugging */
94 		return;
95 	}
96 
97 	va_start(vap, fmt);
98 	drd_log_msg(LOG_DEBUG, fmt, vap);
99 	va_end(vap);
100 }
101