diff options
author | danh-arm <dan.handley@arm.com> | 2014-08-12 16:57:46 +0100 |
---|---|---|
committer | danh-arm <dan.handley@arm.com> | 2014-08-12 16:57:46 +0100 |
commit | 6f08fd5f95c276b532123994407d0c5999ff61db (patch) | |
tree | aee9e7965acceefc95afad26aa9839ec19a13270 /include/common/debug.h | |
parent | 46339731477bbed24f9dbf81d38deb5ad3b5727c (diff) | |
parent | 6ad2e461f0cd6de5aefd89fa0ba7acf2c293b8c2 (diff) |
Merge pull request #183 from danh-arm/dh/print_output2
Add concept of console output log levels
Rationalize console log output
Diffstat (limited to 'include/common/debug.h')
-rw-r--r-- | include/common/debug.h | 57 |
1 files changed, 43 insertions, 14 deletions
diff --git a/include/common/debug.h b/include/common/debug.h index 3f5655ba..a8dcb8da 100644 --- a/include/common/debug.h +++ b/include/common/debug.h @@ -33,24 +33,53 @@ #include <stdio.h> -/* If building the project with DEBUG disabled the INFO and WARN macros - * won't produce any output. The ERROR macro is always enabled. - * The format expected is the same as for printf(). - * INFO("Info %s.\n", "message") -> INFO: Info message. - * WARN("Warning %s.\n", "message") -> WARN: Warning message. - * ERROR("Error %s.\n", "message") -> ERROR: Error message. - * - * TODO : add debug levels. +/* The log output macros print output to the console. These macros produce + * compiled log output only if the LOG_LEVEL defined in the makefile (or the + * make command line) is greater or equal than the level required for that + * type of log output. + * The format expected is the same as for printf(). For example: + * INFO("Info %s.\n", "message") -> INFO: Info message. + * WARN("Warning %s.\n", "message") -> WARNING: Warning message. */ -#if DEBUG - #define INFO(...) tf_printf("INFO: " __VA_ARGS__) - #define WARN(...) tf_printf("WARN: " __VA_ARGS__) + +#define LOG_LEVEL_NONE 0 +#define LOG_LEVEL_ERROR 10 +#define LOG_LEVEL_NOTICE 20 +#define LOG_LEVEL_WARNING 30 +#define LOG_LEVEL_INFO 40 +#define LOG_LEVEL_VERBOSE 50 + + +#if LOG_LEVEL >= LOG_LEVEL_NOTICE +# define NOTICE(...) tf_printf("NOTICE: " __VA_ARGS__) +#else +# define NOTICE(...) +#endif + +#if LOG_LEVEL >= LOG_LEVEL_ERROR +# define ERROR(...) tf_printf("ERROR: " __VA_ARGS__) +#else +# define ERROR(...) +#endif + +#if LOG_LEVEL >= LOG_LEVEL_WARNING +# define WARN(...) tf_printf("WARNING: " __VA_ARGS__) +#else +# define WARN(...) +#endif + +#if LOG_LEVEL >= LOG_LEVEL_INFO +# define INFO(...) tf_printf("INFO: " __VA_ARGS__) +#else +# define INFO(...) +#endif + +#if LOG_LEVEL >= LOG_LEVEL_VERBOSE +# define VERBOSE(...) tf_printf("VERBOSE: " __VA_ARGS__) #else - #define INFO(...) - #define WARN(...) +# define VERBOSE(...) #endif -#define ERROR(...) tf_printf("ERROR: " __VA_ARGS__) void __dead2 do_panic(void); #define panic() do_panic() |