Mercurial > sci
diff libsci/log.h @ 33:1d0ddf9e6efd
misc: general documentation
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 04 Aug 2022 16:47:10 +0200 |
parents | lib/log.h@081e1c258e64 |
children | 71cd8447e3a4 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsci/log.h Thu Aug 04 16:47:10 2022 +0200 @@ -0,0 +1,51 @@ +/* + * log.h -- logging routines + * + * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef SCI_LOG_H +#define SCI_LOG_H + +#include <stdarg.h> +#include <stdlib.h> + +enum log_level { + LOG_LEVEL_WARNING = 1, + LOG_LEVEL_INFO, + LOG_LEVEL_DEBUG +}; + +#define log_debug(...) log_write(LOG_LEVEL_DEBUG, __VA_ARGS__) +#define log_warn(...) log_write(LOG_LEVEL_WARNING, __VA_ARGS__) +#define log_info(...) log_write(LOG_LEVEL_INFO, __VA_ARGS__) +#define log_die(...) do { \ + log_write(LOG_LEVEL_WARNING, __VA_ARGS__); \ + exit(1); \ +} while (0) + +void +log_open(const char *); + +void +log_write(enum log_level, const char *, ...); + +void +log_vwrite(enum log_level, const char *, va_list); + +void +log_finish(void); + +#endif /* !SCI_LOG_H */