TEMU  3.0
The Terma Emulator
Logging.h
Go to the documentation of this file.
1 //===-- temu-c/Logging.h - Logging functions --------------------*- C++ -*-===//
2 //
3 // TEMU: The Terma Emulator
4 // (c) Terma 2015
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEMU_LOGGING_H
10 #define TEMU_LOGGING_H
11 
13 #include "temu-c/Support/Objsys.h"
14 #include <stdarg.h>
15 #include <stdio.h>
16 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
63 typedef enum temu_LogLevel {
64  teLL_Fatal = 0,
70 
78 
92 TEMU_API void temu_logSetFunc(void (*LogFunc)(const char *));
93 
120 TEMU_API void
121 temu_logSetAdvancedFunc(void (*LogFunc)(void *, temu_Object *, unsigned, temu_LogLevel, const char *), void *UserData);
122 
123 
130 TEMU_API void temu_logSetDefaultFile(FILE *FP);
131 
136 TEMU_API void temu_logSetColour(int Enable);
137 
143 TEMU_API void temu_logFatal(const void *Obj, const char *Msg, ...)
144  __attribute__((noreturn)) __attribute__((format(printf, 2, 3)));
145 
151 TEMU_API void temu_logError(const void *Obj, const char *Msg, ...)
152  __attribute__((format(printf, 2, 3)));
153 
159 TEMU_API void temu_logWarning(const void *Obj, const char *Msg, ...)
160  __attribute__((format(printf, 2, 3)));
161 
167 TEMU_API void temu_logInfo(const void *Obj, const char *Msg, ...)
168  __attribute__((format(printf, 2, 3)));
169 
179 TEMU_API void temu_logDebugFunc(const void *Obj, const char *Msg, ...)
180  __attribute__((format(printf, 2, 3)));
181 
182 #ifdef NDEBUG
183 static inline void
184 temu_logDebug(const void *Obj TEMU_UNUSED, const char *Msg TEMU_UNUSED, ...)
185 {
186  ; // Nothing
187 }
188 
189 #else
190 
191 #define temu_logDebug temu_logDebugFunc
192 
193 #endif
194 
195 /*
196  * New logging API
197  *
198  * The new logging API provides specialised logging for temu_Object
199  * derived classes. They cannot be used by external classes.
200  *
201  * EXPERIMENTAL API New logging API. The New logging API provides
202  * improved logging support. Among the features include custom
203  * logging categories and per device per categor control of the
204  * logging. 16 logging categories are supported, of which the first
205  * 8 are reserved for TEMU (i.e. global categories).
206  * The next 8 can be controlled per class.
207  *
208  * The reserved categories is split in three main categories (sim,
209  * target and config). These are further subdivided in severity.
210  *
211  * The config category is used to inform users during the
212  * configuration phase or any issues detected with dynamic
213  * configuration. For example, a device with an IRQ property may be
214  * restricted to e.g. 8 different IRQs, if the user sets another value
215  * than the allowed ones then a config error would be logged.
216  *
217  * The target category is for errors triggered by target software, for
218  * example writing a register would be logged with
219  * temu_logTargetDebug(). Note that the category is intended for
220  * direct effects, which is mostly related to MMIO activity.
221  *
222  * The sim category is for other errors caused by e.g. invalid use of
223  * the TEMU APIs, or other failures.
224  *
225  * A nice feature of this API is the support for user definable
226  * categories. These categories are per class. But category enabling
227  * is controlled per object and globally. A category can be added to a
228  * class using temu_addLoggingCategory() (see Objsys.h), and queried
229  * by id using temu_getLoggingCategory(). The ID can then be used in
230  * calls to temu_logToCategory().
231  *
232  */
233 
234 // User reserved categories are those above 8
235 #define teLC_FirstUserCat 8
236 
237 #define teLC_DefaultCat 0
238 #define teLC_SimCat 1
239 #define teLC_TargetCat 2
240 #define teLC_ConfigCat 3
241 
242 TEMU_API void temu_logToCategoryVA(const void *Obj, unsigned Category,
243  temu_LogLevel Severity, const char *Msg,
244  va_list Args);
245 
252 TEMU_API void temu_logSetSeverity(void *Obj, unsigned Category,
253  temu_LogLevel Severity);
254 
258 TEMU_API void temu_logToCategory(const void *Obj, unsigned Category,
259  temu_LogLevel Severity, const char *Msg, ...)
260  __attribute__((format(printf, 4, 5)));
261 
269 TEMU_API void temu_logSimFatal(const void *Obj, const char *Msg, ...)
270  __attribute__((noreturn)) __attribute__((format(printf, 2, 3)));
271 
278 TEMU_API void temu_logSimError(const void *Obj, const char *Msg, ...)
279  __attribute__((format(printf, 2, 3)));
280 
287 TEMU_API void temu_logSimWarning(const void *Obj, const char *Msg, ...)
288  __attribute__((format(printf, 2, 3)));
289 
296 TEMU_API void temu_logSimInfo(const void *Obj, const char *Msg, ...)
297  __attribute__((format(printf, 2, 3)));
298 
307 TEMU_API void temu_logTargetFatal(const void *Obj, const char *Msg, ...)
308  __attribute__((noreturn)) __attribute__((format(printf, 2, 3)));
309 
316 TEMU_API void temu_logTargetError(const void *Obj, const char *Msg, ...)
317  __attribute__((format(printf, 2, 3)));
318 
325 TEMU_API void temu_logTargetWarning(const void *Obj, const char *Msg, ...)
326  __attribute__((format(printf, 2, 3)));
327 
335 TEMU_API void temu_logTargetInfo(const void *Obj, const char *Msg, ...)
336  __attribute__((format(printf, 2, 3)));
337 
344 TEMU_API void temu_logConfigFatal(const void *Obj, const char *Msg, ...)
345  __attribute__((noreturn)) __attribute__((format(printf, 2, 3)));
346 
353 TEMU_API void temu_logConfigError(const void *Obj, const char *Msg, ...)
354  __attribute__((format(printf, 2, 3)));
355 
362 TEMU_API void temu_logConfigWarning(const void *Obj, const char *Msg, ...)
363  __attribute__((format(printf, 2, 3)));
364 
372 TEMU_API void temu_logConfigInfo(const void *Obj, const char *Msg, ...)
373  __attribute__((format(printf, 2, 3)));
374 
375 TEMU_API temu_LogLevel temu_objectGetLogLevel(void *Obj, unsigned Category);
376 TEMU_API void temu_objectSetLogLevel(void *Obj, unsigned Category,
377  temu_LogLevel LogLevel);
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 
383 #endif /* ! TEMU_LOGGING_H */
TEMU_API void temu_logToCategory(const void *Obj, unsigned Category, temu_LogLevel Severity, const char *Msg,...) __attribute__((format(printf
TEMU_API void temu_logFatal(const void *Obj, const char *Msg,...) __attribute__((noreturn)) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logDebugFunc(const void *Obj, const char *Msg,...) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logConfigInfo(const void *Obj, const char *Msg,...) __attribute__((format(printf
temu_LogLevel
Definition: Logging.h:63
TEMU_API void temu_logSetLevel(temu_LogLevel LogLevel)
TEMU_API void temu_objectSetLogLevel(void *Obj, unsigned Category, temu_LogLevel LogLevel)
Warnings.
Definition: Logging.h:66
TEMU_API void temu_logSetSeverity(void *Obj, unsigned Category, temu_LogLevel Severity)
#define TEMU_UNUSED
Definition: Attributes.h:31
TEMU_API void TEMU_API void temu_logSimFatal(const void *Obj, const char *Msg,...) __attribute__((noreturn)) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logInfo(const void *Obj, const char *Msg,...) __attribute__((format(printf
TEMU_API void temu_logSetDefaultFile(FILE *FP)
TEMU_API void TEMU_API void TEMU_API void temu_logSimError(const void *Obj, const char *Msg,...) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logConfigWarning(const void *Obj, const char *Msg,...) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logTargetInfo(const void *Obj, const char *Msg,...) __attribute__((format(printf
Normal messages.
Definition: Logging.h:67
TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logSimWarning(const void *Obj, const char *Msg,...) __attribute__((format(printf
TEMU_API void temu_logSetAdvancedFunc(void(*LogFunc)(void *, temu_Object *, unsigned, temu_LogLevel, const char *), void *UserData)
#define TEMU_API
Definition: Attributes.h:53
TEMU_API void TEMU_API void TEMU_API void temu_logWarning(const void *Obj, const char *Msg,...) __attribute__((format(printf
Fatal, emulator cannot keep on running.
Definition: Logging.h:64
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logTargetFatal(const void *Obj, const char *Msg,...) __attribute__((noreturn)) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API temu_LogLevel temu_objectGetLogLevel(void *Obj, unsigned Category)
Definition: Objsys.h:82
TEMU_API void TEMU_API void temu_logError(const void *Obj, const char *Msg,...) __attribute__((format(printf
TEMU_API void temu_logSetFunc(void(*LogFunc)(const char *))
TEMU_API void temu_logSetColour(int Enable)
#define temu_logDebug
Definition: Logging.h:191
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logSimInfo(const void *Obj, const char *Msg,...) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logTargetError(const void *Obj, const char *Msg,...) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logConfigError(const void *Obj, const char *Msg,...) __attribute__((format(printf
Error happened, in principle critical but up to user.
Definition: Logging.h:65
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logConfigFatal(const void *Obj, const char *Msg,...) __attribute__((noreturn)) __attribute__((format(printf
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logTargetWarning(const void *Obj, const char *Msg,...) __attribute__((format(printf
Debug.
Definition: Logging.h:68
TEMU_API void temu_logToCategoryVA(const void *Obj, unsigned Category, temu_LogLevel Severity, const char *Msg, va_list Args)