Debian Codegraph @

src/log.h

raw symbols SCIP
1 /*
2 * HTTPDirFS - HTTP Directory Filesystem
3 *
4 * Copyright (C) 2020-2026 Fufu Fang <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * In addition, as a special exception, the copyright holders give
20 * permission to link the code of portions of this program with the OpenSSL
21 * library.
22 */
23
24 #ifndef LOG_H
25 #define LOG_H
26 /**
27 * \file log.h
28 * \brief Logging system macros and levels header
29 */
30
31
32 /**
33 * \brief Log types
34 */
35 typedef enum {
36 fatal = 1 << 0,
37 error = 1 << 1,
38 warning = 1 << 2,
39 info = 1 << 3,
40 debug = 1 << 4,
41 link_lock_debug = 1 << 5,
42 network_lock_debug = 1 << 6,
43 cache_lock_debug = 1 << 7,
44 libcurl_debug = 1 << 8,
45 } LogType;
46
47 /**
48 * \brief The default log level
49 */
50 #define DEFAULT_LOG_LEVEL (fatal | error | warning | info)
51
52 /**
53 * \brief Get the log level from the environment.
54 */
55 int log_level_init(void);
56
57 /**
58 * \brief Log printf
59 * \details This is for printing nice log messages
60 */
61 void log_printf(LogType type, const char *file, const char *func, int line,
62 const char *format, ...) __attribute__((format(printf, 5, 6)));
63
64 /**
65 * \brief Fatal log printf
66 * \details This is for printing fatal error messages and exiting
67 */
68 _Noreturn void fatal_log_printf(const char *file, const char *func, int line,
69 const char *format, ...)
70 __attribute__((format(printf, 4, 5)));
71
72 /**
73 * \brief Log type printf
74 * \details This macro automatically prints out the filename and line number
75 */
76 #define lprintf(type, ...) \
77 do { \
78 LogType _l_type = (type); \
79 if (_l_type & fatal) \
80 fatal_log_printf(__FILE__, __func__, __LINE__, __VA_ARGS__); \
81 else \
82 log_printf(_l_type, __FILE__, __func__, __LINE__, __VA_ARGS__); \
83 } while (0)
84
85 /**
86 * \brief Print the version information for HTTPDirFS
87 */
88 void print_version(void);
89
90 #endif