Imported Upstream version 2.1.0
[platform/upstream/gpg2.git] / common / logging.h
1 /* logging.h
2  * Copyright (C) 1999, 2000, 2001, 2004, 2006,
3  *               2010 Free Software Foundation, Inc.
4  *
5  * This file is part of JNLIB, which is a subsystem of GnuPG.
6  *
7  * JNLIB is free software; you can redistribute it and/or modify it
8  * under the terms of either
9  *
10  *   - the GNU Lesser General Public License as published by the Free
11  *     Software Foundation; either version 3 of the License, or (at
12  *     your option) any later version.
13  *
14  * or
15  *
16  *   - the GNU General Public License as published by the Free
17  *     Software Foundation; either version 2 of the License, or (at
18  *     your option) any later version.
19  *
20  * or both in parallel, as here.
21  *
22  * JNLIB is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * General Public License for more details.
26  *
27  * You should have received a copies of the GNU General Public License
28  * and the GNU Lesser General Public License along with this program;
29  * if not, see <http://www.gnu.org/licenses/>.
30  */
31
32 #ifndef LIBJNLIB_LOGGING_H
33 #define LIBJNLIB_LOGGING_H
34
35 #include <stdio.h>
36 #include "mischelp.h"
37 #include "w32help.h"
38
39 /* Flag values for log_set_prefix. */
40 #define JNLIB_LOG_WITH_PREFIX  1
41 #define JNLIB_LOG_WITH_TIME    2
42 #define JNLIB_LOG_WITH_PID     4
43 #define JNLIB_LOG_RUN_DETACHED 256
44 #define JNLIB_LOG_NO_REGISTRY  512
45
46 int  log_get_errorcount (int clear);
47 void log_inc_errorcount (void);
48 void log_set_file( const char *name );
49 void log_set_fd (int fd);
50 void log_set_pid_suffix_cb (int (*cb)(unsigned long *r_value));
51 void log_set_prefix (const char *text, unsigned int flags);
52 const char *log_get_prefix (unsigned int *flags);
53 int log_test_fd (int fd);
54 int  log_get_fd(void);
55 estream_t log_get_stream (void);
56
57 #ifdef JNLIB_GCC_M_FUNCTION
58   void bug_at( const char *file, int line, const char *func ) JNLIB_GCC_A_NR;
59 # define BUG() bug_at( __FILE__ , __LINE__, __FUNCTION__ )
60 #else
61   void bug_at( const char *file, int line );
62 # define BUG() bug_at( __FILE__ , __LINE__ )
63 #endif
64
65 /* To avoid mandatory inclusion of stdarg and other stuff, do it only
66    if explicitly requested to do so. */
67 #ifdef JNLIB_NEED_LOG_LOGV
68 #include <stdarg.h>
69 enum jnlib_log_levels {
70     JNLIB_LOG_BEGIN,
71     JNLIB_LOG_CONT,
72     JNLIB_LOG_INFO,
73     JNLIB_LOG_WARN,
74     JNLIB_LOG_ERROR,
75     JNLIB_LOG_FATAL,
76     JNLIB_LOG_BUG,
77     JNLIB_LOG_DEBUG
78 };
79 void log_log (int level, const char *fmt, ...) JNLIB_GCC_A_PRINTF(2,3);
80 void log_logv (int level, const char *fmt, va_list arg_ptr);
81 void log_string (int level, const char *string);
82 #endif /*JNLIB_NEED_LOG_LOGV*/
83
84
85 void log_bug( const char *fmt, ... )    JNLIB_GCC_A_NR_PRINTF(1,2);
86 void log_fatal( const char *fmt, ... )  JNLIB_GCC_A_NR_PRINTF(1,2);
87 void log_error( const char *fmt, ... )  JNLIB_GCC_A_PRINTF(1,2);
88 void log_info( const char *fmt, ... )   JNLIB_GCC_A_PRINTF(1,2);
89 void log_debug( const char *fmt, ... )  JNLIB_GCC_A_PRINTF(1,2);
90 void log_printf( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
91 void log_flush (void);
92
93 /* Print a hexdump of BUFFER.  With TEXT passes as NULL print just the
94    raw dump, with TEXT being an empty string, print a trailing
95    linefeed, otherwise print an entire debug line with TEXT followed
96    by the hexdump and a final LF.  */
97 void log_printhex (const char *text, const void *buffer, size_t length);
98
99 void log_clock (const char *string);
100
101
102 #endif /*LIBJNLIB_LOGGING_H*/