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.
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.
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]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
36 * logging.c - contains various logging functions.
39 boolean_t debug
= B_TRUE
;
42 * This idea for having this function is so that you can drop a dtrace probe
43 * here and trace complete strings (not just those containing formatting). Its
44 * important that we actually format the debug strings so we could trace them
45 * even if we choose not to send them to syslog.
48 log_out(int severity
, const char *str
)
50 if (severity
== LOG_DEBUG
&& !debug
)
53 syslog(severity
, str
);
57 log_format(int severity
, const char *fmt
, va_list ap
, char *buf
, int bufsize
)
64 bufsize
= sizeof (vbuf
);
67 offset
= snprintf(buf
, bufsize
, "%d: ", pthread_self());
68 (void) vsnprintf(buf
+ offset
, bufsize
- offset
, fmt
, ap
);
70 log_out(severity
, buf
);
74 * This function takes a syslog severity and uses it to determine what to do
75 * with the message (currently send it to syslog).
78 nlog(int severity
, const char *fmt
, ...)
83 log_format(severity
, fmt
, ap
, NULL
, 0);
88 pfail(const char *fmt
, ...)
96 log_format(LOG_ERR
, fmt
, ap
, msg
, 256);
100 msg
= "ran out of memory exiting. see log.";