4 * Simple logging functions
10 * LEVEL_NONE do not log anything.
11 * LEVEL_WARN Information that needs to be known.
12 * LEVEL_INFO Basic information like startup messages and occasional events.
13 * LEVEL_DEBUG debug statements about things happening that are less expected.
14 * LEVEL_TRACE Way to much information for anybody.
23 static const char *level_string
[5] = {
32 * struct to be initialized by the user of the logging system.
34 * name: The name attribute is used in logging statements do differentiate
37 * log_level The level attribute describes the requested logging level. a level
38 * of 1 will only print warnings while a level of 4 will print all the trace
41 * log_func The logging function to use to log, log.h provides default_log
42 * to display information on the kernel output buffer. As a bonus if the
43 * requested log level is debug or trace the method , file and line number will
44 * be printed to the steam.
51 /* the logging function itself */
52 void (*log_func
) (struct log
* driver
,
55 const char *function
, int line
, const char *fmt
, ...);
59 #define __log(driver,log_level, fmt, args...) \
60 ((driver)->log_func(driver,log_level, \
61 __FILE__, __FUNCTION__, __LINE__,\
65 #define log_warn(driver, fmt, args...) \
66 __log(driver, LEVEL_WARN, fmt, ## args)
68 /* Log an information message */
69 #define log_info(driver, fmt, args...) \
70 __log(driver, LEVEL_INFO, fmt, ## args)
72 /* log debugging output */
73 #define log_debug(driver, fmt, args...) \
74 __log(driver, LEVEL_DEBUG, fmt, ## args)
76 /* log trace output */
77 #define log_trace(driver, fmt, args...) \
78 __log(driver, LEVEL_TRACE, fmt, ## args)
80 #endif /* __LOG_H__ */
83 default_log(struct log
*driver
,
85 const char *file
, const char *function
, int line
, const char *fmt
, ...)
89 if (level
> driver
->log_level
) {
92 /* If the wanted level is debug also display line/method information */
93 if (driver
->log_level
>= LEVEL_DEBUG
) {
94 printf("%s(%s):%s+%d(%s):", driver
->name
,
95 level_string
[level
], file
, line
, function
);
97 printf("%s(%s)", driver
->name
, level_string
[level
]);
107 hexdump(unsigned char *d
, unsigned int size
)
110 for (s
= 0; s
< size
; s
+= 4) {
111 fprintf(stdout
, "0x%04x 0x%02X%02X%02X%02X %c%c%c%c\n", s
,
112 (unsigned int) d
[s
], (unsigned int) d
[s
+ 1],
113 (unsigned int) d
[s
+ 2], (unsigned int) d
[s
+ 3], d
[s
],
114 d
[s
+ 1], d
[s
+ 2], d
[s
+ 3]);