GRU - Generic Reusable Utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
gru_logger.h
Go to the documentation of this file.
1 /*
2  Copyright 2016 Otavio Rodolfo Piske
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
17 #ifndef GRU_LOGGER_H_
18 #define GRU_LOGGER_H_
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #if !defined(_WIN32) && !defined(_WIN64)
25 #include <strings.h>
26 #endif
27 
28 #include <stdarg.h>
29 #include <stdbool.h>
30 
31 #include "common/gru_base.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef enum log_level_t_ {
38  TRACE = 0,
39  DEBUG = 1,
40  INFO = 2,
41  STAT = 3,
42  WARNING = 4,
43  ERROR = 5,
44  FATAL = 6,
45 } log_level_t;
46 
47 typedef void (*logger_t)(log_level_t level, const char *message, ...);
48 
55 
63 
69 
75 
81 
87 
93 gru_export void gru_logger_default_printer(log_level_t level, const char *msg, ...);
94 
102  log_level_t level, const char *msg, va_list ap);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 // GRU_LOGGER_H_
109 #endif
log_level_t_
Definition: gru_logger.h:37
Definition: gru_logger.h:41
logger_t gru_logger_get(void)
Gets the logger.
Definition: gru_logger.c:25
void gru_logger_default_printer(log_level_t level, const char *msg,...)
Default logger that logs to stdout.
Definition: gru_logger.c:78
Definition: gru_logger.h:38
void gru_logger_set_mininum(log_level_t new_minimum)
Sets the minimum log level.
Definition: gru_logger.c:29
#define gru_export
Definition: gru_portable.h:19
Definition: gru_logger.h:40
log_level_t gru_logger_get_mininum()
Gets the minimum log level.
Definition: gru_logger.c:33
void gru_logger_set(logger_t new_logger)
Sets the logger.
Definition: gru_logger.c:21
log_level_t gru_logger_get_level(const char *str)
Gets the log level from an input string.
Definition: gru_logger.c:45
Definition: gru_logger.h:42
void gru_logger_default_do_print(log_level_t level, const char *msg, va_list ap)
Utility printing function that can be used by implementations of the logger printer.
Definition: gru_logger.c:90
bool gru_logger_can_log(log_level_t current)
Whether can log (ie.
Definition: gru_logger.c:37
Definition: gru_logger.h:44
Definition: gru_logger.h:43
Definition: gru_logger.h:39
enum log_level_t_ log_level_t
void(* logger_t)(log_level_t level, const char *message,...)
Definition: gru_logger.h:47