libdas2
das2 core C utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 int daslog_level(void);
86 
100 int daslog_setlevel(int nLevel);
101 
103 bool daslog_set_showline(int nLevel);
104 
105 
106 /* Basic logging function, macros use this */
107 void daslog(int nLevel, const char* sSrcFile, int nLine, const char* sFmt, ...);
108 
109 
111 #define daslog_trace(M) daslog(DASLOG_TRACE, __FILE__, __LINE__, M)
112 
113 #define daslog_debug(M) daslog(DASLOG_DEBUG, __FILE__, __LINE__, M)
114 
115 #define daslog_info(M) daslog(DASLOG_INFO, __FILE__, __LINE__, M)
116 
117 #define daslog_warn(M) daslog(DASLOG_WARN, __FILE__, __LINE__, M)
118 
119 #define daslog_error(M) daslog(DASLOG_ERROR, __FILE__, __LINE__, M)
120 
121 #define daslog_critical(M) daslog(DAS_LL_CRITICAL, __FILE__, __LINE__, M)
122 
123 
125 #define daslog_trace_v(F, ...)\
126  daslog(DASLOG_TRACE, __FILE__, __LINE__, F, __VA_ARGS__)
127 
128 #define daslog_debug_v(F, ...)\
129  daslog(DASLOG_DEBUG, __FILE__, __LINE__, F, __VA_ARGS__)
130 
131 #define daslog_info_v(F, ...)\
132  daslog(DASLOG_INFO, __FILE__, __LINE__, F, __VA_ARGS__)
133 
134 #define daslog_warn_v(F, ...)\
135  daslog(DASLOG_WARN, __FILE__, __LINE__, F, __VA_ARGS__)
136 
137 #define daslog_error_v(F, ...)\
138  daslog(DASLOG_ERROR, __FILE__, __LINE__, F, __VA_ARGS__)
139 
140 #define daslog_critical_v(F, ...)\
141  daslog(DASLOG_CRIT, __FILE__, __LINE__, F, __VA_ARGS__)
142 
143 
153 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif /* _das_log_h_ */
void(* das_log_handler_t)(int nLevel, const char *sMsg, bool bPrnTime)
Definition of a message handler function pointer.
Definition: util.h:143
int daslog_level(void)
Get the log level.
bool daslog_set_showline(int nLevel)
Output source file and line numbers for messages at or above this level.
int daslog_setlevel(int nLevel)
Set the logging level for this thread.
das_log_handler_t daslog_sethandler(das_log_handler_t new_handler)
Install a new message handler function for this thread.