OSDN Git Service

aac0d3f1503f7392a3881bfcf47f8c147e2c68c2
[openpts/openpts.git] / include / openpts_log.h
1 /*
2  * This file is part of the OpenPTS project.
3  *
4  * The Initial Developer of the Original Code is International
5  * Business Machines Corporation. Portions created by IBM
6  * Corporation are Copyright (C) 2011 International Business
7  * Machines Corporation. All Rights Reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the Common Public License as published by
11  * IBM Corporation; either version 1 of the License, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * Common Public License for more details.
18  *
19  * You should have received a copy of the Common Public License
20  * along with this program; if not, a copy can be viewed at
21  * http://www.opensource.org/licenses/cpl1.0.php.
22  */
23
24 /**
25  * \file include/openpts_log.h
26  * \brief
27  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
28  * @author David Sherwood <davidshe@uk.ibm.com>
29  * @date 2011-05-05
30  *
31  */
32
33 #ifndef INCLUDE_OPENPTS_LOG_H_
34 #define INCLUDE_OPENPTS_LOG_H_
35
36 #include <syslog.h>
37 #include <assert.h>
38
39 #ifdef NLS
40 #undef NLS
41 #endif
42
43 /* NLS */
44 #ifdef ENABLE_NLS
45 #ifdef HAVE_CATGETS
46 #include <nl_types.h>
47 #include <openpts_msg.h>
48 extern nl_catd catd;
49 #define NLS(a, b, x) catgets(catd, a, b, x)
50 #else  /* !HAVE_CATGETS */
51 #include <locale.h>
52 #include <libintl.h>
53 #define NLS(a, b, x) gettext(x)
54 #endif  /* HAVE_CATGETS */
55 #else /* !ENABLE_NLS */
56 #define NLS(a, b, x) x
57 #endif /* ENABLE_NLS */
58
59 extern int debugBits;
60 extern int verbosity;
61
62 #define OPENPTS_LOG_UNDEFINED 0
63 #define OPENPTS_LOG_SYSLOG    1
64 #define OPENPTS_LOG_CONSOLE   2
65 #define OPENPTS_LOG_FILE      3
66 #define OPENPTS_LOG_NULL      4
67
68 #define DEBUG_FLAG     0x01
69 #define DEBUG_FSM_FLAG 0x02
70 #define DEBUG_XML_FLAG 0x04
71 #define DEBUG_IFM_FLAG 0x08
72 #define DEBUG_SAX_FLAG 0x10
73 #define DEBUG_TPM_FLAG 0x20
74 #define DEBUG_CAL_FLAG 0x40
75
76 #define isDebugFlagSet(x) (debugBits & (x))
77 #define isAnyDebugFlagSet(x) (debugBits != 0)
78 #define setDebugFlags(x) (debugBits = (x))
79 #define getDebugFlags() (debugBits)
80 #define addDebugFlags(x) (debugBits |= (x))
81
82 #define setVerbosity(x) (verbosity = (x))
83 #define incVerbosity() (verbosity++)
84 #define getVerbosity() (verbosity)
85
86 #define OUTPUT(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
87 #define VERBOSE(v, fmt, ...) if (verbosity >= v) fprintf(stderr, fmt, ##__VA_ARGS__)
88
89 #define ERROR(fmt, ...) writeLog(LOG_ERR,  "%s:%d " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
90 #define TODO(fmt, ...)  writeLog(LOG_INFO, "%s:%d TODO " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
91 #define INFO(fmt, ...)  writeLog(LOG_INFO, fmt, ##__VA_ARGS__)
92
93 #define DEBUG_WITH_FLAG(debug_level, fmt, ...) if (debugBits & debug_level) \
94 writeLog(LOG_DEBUG, "%s:%4d " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
95
96 #define DEBUG(fmt, ...)     DEBUG_WITH_FLAG(DEBUG_FLAG,     fmt, ##__VA_ARGS__)
97 #define DEBUG_FSM(fmt, ...) DEBUG_WITH_FLAG(DEBUG_FSM_FLAG, fmt, ##__VA_ARGS__)
98 #define DEBUG_XML(fmt, ...) DEBUG_WITH_FLAG(DEBUG_XML_FLAG, fmt, ##__VA_ARGS__)
99 #define DEBUG_IFM(fmt, ...) DEBUG_WITH_FLAG(DEBUG_IFM_FLAG, fmt, ##__VA_ARGS__)
100 #define DEBUG_SAX(fmt, ...) DEBUG_WITH_FLAG(DEBUG_SAX_FLAG, fmt, ##__VA_ARGS__)
101 #define DEBUG_TPM(fmt, ...) DEBUG_WITH_FLAG(DEBUG_TPM_FLAG, fmt, ##__VA_ARGS__)
102 #define DEBUG_CAL(fmt, ...) DEBUG_WITH_FLAG(DEBUG_CAL_FLAG, fmt, ##__VA_ARGS__)
103
104 void writeLog(int priority, const char *format, ...);
105 void initCatalog(void);
106 void setLogLocation(int ll, char *filename);
107 char *getLogLocationString();
108 void determineLogLocationByEnv(void);
109 void setSyslogCommandName(char *name);
110
111 #endif  // INCLUDE_OPENPTS_LOG_H_