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,
71 
79 
93 TEMU_API void temu_logSetFunc(void (*LogFunc)(const char *));
94 
121 TEMU_API void
122 temu_logSetAdvancedFunc(void (*LogFunc)(void *, temu_Object *, unsigned, temu_LogLevel, const char *), void *UserData);
123 
124 
131 TEMU_API void temu_logSetDefaultFile(FILE *FP);
132 
137 TEMU_API void temu_logSetColour(int Enable);
138 
144 TEMU_API void temu_logFatal(const void *Obj, const char *Msg, ...)
145  __attribute__((noreturn)) __attribute__((format(printf, 2, 3)));
146 
152 TEMU_API void temu_logError(const void *Obj, const char *Msg, ...)
153  __attribute__((format(printf, 2, 3)));
154 
160 TEMU_API void temu_logWarning(const void *Obj, const char *Msg, ...)
161  __attribute__((format(printf, 2, 3)));
162 
168 TEMU_API void temu_logInfo(const void *Obj, const char *Msg, ...)
169  __attribute__((format(printf, 2, 3)));
170 
176 TEMU_API void temu_logTrace(const void *Obj, const char *Msg, ...)
177  __attribute__((format(printf, 2, 3)));
178 
188 TEMU_API void temu_logDebugFunc(const void *Obj, const char *Msg, ...)
189  __attribute__((format(printf, 2, 3)));
190 
191 #ifdef NDEBUG
192 static inline void
193 temu_logDebug(const void *Obj TEMU_UNUSED, const char *Msg TEMU_UNUSED, ...)
194 {
195  ; // Nothing
196 }
197 
198 #else
199 
200 #define temu_logDebug temu_logDebugFunc
201 
202 #endif
203 
204 /*
205  * New logging API
206  *
207  * The new logging API provides specialised logging for temu_Object
208  * derived classes. They cannot be used by external classes.
209  *
210  * EXPERIMENTAL API New logging API. The New logging API provides
211  * improved logging support. Among the features include custom
212  * logging categories and per device per categor control of the
213  * logging. 16 logging categories are supported, of which the first
214  * 8 are reserved for TEMU (i.e. global categories).
215  * The next 8 can be controlled per class.
216  *
217  * The reserved categories is split in three main categories (sim,
218  * target and config). These are further subdivided in severity.
219  *
220  * The config category is used to inform users during the
221  * configuration phase or any issues detected with dynamic
222  * configuration. For example, a device with an IRQ property may be
223  * restricted to e.g. 8 different IRQs, if the user sets another value
224  * than the allowed ones then a config error would be logged.
225  *
226  * The target category is for errors triggered by target software, for
227  * example writing a register would be logged with
228  * temu_logTargetDebug(). Note that the category is intended for
229  * direct effects, which is mostly related to MMIO activity.
230  *
231  * The sim category is for other errors caused by e.g. invalid use of
232  * the TEMU APIs, or other failures.
233  *
234  * A nice feature of this API is the support for user definable
235  * categories. These categories are per class. But category enabling
236  * is controlled per object and globally. A category can be added to a
237  * class using temu_addLoggingCategory() (see Objsys.h), and queried
238  * by id using temu_getLoggingCategory(). The ID can then be used in
239  * calls to temu_logToCategory().
240  *
241  */
242 
243 // User reserved categories are those above 8
244 #define teLC_FirstUserCat 8
245 
246 #define teLC_DefaultCat 0
247 #define teLC_SimCat 1
248 #define teLC_TargetCat 2
249 #define teLC_ConfigCat 3
250 
251 TEMU_API void temu_logToCategoryVA(const void *Obj, unsigned Category,
252  temu_LogLevel Severity, const char *Msg,
253  va_list Args);
254 
261 TEMU_API void temu_logSetSeverity(void *Obj, unsigned Category,
262  temu_LogLevel Severity);
263 
271 TEMU_API void temu_logToCategory(const void *Obj, unsigned Category,
272  temu_LogLevel Severity, const char *Msg, ...)
273  __attribute__((format(printf, 4, 5)));
274 
282 TEMU_API void temu_logSimFatal(const void *Obj, const char *Msg, ...)
283  __attribute__((noreturn)) __attribute__((format(printf, 2, 3)));
284 
291 TEMU_API void temu_logSimError(const void *Obj, const char *Msg, ...)
292  __attribute__((format(printf, 2, 3)));
293 
300 TEMU_API void temu_logSimWarning(const void *Obj, const char *Msg, ...)
301  __attribute__((format(printf, 2, 3)));
302 
309 TEMU_API void temu_logSimInfo(const void *Obj, const char *Msg, ...)
310  __attribute__((format(printf, 2, 3)));
311 
320 TEMU_API void temu_logTargetFatal(const void *Obj, const char *Msg, ...)
321  __attribute__((noreturn)) __attribute__((format(printf, 2, 3)));
322 
329 TEMU_API void temu_logTargetError(const void *Obj, const char *Msg, ...)
330  __attribute__((format(printf, 2, 3)));
331 
338 TEMU_API void temu_logTargetWarning(const void *Obj, const char *Msg, ...)
339  __attribute__((format(printf, 2, 3)));
340 
348 TEMU_API void temu_logTargetInfo(const void *Obj, const char *Msg, ...)
349  __attribute__((format(printf, 2, 3)));
350 
357 TEMU_API void temu_logConfigFatal(const void *Obj, const char *Msg, ...)
358  __attribute__((noreturn)) __attribute__((format(printf, 2, 3)));
359 
366 TEMU_API void temu_logConfigError(const void *Obj, const char *Msg, ...)
367  __attribute__((format(printf, 2, 3)));
368 
375 TEMU_API void temu_logConfigWarning(const void *Obj, const char *Msg, ...)
376  __attribute__((format(printf, 2, 3)));
377 
385 TEMU_API void temu_logConfigInfo(const void *Obj, const char *Msg, ...)
386  __attribute__((format(printf, 2, 3)));
387 
395 TEMU_API temu_LogLevel temu_objectGetLogLevel(void *Obj, unsigned Category);
403 TEMU_API void temu_objectSetLogLevel(void *Obj, unsigned Category,
404  temu_LogLevel LogLevel);
405 
406 #ifdef __cplusplus
407 }
408 #endif
409 
410 #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_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
Trace messages, not compiled away.
Definition: Logging.h:68
TEMU_API void TEMU_API void TEMU_API void TEMU_API void TEMU_API void temu_logTrace(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_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_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:200
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:69
TEMU_API void temu_logToCategoryVA(const void *Obj, unsigned Category, temu_LogLevel Severity, const char *Msg, va_list Args)