4 * Simple logging functions for the MMC layer
8 * LEVEL_NONE do not log anything.
9 * LEVEL_WARN Information that needs to be known.
10 * LEVEL_INFO Basic information like startup messages and occasional events.
11 * LEVEL_DEBUG debug statements about things happening that are less expected.
12 * LEVEL_TRACE Way to much information for anybody.
21 static const char *level_string
[5] = {
30 * struct to be initialized by the user of the logging system.
32 * name: The name attribute is used in logging statements do differentiate
35 * log_level The level attribute describes the requested logging level. a level
36 * of 1 will only print warnings while a level of 4 will print all the trace
39 * log_func The logging function to use to log, mmclog.h provides default_log
40 * to display information on the kernel output buffer. As a bonus if the
41 * requested log level is debug or trace the method , file and line number will
42 * be printed to the steam.
44 struct mmclog
{ const char *name
; int log_level
;
46 /* the logging function itself */
47 void (*log_func
) (struct mmclog
* driver
,
50 const char *function
, int line
, const char *fmt
, ...);
54 #define __mmc_log(driver,log_level, fmt, args...) \
55 ((driver)->log_func(driver,log_level, \
56 __FILE__, __FUNCTION__, __LINE__,\
60 #define mmc_log_warn(driver, fmt, args...) \
61 __mmc_log(driver, LEVEL_WARN, fmt, ## args)
63 /* Log an information message */
64 #define mmc_log_info(driver, fmt, args...) \
65 __mmc_log(driver, LEVEL_INFO, fmt, ## args)
67 /* log debugging output */
68 #define mmc_log_debug(driver, fmt, args...) \
69 __mmc_log(driver, LEVEL_DEBUG, fmt, ## args)
71 /* log trace output */
72 #define mmc_log_trace(driver, fmt, args...) \
73 __mmc_log(driver, LEVEL_TRACE, fmt, ## args)
75 #endif /* __MMCLOG_H__ */
78 default_log(struct mmclog
*driver
,
80 const char *file
, const char *function
, int line
, const char *fmt
, ...)
84 if (level
> driver
->log_level
) {
87 /* If the wanted level is debug also display line/method information */
88 if (driver
->log_level
>= LEVEL_DEBUG
) {
89 fprintf(stderr
, "%s(%s):%s+%d(%s):", driver
->name
,
90 level_string
[level
], file
, line
, function
);
92 fprintf(stderr
, "%s(%s)", driver
->name
, level_string
[level
]);
96 vfprintf(stderr
, fmt
, args
);
102 hexdump(unsigned char *d
, unsigned int size
)
105 for (s
= 0; s
< size
; s
+= 4) {
106 fprintf(stdout
, "0x%04x 0x%02X%02X%02X%02X %c%c%c%c\n", s
,
107 (unsigned int) d
[s
], (unsigned int) d
[s
+ 1],
108 (unsigned int) d
[s
+ 2], (unsigned int) d
[s
+ 3], d
[s
],
109 d
[s
+ 1], d
[s
+ 2], d
[s
+ 3]);