1 /* logging.h 2 * Copyright (C) 1999, 2000, 2001, 2004, 2006 Free Software Foundation, Inc. 3 * 4 * This file is part of JNLIB. 5 * 6 * JNLIB is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as 8 * published by the Free Software Foundation; either version 2.1 of 9 * the License, or (at your option) any later version. 10 * 11 * JNLIB is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 * 02110-1301, USA. 20 */ 21 22 #ifndef LIBJNLIB_LOGGING_H 23 #define LIBJNLIB_LOGGING_H 24 25 #include <stdio.h> 26 #include "mischelp.h" 27 28 /* Flag values for log_set_prefix. */ 29 #define JNLIB_LOG_WITH_PREFIX 1 30 #define JNLIB_LOG_WITH_TIME 2 31 #define JNLIB_LOG_WITH_PID 4 32 #define JNLIB_LOG_RUN_DETACHED 256 33 34 int log_get_errorcount (int clear); 35 void log_inc_errorcount (void); 36 void log_set_file( const char *name ); 37 void log_set_fd (int fd); 38 void log_set_pid_suffix_cb (int (*fnc)(int *pidsuf)); 39 void log_set_prefix (const char *text, unsigned int flags); 40 const char *log_get_prefix (unsigned int *flags); 41 int log_test_fd (int fd); 42 int log_get_fd(void); 43 FILE *log_get_stream (void); 44 45 #ifdef JNLIB_GCC_M_FUNCTION 46 void bug_at( const char *file, int line, const char *func ) JNLIB_GCC_A_NR; 47 # define BUG() bug_at( __FILE__ , __LINE__, __FUNCTION__ ) 48 #else 49 void bug_at( const char *file, int line ); 50 # define BUG() bug_at( __FILE__ , __LINE__ ) 51 #endif 52 53 /* To avoid mandatory inclusion of stdarg and other stuff, do it only 54 if explicitly requested to do so. */ 55 #ifdef JNLIB_NEED_LOG_LOGV 56 #include <stdarg.h> 57 enum jnlib_log_levels { 58 JNLIB_LOG_BEGIN, 59 JNLIB_LOG_CONT, 60 JNLIB_LOG_INFO, 61 JNLIB_LOG_WARN, 62 JNLIB_LOG_ERROR, 63 JNLIB_LOG_FATAL, 64 JNLIB_LOG_BUG, 65 JNLIB_LOG_DEBUG 66 }; 67 void log_logv (int level, const char *fmt, va_list arg_ptr); 68 #endif /*JNLIB_NEED_LOG_LOGV*/ 69 70 71 void log_bug( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2); 72 void log_fatal( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2); 73 void log_error( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); 74 void log_info( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); 75 void log_debug( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); 76 void log_printf( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); 77 void log_printhex (const char *text, const void *buffer, size_t length); 78 79 80 #endif /*LIBJNLIB_LOGGING_H*/ 81 82 83 84 85 86