blob: c2ab1f51225aceaf89753800da99ff329f2d1f9a [file] [log] [blame]
robert.swiecki3bb518c2010-10-14 00:48:24 +00001/*
robert.swiecki3bb518c2010-10-14 00:48:24 +00002
Robert Swieckic8c32db2015-10-09 18:06:22 +02003 honggfuzz - logging
4 -----------------------------------------
robert.swiecki3bb518c2010-10-14 00:48:24 +00005
Robert Swieckic8c32db2015-10-09 18:06:22 +02006 Copyright 2014 Google Inc. All Rights Reserved.
Robert Swiecki7353a8d2015-09-08 15:53:59 +02007
Robert Swieckic8c32db2015-10-09 18:06:22 +02008 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
robert.swiecki3bb518c2010-10-14 00:48:24 +000011
Robert Swieckic8c32db2015-10-09 18:06:22 +020012 http://www.apache.org/licenses/LICENSE-2.0
robert.swiecki3bb518c2010-10-14 00:48:24 +000013
Robert Swieckic8c32db2015-10-09 18:06:22 +020014 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.
Robert Swiecki30254b82015-10-08 16:36:08 +020019
Robert Swieckic8c32db2015-10-09 18:06:22 +020020*/
robert.swiecki3bb518c2010-10-14 00:48:24 +000021
Jagger48a1b902016-02-09 22:12:02 +010022#ifndef _HF_LOG_H_
23#define _HF_LOG_H_
Robert Swiecki7353a8d2015-09-08 15:53:59 +020024
Robert Swieckic8c32db2015-10-09 18:06:22 +020025#include <getopt.h>
26#include <stdbool.h>
robert.swiecki3bb518c2010-10-14 00:48:24 +000027
Robert Swieckic8c32db2015-10-09 18:06:22 +020028#include "common.h"
29
Robert Swieckic8c32db2015-10-09 18:06:22 +020030enum llevel_t {
Robert Swieckia88f96f2015-10-09 16:47:39 +020031 FATAL = 0,
Robert Swieckic8c32db2015-10-09 18:06:22 +020032 ERROR,
Robert Swieckia88f96f2015-10-09 16:47:39 +020033 WARNING,
34 INFO,
35 DEBUG,
36 HELP,
37 HELP_BOLD
Robert Swieckic8c32db2015-10-09 18:06:22 +020038};
39
Jagger93fd06c2016-01-28 04:26:04 +010040extern 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
Robert Swieckic8c32db2015-10-09 18:06:22 +020057bool logInitLogFile(const char *logfile, enum llevel_t ll);
58void logLog(enum llevel_t ll, const char *fn, int ln, bool perr, const char *fmt, ...)
59 __attribute__ ((format(printf, 5, 6)));
60void logStop(int sig);
61
Jagger48a1b902016-02-09 22:12:02 +010062#endif /* _HF_LOG_H_ */