1 /*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Pawel Jakub Dawidek under sponsorship from 6 * the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD$ 30 */ 31 32 #ifndef _PJDLOG_H_ 33 #define _PJDLOG_H_ 34 35 #include <sys/cdefs.h> 36 37 #include <stdarg.h> 38 #include <sysexits.h> 39 #include <syslog.h> 40 41 #define PJDLOG_MODE_STD 0 42 #define PJDLOG_MODE_SYSLOG 1 43 44 void pjdlog_mode_set(int mode); 45 int pjdlog_mode_get(void); 46 47 void pjdlog_debug_set(int level); 48 int pjdlog_debug_get(void); 49 50 void pjdlog_prefix_set(const char *fmt, ...) __printflike(1, 2); 51 void pjdlog_prefix_setv(const char *fmt, va_list ap) __printflike(1, 0); 52 53 void pjdlog_common(int loglevel, int debuglevel, int error, const char *fmt, 54 ...) __printflike(4, 5); 55 void pjdlogv_common(int loglevel, int debuglevel, int error, const char *fmt, 56 va_list ap) __printflike(4, 0); 57 58 void pjdlog(int loglevel, const char *fmt, ...) __printflike(2, 3); 59 void pjdlogv(int loglevel, const char *fmt, va_list ap) __printflike(2, 0); 60 61 #define pjdlogv_emergency(fmt, ap) pjdlogv(LOG_EMERG, (fmt), (ap)) 62 #define pjdlog_emergency(...) pjdlog(LOG_EMERG, __VA_ARGS__) 63 #define pjdlogv_alert(fmt, ap) pjdlogv(LOG_ALERT, (fmt), (ap)) 64 #define pjdlog_alert(...) pjdlog(LOG_ALERT, __VA_ARGS__) 65 #define pjdlogv_critical(fmt, ap) pjdlogv(LOG_CRIT, (fmt), (ap)) 66 #define pjdlog_critical(...) pjdlog(LOG_CRIT, __VA_ARGS__) 67 #define pjdlogv_error(fmt, ap) pjdlogv(LOG_ERR, (fmt), (ap)) 68 #define pjdlog_error(...) pjdlog(LOG_ERR, __VA_ARGS__) 69 #define pjdlogv_warning(fmt, ap) pjdlogv(LOG_WARNING, (fmt), (ap)) 70 #define pjdlog_warning(...) pjdlog(LOG_WARNING, __VA_ARGS__) 71 #define pjdlogv_notice(fmt, ap) pjdlogv(LOG_NOTICE, (fmt), (ap)) 72 #define pjdlog_notice(...) pjdlog(LOG_NOTICE, __VA_ARGS__) 73 #define pjdlogv_info(fmt, ap) pjdlogv(LOG_INFO, (fmt), (ap)) 74 #define pjdlog_info(...) pjdlog(LOG_INFO, __VA_ARGS__) 75 76 void pjdlog_debug(int debuglevel, const char *fmt, ...) __printflike(2, 3); 77 void pjdlogv_debug(int debuglevel, const char *fmt, va_list ap) __printflike(2, 0); 78 79 void pjdlog_errno(int loglevel, const char *fmt, ...) __printflike(2, 3); 80 void pjdlogv_errno(int loglevel, const char *fmt, va_list ap) __printflike(2, 0); 81 82 void pjdlog_exit(int exitcode, const char *fmt, ...) __printflike(2, 3) __dead2; 83 void pjdlogv_exit(int exitcode, const char *fmt, va_list ap) __printflike(2, 0) __dead2; 84 85 void pjdlog_exitx(int exitcode, const char *fmt, ...) __printflike(2, 3) __dead2; 86 void pjdlogv_exitx(int exitcode, const char *fmt, va_list ap) __printflike(2, 0) __dead2; 87 88 void pjdlog_verify(const char *func, const char *file, int line, 89 const char *failedexpr) __dead2; 90 91 #define PJDLOG_VERIFY(expr) do { \ 92 if (!(expr)) \ 93 pjdlog_verify(__func__, __FILE__, __LINE__, #expr); \ 94 } while (0) 95 #ifdef NDEBUG 96 #define PJDLOG_ASSERT(expr) do { } while (0) 97 #else 98 #define PJDLOG_ASSERT(expr) PJDLOG_VERIFY(expr) 99 #endif 100 101 #endif /* !_PJDLOG_H_ */ 102