1 /* $NetBSD: logging.h,v 1.1.1.1 2009/12/02 00:27:06 haad Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. 5 * 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. 9 * 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 13 */ 14 15 #ifndef __CLUSTER_LOG_LOGGING_DOT_H__ 16 #define __CLUSTER_LOG_LOGGING_DOT_H__ 17 18 #include <stdio.h> 19 #include <syslog.h> 20 21 /* SHORT_UUID - print last 8 chars of a string */ 22 #define SHORT_UUID(x) (strlen(x) > 8) ? ((x) + (strlen(x) - 8)) : (x) 23 24 extern char *__rq_types_off_by_one[]; 25 #define RQ_TYPE(x) __rq_types_off_by_one[(x) - 1] 26 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; 32 33 #define LOG_OPEN(ident, option, facility) do { \ 34 openlog(ident, option, facility); \ 35 log_is_open = 1; \ 36 } while (0) 37 38 #define LOG_CLOSE(void) do { \ 39 log_is_open = 0; \ 40 closelog(); \ 41 } while (0) 42 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) 58 59 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 */ 65 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) 73 74 #endif /* __CLUSTER_LOG_LOGGING_DOT_H__ */ 75