Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / daemons / cmirrord / logging.h
blob8efbe55251f12a8d4d4974122473f9de943ea7f5
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU Lesser General Public License v.2.1.
10 * You should have received a copy of the GNU Lesser General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 #ifndef __CLUSTER_LOG_LOGGING_DOT_H__
16 #define __CLUSTER_LOG_LOGGING_DOT_H__
18 #include <stdio.h>
19 #include <syslog.h>
21 /* SHORT_UUID - print last 8 chars of a string */
22 #define SHORT_UUID(x) (strlen(x) > 8) ? ((x) + (strlen(x) - 8)) : (x)
24 extern char *__rq_types_off_by_one[];
25 #define RQ_TYPE(x) __rq_types_off_by_one[(x) - 1]
27 extern int log_tabbing;
28 extern int log_is_open;
29 extern int log_membership_change;
30 extern int log_checkpoint;
31 extern int log_resend_requests;
33 #define LOG_OPEN(ident, option, facility) do { \
34 openlog(ident, option, facility); \
35 log_is_open = 1; \
36 } while (0)
38 #define LOG_CLOSE(void) do { \
39 log_is_open = 0; \
40 closelog(); \
41 } while (0)
43 #define LOG_OUTPUT(level, f, arg...) do { \
44 int __i; \
45 char __buffer[16]; \
46 FILE *fp = (level > LOG_NOTICE) ? stderr : stdout; \
47 if (log_is_open) { \
48 for (__i = 0; (__i < log_tabbing) && (__i < 15); __i++) \
49 __buffer[__i] = '\t'; \
50 __buffer[__i] = '\0'; \
51 syslog(level, "%s" f "\n", __buffer, ## arg); \
52 } else { \
53 for (__i = 0; __i < log_tabbing; __i++) \
54 fprintf(fp, "\t"); \
55 fprintf(fp, f "\n", ## arg); \
56 } \
57 } while (0)
60 #ifdef DEBUG
61 #define LOG_DBG(f, arg...) LOG_OUTPUT(LOG_DEBUG, f, ## arg)
62 #else /* DEBUG */
63 #define LOG_DBG(f, arg...)
64 #endif /* DEBUG */
66 #define LOG_COND(__X, f, arg...) do {\
67 if (__X) { \
68 LOG_OUTPUT(LOG_NOTICE, f, ## arg); \
69 } \
70 } while (0)
71 #define LOG_PRINT(f, arg...) LOG_OUTPUT(LOG_NOTICE, f, ## arg)
72 #define LOG_ERROR(f, arg...) LOG_OUTPUT(LOG_ERR, f, ## arg)
74 #endif /* __CLUSTER_LOG_LOGGING_DOT_H__ */