Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
logging.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright © 2015-2016 Franklin "Snaipe" Mathieu <http://snai.pe/>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24/**
25 * @file
26 * @brief Logging functions
27 *****************************************************************************/
28#ifndef CRITERION_LOGGING_H_
29#define CRITERION_LOGGING_H_
30
31#include "internal/common.h"
34#include "stats.h"
35
37
44
50
51/**
52 * Prints a log message
53 *
54 * One can use this function, but it is more convenient to use the 3 macros.
55 *
56 * @param[in] severity Severity level of the log message
57 * @param[in] msg printf like format string
58 * @param[in] ... Additional arguments depending on msg
59 *
60 *****************************************************************************/
61CR_FORMAT(printf, 2, 3)
62CR_API void cr_log(enum criterion_severity severity, const char *msg, ...);
63
64/**
65 * Prints a info message
66 *
67 * Call: cr_log_info(msg, ...)\n
68 * Prints a info message defined by msg and the following optional parameters
69 *
70 * @param[in] msg printf like format string
71 * @param[in] ... Additional arguments depending on msg
72 *
73 *****************************************************************************/
74#define cr_log_info(...) cr_log(CR_LOG_INFO, __VA_ARGS__)
75
76/**
77 * Prints a warning message
78 *
79 * Call: cr_log_warn(msg, ...)\n
80 * Prints a warning message defined by msg and the following optional parameters
81 *
82 * @param[in] msg printf like format string
83 * @param[in] ... Additional arguments depending on msg
84 *
85 *****************************************************************************/
86#define cr_log_warn(...) cr_log(CR_LOG_WARNING, __VA_ARGS__)
87
88/**
89 * Prints a error message
90 *
91 * Call: cr_log_error(msg, ...)\n
92 * Prints a error message defined by msg and the following optional parameters
93 *
94 * @param[in] msg printf like format string
95 * @param[in] ... Additional arguments depending on msg
96 *
97 *****************************************************************************/
98#define cr_log_error(...) cr_log(CR_LOG_ERROR, __VA_ARGS__)
99
104
106 const char *name;
107 size_t size;
108 void *data;
110};
111
113 void (*log_pre_all )(struct criterion_test_set *set);
114 void (*log_pre_suite )(struct criterion_suite_set *set);
115 void (*log_pre_init )(struct criterion_suite *suite, struct criterion_test *test);
116 void (*log_pre_test )(struct criterion_suite *suite, struct criterion_test *test);
117 void (*log_assert )(struct criterion_assert_stats *stats);
119 void (*log_test_timeout )(struct criterion_test_stats *stats);
120 void (*log_test_crash )(struct criterion_test_stats *stats);
121 void (*log_test_abort )(struct criterion_test_stats *stats, const char *msg);
122 void (*log_other_crash )(struct criterion_test_stats *stats);
124 void (*log_post_test )(struct criterion_test_stats *stats);
125 void (*log_post_fini )(struct criterion_test_stats *stats);
126 void (*log_post_suite )(struct criterion_suite_stats *stats);
127 void (*log_post_all )(struct criterion_global_stats *stats);
128 void (*log_message )(enum criterion_severity, const char *msg);
130 const char *repr, const char *message);
132 const char *formatted);
134 struct cr_log_assert_param *param);
136 struct cr_log_assert_param *expected,
137 struct cr_log_assert_param *actual);
138};
139
140extern struct criterion_logger normal_logging;
141
143
144#define CR_NORMAL_LOGGING (&normal_logging)
145
146#ifdef __cplusplus
147# include <sstream>
148
149namespace criterion
150{ namespace logging
151 {
152 static void(*const log)(enum criterion_severity, const char *, ...) = cr_log;
153
154 class streambuf : public std::stringbuf {
155 public:
156 streambuf(enum criterion_severity severity__)
157 : std::stringbuf(), severity__(severity__)
158 {}
159
160 virtual int sync() override
161 {
162 criterion::logging::log(severity__, "%s", str().c_str());
163 str(std::string());
164 return 0;
165 }
166 private:
167 enum criterion_severity severity__;
168 };
169
170 class stream : public std::ostream {
171 public:
172 stream(enum criterion_severity severity__)
173 : std::ostream(&buf), buf(severity__)
174 {}
175 private:
176 streambuf buf;
177 };
178
179 static stream info { CR_LOG_INFO };
180 static stream warn { CR_LOG_WARNING };
181 static stream error { CR_LOG_ERROR };
182 } }
183#endif
184
185/* Deprecated old logging system, schedule removal for 3.0 */
186#ifndef CRITERION_NO_COMPAT
187
188# define criterion_log(_, ...) CR_DEPRECATED("criterion_log is deprecated, please use cr_log instead.") cr_log_info(__VA_ARGS__)
189# define criterion_info(...) CR_DEPRECATED("criterion_info is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__)
190# define criterion_pinfo(_, ...) CR_DEPRECATED("criterion_pinfo is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__)
191# define criterion_important(...) CR_DEPRECATED("criterion_important is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__)
192# define criterion_pimportant(_, ...) CR_DEPRECATED("criterion_pimportant is deprecated, please use cr_log_info instead.") cr_log_info(__VA_ARGS__)
193# define criterion_perror(...) CR_DEPRECATED("criterion_perror is deprecated, please use cr_log_error instead.") cr_log_error(__VA_ARGS__)
194
195#endif /* !CRITERION_NO_COMPAT */
196
197#endif /* !CRITERION_LOGGING_H_ */
#define CR_BEGIN_C_API
Definition common.h:54
#define CR_API
Definition common.h:128
#define CR_FORMAT(Archetype, Index, Ftc)
Definition common.h:105
#define CR_END_C_API
Definition common.h:55
struct criterion_logger normal_logging
CR_API void cr_log(enum criterion_severity severity, const char *msg,...)
criterion_logging_level
Definition logging.h:38
@ CRITERION_IMPORTANT
Definition logging.h:40
@ CRITERION_LOG_LEVEL_QUIET
Definition logging.h:42
@ CRITERION_INFO
Definition logging.h:39
criterion_severity
Definition logging.h:45
@ CR_LOG_ERROR
Definition logging.h:48
@ CR_LOG_WARNING
Definition logging.h:47
@ CR_LOG_INFO
Definition logging.h:46
cr_log_assert_param_kind
Definition logging.h:100
@ CR_LOG_PARAM_STR
Definition logging.h:101
@ CR_LOG_PARAM_RAW
Definition logging.h:102
static void error(LoadState *S, const char *why)
basic_ostream< char, char_traits< char > > ostream
Definition doctest.h:531
Test stats.
enum cr_log_assert_param_kind kind
Definition logging.h:109
const char * name
Definition logging.h:106
void(* log_post_suite)(struct criterion_suite_stats *stats)
Definition logging.h:126
void(* log_assert)(struct criterion_assert_stats *stats)
Definition logging.h:117
void(* log_assert_param)(struct criterion_assert_stats *stats, struct cr_log_assert_param *param)
Definition logging.h:133
void(* log_test_crash)(struct criterion_test_stats *stats)
Definition logging.h:120
void(* log_post_test)(struct criterion_test_stats *stats)
Definition logging.h:124
void(* log_pre_init)(struct criterion_suite *suite, struct criterion_test *test)
Definition logging.h:115
void(* log_abnormal_exit)(struct criterion_test_stats *stats)
Definition logging.h:123
void(* log_test_abort)(struct criterion_test_stats *stats, const char *msg)
Definition logging.h:121
void(* log_pre_test)(struct criterion_suite *suite, struct criterion_test *test)
Definition logging.h:116
void(* log_post_all)(struct criterion_global_stats *stats)
Definition logging.h:127
void(* log_message)(enum criterion_severity, const char *msg)
Definition logging.h:128
void(* log_other_crash)(struct criterion_test_stats *stats)
Definition logging.h:122
void(* log_assert_formatted)(struct criterion_assert_stats *stats, const char *formatted)
Definition logging.h:131
void(* log_assert_sub)(struct criterion_assert_stats *stats, const char *repr, const char *message)
Definition logging.h:129
void(* log_post_fini)(struct criterion_test_stats *stats)
Definition logging.h:125
void(* log_assert_param_eq)(struct criterion_assert_stats *stats, struct cr_log_assert_param *expected, struct cr_log_assert_param *actual)
Definition logging.h:135
void(* log_test_timeout)(struct criterion_test_stats *stats)
Definition logging.h:119
void(* log_pre_suite)(struct criterion_suite_set *set)
Definition logging.h:114
void(* log_pre_all)(struct criterion_test_set *set)
Definition logging.h:113
void(* log_theory_fail)(struct criterion_theory_stats *stats)
Definition logging.h:118
#define printf
static void warn(const char *fmt,...)