/* ***************************************************************************** * libg1m/internals/log.h -- libg1m's logging system. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. * libg1m is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3.0 of the License, * or (at your option) any later version. * * libg1m is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * * The libg1m logging system is quite simple and defined at compilation time. * It cannot be tweaked at runtime (I should probably correct that someday). * Also, as it's an internal header, only the libg1m sources can use it. * ************************************************************************** */ #ifndef LIBG1M_INTERNALS_LOG_H # define LIBG1M_INTERNALS_LOG_H # include # include /* Some printf types */ # ifdef _WIN64 # define PRIuSIZE "l64u" # elif _WIN32 # define PRIuSIZE "u" # else # define PRIuSIZE "zu" # endif /* ************************************************************************** */ /* Log utility */ /* ************************************************************************** */ /* Log level */ # define ll_info 0 # define ll_warn 1 # define ll_error 2 # define ll_fatal 3 # define ll_none 4 /* Macros */ # define g1m_log(P, S, ...) \ fprintf(stderr, P "%s: " S "\n", __FUNCTION__, ##__VA_ARGS__) # define logm(S, M, N) g1m_log_mem(S, M, N) # if LOGLEVEL <= ll_info # define log_info(S, ...) g1m_log("[libg1m info] ", S, ##__VA_ARGS__) # define logm_info(M, N) logm("[libg1m info] ", M, N) # else # define log_info(S, ...) # define logm_info(M, N) # endif # if LOGLEVEL <= ll_warn # define log_warn(S, ...) g1m_log("[libg1m warn] ", S, ##__VA_ARGS__) # define logm_warn(M, N) logm("[libg1m warn] ", M, N) # else # define log_warn(S, ...) # define logm_warn(M, N) # endif # if LOGLEVEL <= ll_error # define log_error(S, ...) g1m_log("[libg1m error] ", S, ##__VA_ARGS__) # else # define log_error(S, ...) # endif # if LOGLEVEL <= ll_fatal # define log_fatal(S, ...) g1m_log("[libg1m fatal] ", S, ##__VA_ARGS__) # else # define log_fatal(S, ...) # endif /* Functions prototypes */ void g1m_log_mem(const char *prefix, void *m, size_t n); const char *g1m_get_type_string(int main_id, int type); const char *g1m_get_mcs_ftype_string(int code); const char *g1m_get_eact_ltype_string(int code); #endif /* LIBG1M_INTERNALS_LOG_H */