blob: 0c2456576151f6d66b789bbd88efaa6d6aca2a53 [file] [log] [blame]
robert.swiecki3bb518c2010-10-14 00:48:24 +00001/*
Robert Swieckieab0e862016-10-18 23:04:42 +02002 *
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 */
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>
Robert Swiecki0212d692016-08-30 16:45:33 +020026#include <pthread.h>
Robert Swieckic8c32db2015-10-09 18:06:22 +020027#include <stdbool.h>
robert.swiecki3bb518c2010-10-14 00:48:24 +000028
Robert Swieckic8c32db2015-10-09 18:06:22 +020029#include "common.h"
30
Robert Swieckic8c32db2015-10-09 18:06:22 +020031enum llevel_t {
Robert Swieckia88f96f2015-10-09 16:47:39 +020032 FATAL = 0,
Robert Swieckic8c32db2015-10-09 18:06:22 +020033 ERROR,
Robert Swieckia88f96f2015-10-09 16:47:39 +020034 WARNING,
35 INFO,
36 DEBUG,
37 HELP,
38 HELP_BOLD
Robert Swieckic8c32db2015-10-09 18:06:22 +020039};
40
Jagger93fd06c2016-01-28 04:26:04 +010041extern enum llevel_t log_level;
42
43#define LOG_HELP(...) logLog(HELP, __FUNCTION__, __LINE__, false, __VA_ARGS__);
44#define LOG_HELP_BOLD(...) logLog(HELP_BOLD, __FUNCTION__, __LINE__, false, __VA_ARGS__);
45
46#define LOG_D(...) if (log_level >= DEBUG) { logLog(DEBUG, __FUNCTION__, __LINE__, false, __VA_ARGS__); }
47#define LOG_I(...) if (log_level >= INFO) { logLog(INFO, __FUNCTION__, __LINE__, false, __VA_ARGS__); }
48#define LOG_W(...) if (log_level >= WARNING) { logLog(WARNING, __FUNCTION__, __LINE__, false, __VA_ARGS__); }
49#define LOG_E(...) if (log_level >= ERROR) { logLog(ERROR, __FUNCTION__, __LINE__, false, __VA_ARGS__); }
50#define LOG_F(...) if (log_level >= FATAL) { logLog(FATAL, __FUNCTION__, __LINE__, false, __VA_ARGS__); }
51
52#define PLOG_D(...) if (log_level >= DEBUG) { logLog(DEBUG, __FUNCTION__, __LINE__, true, __VA_ARGS__); }
53#define PLOG_I(...) if (log_level >= INFO) { logLog(INFO, __FUNCTION__, __LINE__, true, __VA_ARGS__); }
54#define PLOG_W(...) if (log_level >= WARNING) { logLog(WARNING, __FUNCTION__, __LINE__, true, __VA_ARGS__); }
55#define PLOG_E(...) if (log_level >= ERROR) { logLog(ERROR, __FUNCTION__, __LINE__, true, __VA_ARGS__); }
56#define PLOG_F(...) if (log_level >= FATAL) { logLog(FATAL, __FUNCTION__, __LINE__, true, __VA_ARGS__); }
57
Robert Swiecki0212d692016-08-30 16:45:33 +020058extern bool logInitLogFile(const char *logfile, enum llevel_t ll);
Robert Swieckieab0e862016-10-18 23:04:42 +020059
Robert Swiecki0212d692016-08-30 16:45:33 +020060extern void logLog(enum llevel_t ll, const char *fn, int ln, bool perr, const char *fmt, ...)
Robert Swieckic8c32db2015-10-09 18:06:22 +020061 __attribute__ ((format(printf, 5, 6)));
Robert Swieckieab0e862016-10-18 23:04:42 +020062
Robert Swiecki0212d692016-08-30 16:45:33 +020063extern void logStop(int sig);
Robert Swieckieab0e862016-10-18 23:04:42 +020064
Robert Swiecki0212d692016-08-30 16:45:33 +020065extern pthread_mutex_t *logMutexGet(void);
Robert Swieckic8c32db2015-10-09 18:06:22 +020066
Jagger48a1b902016-02-09 22:12:02 +010067#endif /* _HF_LOG_H_ */