Added logging facilities
This commit is contained in:
parent
602b43d501
commit
d575f579bc
4 changed files with 43 additions and 0 deletions
|
@ -28,6 +28,7 @@ subdirinclude_HEADERS = \
|
|||
include/criterion/criterion.h \
|
||||
include/criterion/event.h \
|
||||
include/criterion/hooks.h \
|
||||
include/criterion/logging.h \
|
||||
include/criterion/stats.h
|
||||
|
||||
libcriterion_la_SOURCES = \
|
||||
|
@ -41,4 +42,5 @@ libcriterion_la_SOURCES = \
|
|||
src/process.h \
|
||||
src/stats.c \
|
||||
src/stats.h \
|
||||
src/logging.c \
|
||||
src/main.c
|
||||
|
|
|
@ -27,4 +27,10 @@
|
|||
# define SECTION_(Name) __attribute__((section(Name)))
|
||||
# define UNUSED __attribute__((unused))
|
||||
|
||||
# ifdef __GNUC__
|
||||
# define FORMAT(Archetype, Index, Ftc) __attribute__((format(Archetype, Index, Ftc)))
|
||||
# else
|
||||
# define FORMAT(Archetype, Index, Ftc)
|
||||
# endif
|
||||
|
||||
#endif /* !CRITERION_COMMON_H_ */
|
||||
|
|
19
include/criterion/logging.h
Normal file
19
include/criterion/logging.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef CRITERION_LOGGING_H_
|
||||
# define CRITERION_LOGGING_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
enum criterion_logging_level {
|
||||
CRITERION_INFO = 1,
|
||||
CRITERION_IMPORTANT,
|
||||
};
|
||||
|
||||
extern enum criterion_logging_level logging_threshold;
|
||||
|
||||
FORMAT(printf, 2, 3)
|
||||
void criterion_log(enum criterion_logging_level level, const char *msg, ...);
|
||||
|
||||
# define criterion_info(...) criterion_log(CRITERION_INFO, __VA_ARGS__)
|
||||
# define criterion_important(...) criterion_log(CRITERION_IMPORTANT, __VA_ARGS__)
|
||||
|
||||
#endif /* !CRITERION_LOGGING_H_ */
|
16
src/logging.c
Normal file
16
src/logging.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "criterion/logging.h"
|
||||
|
||||
enum criterion_logging_level logging_threshold = CRITERION_IMPORTANT;
|
||||
|
||||
void criterion_log(enum criterion_logging_level level, const char *msg, ...) {
|
||||
va_list args;
|
||||
|
||||
if (level < logging_threshold)
|
||||
return;
|
||||
|
||||
va_start(args, msg);
|
||||
vfprintf(stderr, msg, args);
|
||||
va_end(args);
|
||||
}
|
Loading…
Add table
Reference in a new issue