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