project_files/frontlib/util/logging.h
changeset 7482 d70a5b0d1190
parent 7338 1ed603a54ebd
child 10017 de822cd3df3a
equal deleted inserted replaced
7479:c8c552ee3acb 7482:d70a5b0d1190
    37 char* flib_format_ip(uint32_t numip);
    37 char* flib_format_ip(uint32_t numip);
    38 
    38 
    39 /**
    39 /**
    40  * Evaluates the expression cond. If it is true, a formatted error will be logged.
    40  * Evaluates the expression cond. If it is true, a formatted error will be logged.
    41  * Returns true if an error is logged, false otherwise (i.e. the boolean value of the argument)
    41  * Returns true if an error is logged, false otherwise (i.e. the boolean value of the argument)
       
    42  * Usage: log_e_if(errorHasHappened, "Format string", formatArg, ...);
    42  */
    43  */
    43 #define log_e_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_ERROR, !(bool)(cond), __VA_ARGS__)
    44 #define log_e_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_ERROR, !(bool)(cond), __VA_ARGS__)
    44 #define log_w_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_WARNING, !(bool)(cond), __VA_ARGS__)
    45 #define log_w_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_WARNING, !(bool)(cond), __VA_ARGS__)
    45 
    46 
    46 /**
    47 /**
    77 #define flib_log_d(...) _flib_flog(__func__, FLIB_LOGLEVEL_DEBUG, __VA_ARGS__)
    78 #define flib_log_d(...) _flib_flog(__func__, FLIB_LOGLEVEL_DEBUG, __VA_ARGS__)
    78 
    79 
    79 bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...);
    80 bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...);
    80 void _flib_flog(const char *func, int level, const char *fmt, ...);
    81 void _flib_flog(const char *func, int level, const char *fmt, ...);
    81 
    82 
       
    83 /**
       
    84  * Only log messages that are at least the indicated level
       
    85  */
       
    86 void flib_log_setLevel(int level);
    82 int flib_log_getLevel();
    87 int flib_log_getLevel();
    83 void flib_log_setLevel(int level);
    88 
       
    89 /**
       
    90  * Log to the indicated file. You can pass NULL to log to stdout.
       
    91  * This overrides setCallback and vice versa.
       
    92  */
    84 void flib_log_setFile(FILE *logfile);
    93 void flib_log_setFile(FILE *logfile);
       
    94 
       
    95 /**
       
    96  * Returns whether messages of this level are logged at the moment.
       
    97  */
    85 bool flib_log_isActive(int level);
    98 bool flib_log_isActive(int level);
    86 
    99 
    87 /**
   100 /**
    88  * Allows logging through an arbitrary callback function. Useful for integrating into an
   101  * Allows logging through an arbitrary callback function. Useful for integrating into an
    89  * existing logging system. This overrides setFile and vice versa.
   102  * existing logging system. This overrides setFile and vice versa.