84 lines
3.5 KiB
C
84 lines
3.5 KiB
C
/* *****************************************************************************
|
|
* libp7/internals/log.h -- libp7's logging system.
|
|
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of libp7.
|
|
* libp7 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.
|
|
*
|
|
* libp7 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 libp7; if not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* The libp7 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 libp7 core and built-in streams
|
|
* can use it.
|
|
*
|
|
* `log[m]_*` make use of the `handle` variable to display the name of the
|
|
* current handle (e.g. `server` or `client`). If you don't have one (that's
|
|
* the case for the streams functions), use the `logr[m]_*` functions.
|
|
* ************************************************************************** */
|
|
#ifndef LIBP7_INTERNALS_LOG_H
|
|
# define LIBP7_INTERNALS_LOG_H
|
|
# include <stdio.h>
|
|
|
|
/* Log levels */
|
|
# define ll_info p7_loglevel_info
|
|
# define ll_warn p7_loglevel_warn
|
|
# define ll_error p7_loglevel_error
|
|
# define ll_fatal p7_loglevel_fatal
|
|
# define ll_none p7_loglevel_none
|
|
|
|
/* check if we can log */
|
|
# if defined(P7_DISABLED_FILE)
|
|
# undef LOGLEVEL
|
|
# define LOGLEVEL ll_none
|
|
# endif
|
|
/* ************************************************************************** */
|
|
/* Log utilities */
|
|
/* ************************************************************************** */
|
|
/* Main functions */
|
|
extern void p7_log(const char *name, p7_loglevel_t loglevel,
|
|
const char *format, ...);
|
|
extern void p7_log_mem(const char *name, p7_loglevel_t loglevel,
|
|
const void *m, size_t n);
|
|
|
|
/* Macros */
|
|
# define p7_log_(LEVEL, ...) \
|
|
p7_log(handle->_name, (LEVEL), __VA_ARGS__)
|
|
# define p7_logm_(LEVEL, M, N) \
|
|
p7_log_mem(handle->_name, (LEVEL), (M), (N))
|
|
# define p7_logr_(LEVEL, ...) \
|
|
p7_log(NULL, (LEVEL), __VA_ARGS__)
|
|
# define p7_logrm_(LEVEL, M, N) \
|
|
p7_log_mem(NULL, (LEVEL), (M), (N))
|
|
|
|
/* Adapted for different log levels */
|
|
# define log_info(...) p7_log_(ll_info, __VA_ARGS__)
|
|
# define logm_info(M, N) p7_logm_(ll_info, (M), (N))
|
|
# define logr_info(...) p7_logr_(ll_info, __VA_ARGS__)
|
|
# define logrm_info(M, N) p7_logrm_(ll_info, (M), (N))
|
|
|
|
# define log_warn(...) p7_log_(ll_warn, __VA_ARGS__)
|
|
# define logm_warn(M, N) p7_logm_(ll_warn, (M), (N))
|
|
# define logr_warn(...) p7_logr_(ll_warn, __VA_ARGS__)
|
|
# define logrm_warn(M, N) p7_logrm_(ll_warn, (M), (N))
|
|
|
|
# define log_error(...) p7_log_(ll_error, __VA_ARGS__)
|
|
# define logm_error(M, N) p7_logm_(ll_error, (M), (N))
|
|
# define logr_error(...) p7_logr_(ll_error, __VA_ARGS__)
|
|
# define logrm_error(M, N) p7_logrm_(ll_error, (M), (N))
|
|
|
|
# define log_fatal(...) p7_log_(ll_fatal, __VA_ARGS__)
|
|
# define logm_fatal(M, N) p7_logm_(ll_fatal, (M), (N))
|
|
# define logr_fatal(...) p7_logr_(ll_fatal, __VA_ARGS__)
|
|
# define logrm_fatal(M, N) p7_logrm_(ll_fatal, (M), (N))
|
|
#endif /* LIBP7_INTERNALS_LOG_H */
|