#ifndef LOG_H
#define LOG_H

#include "util.h"

/**
 * \brief Log types
 */
typedef enum {
    fatal = 1 << 0,
    error = 1 << 1,
    warning = 1 << 2,
    info = 1 << 3,
    debug = 1 << 4,
    link_lock_debug = 1 << 5,
    network_lock_debug = 1 << 6,
    cache_lock_debug = 1 << 7,
    libcurl_debug = 1 << 8,
} LogType;

/**
 * \brief The default log level
 */
#define DEFAULT_LOG_LEVEL (fatal | error | warning | info)

/**
 * \brief Get the log level from the environment.
 */
int log_level_init(void);

/**
 * \brief Log printf
 * \details This is for printing nice log messages
 */
void log_printf(LogType type, const char *file, const char *func, int line,
                const char *format,
                ...); // NOLINT(bugprone-easily-swappable-parameters)

/**
 * \brief Log type printf
 * \details This macro automatically prints out the filename and line number
 */
#define lprintf(type, ...)                                                     \
    do {                                                                       \
        log_printf(type, __FILE__, __func__, __LINE__, __VA_ARGS__);           \
        if ((type) == fatal)                                                   \
            exit_failure();                                                    \
    } while (0)

/**
 * \brief Print the version information for HTTPDirFS
 */
void print_version(void);

#endif
