das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
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 das2C, the Core Das2 C Library.
4 *
5 * Das2C 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 * Das2C 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 das2C; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18
52/* Ported over from librpwgse which was laboriously developed for Juno Waves
53 * support. Since logging is much different then just failing with an
54 * error, this is a different facility 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 <das3/util.h>
63
64#ifdef __cplusplus
65extern "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
85DAS_API int daslog_level(void);
86
100DAS_API int daslog_setlevel(int nLevel);
101
113DAS_API int daslog_strlevel(const char* sLevel);
114
124DAS_API const char* daslog_levelstr(int nLevel);
125
127DAS_API bool daslog_set_showline(int nLevel);
128
129
130/* Basic logging function, macros use this */
131DAS_API void daslog(int nLevel, const char* sSrcFile, int nLine, const char* sFmt, ...)
132 _das_fmt_check(4, 5);
133
134
136#define daslog_trace(M) daslog(DASLOG_TRACE, __FILE__, __LINE__, M)
138#define daslog_debug(M) daslog(DASLOG_DEBUG, __FILE__, __LINE__, M)
140#define daslog_info(M) daslog(DASLOG_INFO, __FILE__, __LINE__, M)
142#define daslog_warn(M) daslog(DASLOG_WARN, __FILE__, __LINE__, M)
144#define daslog_error(M) daslog(DASLOG_ERROR, __FILE__, __LINE__, M)
146#define daslog_critical(M) daslog(DASLOG_CRIT, __FILE__, __LINE__, M)
147
148
150#define daslog_trace_v(F, ...)\
151 daslog(DASLOG_TRACE, __FILE__, __LINE__, F, __VA_ARGS__)
153#define daslog_debug_v(F, ...)\
154 daslog(DASLOG_DEBUG, __FILE__, __LINE__, F, __VA_ARGS__)
156#define daslog_info_v(F, ...)\
157 daslog(DASLOG_INFO, __FILE__, __LINE__, F, __VA_ARGS__)
159#define daslog_warn_v(F, ...)\
160 daslog(DASLOG_WARN, __FILE__, __LINE__, F, __VA_ARGS__)
162#define daslog_error_v(F, ...)\
163 daslog(DASLOG_ERROR, __FILE__, __LINE__, F, __VA_ARGS__)
165#define daslog_critical_v(F, ...)\
166 daslog(DASLOG_CRIT, __FILE__, __LINE__, F, __VA_ARGS__)
167
168
178
181#ifdef __cplusplus
182}
183#endif
184
185#endif /* _das_log_h_ */
DAS_API const char * daslog_levelstr(int nLevel)
The opposite of daslog_strlevel(), returns a string appropriate for the log level indicated.
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