das2C
das core C utilities (v3)
log.h
Go to the documentation of this file.
1 /* Copyright (C) 2015-2017 Chris Piker <chris-piker@uiowa.edu>
2  *
3  * This file is part of libdas2, the Core Das2 C Library.
4  *
5  * Libdas2 is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * Libdas2 is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * version 2.1 along with libdas2; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
52 /* Ported over from librpwgse which was laborously developed for Juno Waves
53  * support. Since logging is much different then just failing with an
54  * error, this is a different falcility than the das_error_func from util.h
55  * but the two items have common functionality that should be merged over time.
56  * -cwp 2016-10-20
57  */
58 
59 #ifndef _das_log_h_
60 #define _das_log_h_
61 
62 #include <das2/util.h>
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
72 #define DASLOG_NOTHING 255
73 #define DASLOG_CRIT 100 /* same as java.util.logging.Level.SEVERE */
74 #define DASLOG_ERROR 80
75 #define DASLOG_WARN 60 /* same as java.util.logging.Level.WARNING */
76 #define DASLOG_INFO 40 /* same as java.util.logging.Level.INFO & CONFIG */
77 #define DASLOG_DEBUG 20 /* same as java.util.logging.Level.FINE */
78 #define DASLOG_TRACE 0 /* same as java.util.logging.Level.FINER & FINEST */
79 
85 DAS_API int daslog_level(void);
86 
100 DAS_API int daslog_setlevel(int nLevel);
101 
113 DAS_API int daslog_strlevel(const char* sLevel);
114 
116 DAS_API bool daslog_set_showline(int nLevel);
117 
118 
119 /* Basic logging function, macros use this */
120 DAS_API void daslog(int nLevel, const char* sSrcFile, int nLine, const char* sFmt, ...);
121 
122 
124 #define daslog_trace(M) daslog(DASLOG_TRACE, __FILE__, __LINE__, M)
126 #define daslog_debug(M) daslog(DASLOG_DEBUG, __FILE__, __LINE__, M)
128 #define daslog_info(M) daslog(DASLOG_INFO, __FILE__, __LINE__, M)
130 #define daslog_warn(M) daslog(DASLOG_WARN, __FILE__, __LINE__, M)
132 #define daslog_error(M) daslog(DASLOG_ERROR, __FILE__, __LINE__, M)
134 #define daslog_critical(M) daslog(DAS_LL_CRITICAL, __FILE__, __LINE__, M)
135 
136 
138 #define daslog_trace_v(F, ...)\
139  daslog(DASLOG_TRACE, __FILE__, __LINE__, F, __VA_ARGS__)
141 #define daslog_debug_v(F, ...)\
142  daslog(DASLOG_DEBUG, __FILE__, __LINE__, F, __VA_ARGS__)
144 #define daslog_info_v(F, ...)\
145  daslog(DASLOG_INFO, __FILE__, __LINE__, F, __VA_ARGS__)
147 #define daslog_warn_v(F, ...)\
148  daslog(DASLOG_WARN, __FILE__, __LINE__, F, __VA_ARGS__)
150 #define daslog_error_v(F, ...)\
151  daslog(DASLOG_ERROR, __FILE__, __LINE__, F, __VA_ARGS__)
153 #define daslog_critical_v(F, ...)\
154  daslog(DASLOG_CRIT, __FILE__, __LINE__, F, __VA_ARGS__)
155 
156 
166 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif /* _das_log_h_ */
DAS_API das_log_handler_t daslog_sethandler(das_log_handler_t new_handler)
Install a new message handler function for this thread.
DAS_API int daslog_setlevel(int nLevel)
Set the logging level for this thread.
DAS_API bool daslog_set_showline(int nLevel)
Output source file and line numbers for messages at or above this level.
DAS_API int daslog_level(void)
Get the log level.
DAS_API int daslog_strlevel(const char *sLevel)
Get a logging level integer from a string.
void(* das_log_handler_t)(int nLevel, const char *sMsg, bool bPrnTime)
Definition of a message handler function pointer.
Definition: util.h:58