1 /* 2 This program is free software; you can redistribute it and/or 3 modify it under the terms of the GNU General Public License as 4 published by the Free Software Foundation; either version 2, or (at 5 your option) any later version. 6 7 This program is distributed in the hope that it will be useful, but 8 WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 General Public License for more details. 11 12 Copyright (c) Alexey Mahotkin <alexm@hsys.msk.ru> 2002-2004 13 14 Provide logging facilities 15 16 */ 17 18 #ifndef LOGGING_H_ 19 #define LOGGING_H_ 1 20 21 #include <stdio.h> 22 #include <syslog.h> 23 24 extern int opt_use_stdout; 25 extern int opt_debugging; 26 27 #define init_logging(id) \ 28 do { \ 29 openlog(id, LOG_PID, LOG_AUTH); \ 30 } while (0) 31 32 33 #define terminate_logging() \ 34 do { \ 35 closelog(); \ 36 } while (0) 37 38 39 #define fatal(msg, args...) \ 40 do { \ 41 if (opt_use_stdout) { \ 42 fprintf(stderr, msg , ##args); \ 43 fputc('\n', stderr); \ 44 } else { \ 45 syslog(LOG_ERR, msg , ##args); \ 46 } \ 47 } while (0) 48 49 50 #define debugging(msg, args...) \ 51 do { \ 52 if (opt_debugging) { \ 53 if (opt_use_stdout) { \ 54 fprintf(stderr, msg , ##args); \ 55 fputc('\n', stderr); \ 56 } else { \ 57 syslog(LOG_DEBUG, msg , ##args); \ 58 } \ 59 } \ 60 } while (0) 61 62 63 #endif /* LOGGING_H_ */ 64