2 * This file is part of the OpenPTS project.
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.
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)
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.
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.
25 * \file include/openpts_log.h
27 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
28 * @author David Sherwood <davidshe@uk.ibm.com>
33 #ifndef INCLUDE_OPENPTS_LOG_H_
34 #define INCLUDE_OPENPTS_LOG_H_
47 #include <openpts_msg.h>
49 #define NLS(a, b, x) catgets(catd, a, b, x)
50 #else /* !HAVE_CATGETS */
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 */
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
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
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))
82 #define setVerbosity(x) (verbosity = (x))
83 #define incVerbosity() (verbosity++)
84 #define getVerbosity() (verbosity)
86 #define OUTPUT(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
87 #define VERBOSE(v, fmt, ...) if (verbosity >= v) fprintf(stderr, fmt, ##__VA_ARGS__)
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__)
93 #define DEBUG_WITH_FLAG(debug_level, fmt, ...) if (debugBits & debug_level) \
94 writeLog(LOG_DEBUG, "%s:%4d " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
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__)
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);
111 #endif // INCLUDE_OPENPTS_LOG_H_