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_LOG_H_ 23 #define _HF_LOG_H_ 24 25 #include <getopt.h> 26 #include <stdbool.h> 27 28 #include "common.h" 29 30 enum llevel_t { 31 FATAL = 0, 32 ERROR, 33 WARNING, 34 INFO, 35 DEBUG, 36 HELP, 37 HELP_BOLD 38 }; 39 40 extern enum llevel_t log_level; 41 42 #define LOG_HELP(...) logLog(HELP, __FUNCTION__, __LINE__, false, __VA_ARGS__); 43 #define LOG_HELP_BOLD(...) logLog(HELP_BOLD, __FUNCTION__, __LINE__, false, __VA_ARGS__); 44 45 #define LOG_D(...) if (log_level >= DEBUG) { logLog(DEBUG, __FUNCTION__, __LINE__, false, __VA_ARGS__); } 46 #define LOG_I(...) if (log_level >= INFO) { logLog(INFO, __FUNCTION__, __LINE__, false, __VA_ARGS__); } 47 #define LOG_W(...) if (log_level >= WARNING) { logLog(WARNING, __FUNCTION__, __LINE__, false, __VA_ARGS__); } 48 #define LOG_E(...) if (log_level >= ERROR) { logLog(ERROR, __FUNCTION__, __LINE__, false, __VA_ARGS__); } 49 #define LOG_F(...) if (log_level >= FATAL) { logLog(FATAL, __FUNCTION__, __LINE__, false, __VA_ARGS__); } 50 51 #define PLOG_D(...) if (log_level >= DEBUG) { logLog(DEBUG, __FUNCTION__, __LINE__, true, __VA_ARGS__); } 52 #define PLOG_I(...) if (log_level >= INFO) { logLog(INFO, __FUNCTION__, __LINE__, true, __VA_ARGS__); } 53 #define PLOG_W(...) if (log_level >= WARNING) { logLog(WARNING, __FUNCTION__, __LINE__, true, __VA_ARGS__); } 54 #define PLOG_E(...) if (log_level >= ERROR) { logLog(ERROR, __FUNCTION__, __LINE__, true, __VA_ARGS__); } 55 #define PLOG_F(...) if (log_level >= FATAL) { logLog(FATAL, __FUNCTION__, __LINE__, true, __VA_ARGS__); } 56 57 bool logInitLogFile(const char *logfile, enum llevel_t ll); 58 void logLog(enum llevel_t ll, const char *fn, int ln, bool perr, const char *fmt, ...) 59 __attribute__ ((format(printf, 5, 6))); 60 void logStop(int sig); 61 62 #endif /* _HF_LOG_H_ */ 63