libtcod
Loading...
Searching...
No Matches
logging.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34#pragma once
35#ifndef LIBTCOD_LOGGING_H_
36#define LIBTCOD_LOGGING_H_
37
38#include "config.h"
39#include "error.h"
40
41typedef enum TCOD_LogLevel {
42 TCOD_LOG_DEBUG = 10,
43 TCOD_LOG_INFO = 20,
44 TCOD_LOG_WARNING = 30,
45 TCOD_LOG_ERROR = 40,
46 TCOD_LOG_CRITICAL = 50,
47} TCOD_LogLevel;
48
56typedef struct TCOD_LogMessage {
57 const char* message; // Message that was logged.
58 int level; // The log level, usually one of TCOD_LogLevel.
59 const char* source; // Source file of the logged message, usually __FILE__.
60 int lineno; // Source line of the logged message, usually __LINE__.
62
65typedef void (*TCOD_LoggingCallback)(const TCOD_LogMessage* message, void* userdata);
66#ifdef __cplusplus
67extern "C" {
68#endif // __cplusplus
69
78TCODLIB_API void TCOD_set_log_level(int level);
79
90TCODLIB_API void TCOD_set_log_callback(TCOD_LoggingCallback callback, void* userdata);
91
99TCODLIB_API void TCOD_log_verbose_(const char* msg, int level, const char* source, int line);
100
109TCODLIB_FORMAT(4, 5)
110TCODLIB_API void TCOD_log_verbose_fmt_(int level, const char* source, int line, const char* fmt, ...);
111
112// All of these are for internal use.
113#define TCOD_log_debug_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_DEBUG, __FILE__, __LINE__, (fmt), __VA_ARGS__)
114#define TCOD_log_info_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_INFO, __FILE__, __LINE__, (fmt), __VA_ARGS__)
115#define TCOD_log_warning_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_WARNING, __FILE__, __LINE__, (fmt), __VA_ARGS__)
116#define TCOD_log_error_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_ERROR, __FILE__, __LINE__, (fmt), __VA_ARGS__)
117#define TCOD_log_critical_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_CRITICAL, __FILE__, __LINE__, (fmt), __VA_ARGS__)
118#define TCOD_log_debug(msg) TCOD_log_verbose_((msg), TCOD_LOG_DEBUG, __FILE__, __LINE__)
119#define TCOD_log_info(msg) TCOD_log_verbose_((msg), TCOD_LOG_INFO, __FILE__, __LINE__)
120#define TCOD_log_warning(msg) TCOD_log_verbose_((msg), TCOD_LOG_WARNING, __FILE__, __LINE__)
121#define TCOD_log_error(msg) TCOD_log_verbose_((msg), TCOD_LOG_ERROR, __FILE__, __LINE__)
122#define TCOD_log_critical(msg) TCOD_log_verbose_((msg), TCOD_LOG_CRITICAL, __FILE__, __LINE__)
123#ifdef __cplusplus
124} // extern "C"
125#endif // __cplusplus
126#endif // LIBTCOD_LOGGING_H_
Libtcod config header.
Error handling module.
void TCOD_set_log_level(int level)
Set the level of messages being logged.
void(* TCOD_LoggingCallback)(const TCOD_LogMessage *message, void *userdata)
A callback for logger listeners.
Definition logging.h:65
void TCOD_set_log_callback(TCOD_LoggingCallback callback, void *userdata)
Sets a callback for libtcod's logged output.
Information being logged, this is a temporary object which doesn't last longer than the logging callb...
Definition logging.h:56