libtcod
Loading...
Searching...
No Matches
logging.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2026, 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
54typedef struct TCOD_LogMessage {
55 const char* message; // Message that was logged.
56 int level; // The log level, usually one of TCOD_LogLevel.
57 const char* source; // Source file of the logged message, usually __FILE__.
58 int lineno; // Source line of the logged message, usually __LINE__.
60
63typedef void (*TCOD_LoggingCallback)(const TCOD_LogMessage* message, void* userdata);
64#ifdef __cplusplus
65extern "C" {
66#endif // __cplusplus
67
74TCODLIB_API void TCOD_set_log_level(int level);
75
84TCODLIB_API void TCOD_set_log_callback(TCOD_LoggingCallback callback, void* userdata);
85
93TCODLIB_API void TCOD_log_verbose_(const char* msg, int level, const char* source, int line);
94
103TCODLIB_FORMAT(4, 5)
104TCODLIB_API void TCOD_log_verbose_fmt_(int level, const char* source, int line, const char* fmt, ...);
105
106// All of these are for internal use.
107#define TCOD_log_debug_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_DEBUG, __FILE__, __LINE__, (fmt), __VA_ARGS__)
108#define TCOD_log_info_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_INFO, __FILE__, __LINE__, (fmt), __VA_ARGS__)
109#define TCOD_log_warning_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_WARNING, __FILE__, __LINE__, (fmt), __VA_ARGS__)
110#define TCOD_log_error_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_ERROR, __FILE__, __LINE__, (fmt), __VA_ARGS__)
111#define TCOD_log_critical_f(fmt, ...) TCOD_log_verbose_fmt_(TCOD_LOG_CRITICAL, __FILE__, __LINE__, (fmt), __VA_ARGS__)
112#define TCOD_log_debug(msg) TCOD_log_verbose_((msg), TCOD_LOG_DEBUG, __FILE__, __LINE__)
113#define TCOD_log_info(msg) TCOD_log_verbose_((msg), TCOD_LOG_INFO, __FILE__, __LINE__)
114#define TCOD_log_warning(msg) TCOD_log_verbose_((msg), TCOD_LOG_WARNING, __FILE__, __LINE__)
115#define TCOD_log_error(msg) TCOD_log_verbose_((msg), TCOD_LOG_ERROR, __FILE__, __LINE__)
116#define TCOD_log_critical(msg) TCOD_log_verbose_((msg), TCOD_LOG_CRITICAL, __FILE__, __LINE__)
117#ifdef __cplusplus
118} // extern "C"
119#endif // __cplusplus
120#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:63
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:54