123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- #ifndef __NV_LOGGING_H_
- #define __NV_LOGGING_H_
- #include <iostream>
- #include <sstream>
- #define LOG_LEVEL_INFO 0
- #define LOG_LEVEL_ERROR 1
- #define LOG_LEVEL_WARN 2
- #define LOG_LEVEL_DEBUG 3
- extern int log_level;
- #define DEFAULT_LOG_LEVEL LOG_LEVEL_ERROR
- #define stringify(s) #s
- #define xstringify(s) stringify(s)
- #define __LINE_NUM_STR__ xstringify(__LINE__)
- extern const char *log_level_name[];
- #define PRINT_MSG(level, str1) if(level <= log_level) { \
- std::ostringstream ostr; \
- ostr << "[" << log_level_name[level] << "] (" << \
- __FILE__ << ":" __LINE_NUM_STR__ ") " << \
- str1 << std::endl; \
- std::cerr << ostr.str(); \
- }
- #define INFO_MSG(str) PRINT_MSG(LOG_LEVEL_INFO, str)
- #define COMP_INFO_MSG(str) INFO_MSG("<" << comp_name << "> " << str)
- #define CAT_INFO_MSG(str) INFO_MSG("<" CAT_NAME "> " << str)
- #define ERROR_MSG(str) PRINT_MSG(LOG_LEVEL_ERROR, str)
- #define COMP_ERROR_MSG(str) ERROR_MSG("<" << comp_name << "> " << str)
- #define CAT_ERROR_MSG(str) ERROR_MSG("<" CAT_NAME "> " << str)
- #define SYS_ERROR_MSG(str) ERROR_MSG(str << ": " << strerror(errno))
- #define COMP_SYS_ERROR_MSG(str) SYS_ERROR_MSG("<" << comp_name << "> " << str)
- #define CAT_SYS_ERROR_MSG(str) SYS_ERROR_MSG("<" CAT_NAME "> " << str)
- #define WARN_MSG(str) PRINT_MSG(LOG_LEVEL_WARN, str)
- #define COMP_WARN_MSG(str) WARN_MSG("<" << comp_name << "> :" << str)
- #define CAT_WARN_MSG(str) WARN_MSG("<" CAT_NAME "> " << str)
- #define DEBUG_MSG(str) PRINT_MSG(LOG_LEVEL_DEBUG, str)
- #define COMP_DEBUG_MSG(str) DEBUG_MSG("<" << comp_name << "> :" << str)
- #define CAT_DEBUG_MSG(str) DEBUG_MSG("<" CAT_NAME "> " << str)
- #endif
|