• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   honggfuzz - logging
4  *   -----------------------------------------
5  *
6  *   Copyright 2014 Google Inc. All Rights Reserved.
7  *
8  *   Licensed under the Apache License, Version 2.0 (the "License");
9  *   you may not use this file except in compliance with the License.
10  *   You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *   Unless required by applicable law or agreed to in writing, software
15  *   distributed under the License is distributed on an "AS IS" BASIS,
16  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *   See the License for the specific language governing permissions and
18  *   limitations under the License.
19  *
20  */
21 
22 #ifndef _HF_COMMON_LOG_H_
23 #define _HF_COMMON_LOG_H_
24 
25 #include <pthread.h>
26 #include <stdbool.h>
27 #include <stdlib.h>
28 
29 enum llevel_t { FATAL = 0, ERROR, WARNING, INFO, DEBUG, HELP, HELP_BOLD };
30 
31 extern enum llevel_t log_level;
32 
33 #define LOG_HELP(...) logLog(HELP, __FUNCTION__, __LINE__, false, __VA_ARGS__);
34 #define LOG_HELP_BOLD(...) logLog(HELP_BOLD, __FUNCTION__, __LINE__, false, __VA_ARGS__);
35 
36 #define LOG_D(...)                                                 \
37     if (log_level >= DEBUG) {                                      \
38         logLog(DEBUG, __FUNCTION__, __LINE__, false, __VA_ARGS__); \
39     }
40 #define LOG_I(...)                                                \
41     if (log_level >= INFO) {                                      \
42         logLog(INFO, __FUNCTION__, __LINE__, false, __VA_ARGS__); \
43     }
44 #define LOG_W(...)                                                   \
45     if (log_level >= WARNING) {                                      \
46         logLog(WARNING, __FUNCTION__, __LINE__, false, __VA_ARGS__); \
47     }
48 #define LOG_E(...)                                                 \
49     if (log_level >= ERROR) {                                      \
50         logLog(ERROR, __FUNCTION__, __LINE__, false, __VA_ARGS__); \
51     }
52 #define LOG_F(...)                                             \
53     logLog(FATAL, __FUNCTION__, __LINE__, false, __VA_ARGS__); \
54     exit(EXIT_FAILURE);
55 
56 #define PLOG_D(...)                                               \
57     if (log_level >= DEBUG) {                                     \
58         logLog(DEBUG, __FUNCTION__, __LINE__, true, __VA_ARGS__); \
59     }
60 #define PLOG_I(...)                                              \
61     if (log_level >= INFO) {                                     \
62         logLog(INFO, __FUNCTION__, __LINE__, true, __VA_ARGS__); \
63     }
64 #define PLOG_W(...)                                                 \
65     if (log_level >= WARNING) {                                     \
66         logLog(WARNING, __FUNCTION__, __LINE__, true, __VA_ARGS__); \
67     }
68 #define PLOG_E(...)                                               \
69     if (log_level >= ERROR) {                                     \
70         logLog(ERROR, __FUNCTION__, __LINE__, true, __VA_ARGS__); \
71     }
72 #define PLOG_F(...)                                           \
73     logLog(FATAL, __FUNCTION__, __LINE__, true, __VA_ARGS__); \
74     exit(EXIT_FAILURE);
75 
76 extern void logInitLogFile(const char* logfile, int fd, enum llevel_t ll);
77 
78 extern void logLog(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt, ...)
79     __attribute__((format(printf, 5, 6)));
80 
81 extern void logStop(int sig);
82 
83 extern bool logIsTTY(void);
84 
85 extern void logRedirectLogFD(int fd);
86 
87 extern int logFd(void);
88 
89 extern enum llevel_t logGetLevel(void);
90 
91 extern pthread_mutex_t* logMutexGet(void);
92 
93 void logMutexReset(void);
94 
95 #endif /* ifndef _HF_COMMON_LOG_H_ */
96