Imported Upstream version 2.1.4
[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 GnuPG.
6  *
7  * GnuPG 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  * GnuPG 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 GNUPG_COMMON_LOGGING_H
33 #define GNUPG_COMMON_LOGGING_H
34
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include "mischelp.h"
38 #include "w32help.h"
39
40 int  log_get_errorcount (int clear);
41 void log_inc_errorcount (void);
42 void log_set_file( const char *name );
43 void log_set_fd (int fd);
44 void log_set_pid_suffix_cb (int (*cb)(unsigned long *r_value));
45 void log_set_prefix (const char *text, unsigned int flags);
46 const char *log_get_prefix (unsigned int *flags);
47 int log_test_fd (int fd);
48 int  log_get_fd(void);
49 estream_t log_get_stream (void);
50
51 #ifdef GPGRT_GCC_M_FUNCTION
52   void bug_at( const char *file, int line, const char *func ) GPGRT_GCC_A_NR;
53 # define BUG() bug_at( __FILE__ , __LINE__, __FUNCTION__ )
54 #else
55   void bug_at( const char *file, int line );
56 # define BUG() bug_at( __FILE__ , __LINE__ )
57 #endif
58
59 /* Flag values for log_set_prefix. */
60 #define GPGRT_LOG_WITH_PREFIX  1
61 #define GPGRT_LOG_WITH_TIME    2
62 #define GPGRT_LOG_WITH_PID     4
63 #define GPGRT_LOG_RUN_DETACHED 256
64 #define GPGRT_LOG_NO_REGISTRY  512
65
66 /* Log levels as used by log_log.  */
67 enum jnlib_log_levels {
68     GPGRT_LOG_BEGIN,
69     GPGRT_LOG_CONT,
70     GPGRT_LOG_INFO,
71     GPGRT_LOG_WARN,
72     GPGRT_LOG_ERROR,
73     GPGRT_LOG_FATAL,
74     GPGRT_LOG_BUG,
75     GPGRT_LOG_DEBUG
76 };
77 void log_log (int level, const char *fmt, ...) GPGRT_GCC_A_PRINTF(2,3);
78 void log_logv (int level, const char *fmt, va_list arg_ptr);
79 void log_string (int level, const char *string);
80
81
82 void log_bug( const char *fmt, ... )    GPGRT_GCC_A_NR_PRINTF(1,2);
83 void log_fatal( const char *fmt, ... )  GPGRT_GCC_A_NR_PRINTF(1,2);
84 void log_error( const char *fmt, ... )  GPGRT_GCC_A_PRINTF(1,2);
85 void log_info( const char *fmt, ... )   GPGRT_GCC_A_PRINTF(1,2);
86 void log_debug( const char *fmt, ... )  GPGRT_GCC_A_PRINTF(1,2);
87 void log_printf( const char *fmt, ... ) GPGRT_GCC_A_PRINTF(1,2);
88 void log_flush (void);
89
90 /* Print a hexdump of BUFFER.  With TEXT passes as NULL print just the
91    raw dump, with TEXT being an empty string, print a trailing
92    linefeed, otherwise print an entire debug line with TEXT followed
93    by the hexdump and a final LF.  */
94 void log_printhex (const char *text, const void *buffer, size_t length);
95
96 void log_clock (const char *string);
97
98
99 #endif /*GNUPG_COMMON_LOGGING_H*/