Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 14de4106 in mainline


Ignore:
Timestamp:
2012-07-17T06:14:58Z (10 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
76d92db1
Parents:
3ab9de0
Message:

Speed-up logging when not recorded

Location:
uspace/lib/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/log.c

    r3ab9de0 r14de4106  
    194194}
    195195
     196bool __log_shall_record(log_level_t level)
     197{
     198        return get_current_observed_level() >= level;
     199}
     200
    196201/** Write an entry to the log.
    197202 *
     
    201206 * @param fmt           Format string (no traling newline).
    202207 */
    203 void log_msg(log_level_t level, const char *fmt, ...)
     208void __log_msg(log_level_t level, const char *fmt, ...)
    204209{
    205210        va_list args;
    206211
    207212        va_start(args, fmt);
    208         log_msgv(level, fmt, args);
     213        __log_msgv(level, fmt, args);
    209214        va_end(args);
    210215}
     
    217222 * @param fmt           Format string (no trailing newline)
    218223 */
    219 void log_msgv(log_level_t level, const char *fmt, va_list args)
     224void __log_msgv(log_level_t level, const char *fmt, va_list args)
    220225{
    221226        assert(level < LVL_LIMIT);
  • uspace/lib/c/include/io/log.h

    r3ab9de0 r14de4106  
    3636
    3737#include <stdarg.h>
     38#include <bool.h>
    3839
    3940typedef enum {
     
    4950} log_level_t;
    5051
     52extern bool __log_shall_record(log_level_t);
    5153extern int log_init(const char *, log_level_t);
    52 extern void log_msg(log_level_t, const char *, ...);
    53 extern void log_msgv(log_level_t, const char *, va_list);
     54
     55#define log_msg(level, format, ...) \
     56        do { \
     57                if (__log_shall_record((level))) { \
     58                        __log_msg(level, format, ##__VA_ARGS__); \
     59                } \
     60        } while (false)
     61
     62#define log_msgv(level, format, args) \
     63        do { \
     64                if (__log_shall_record((level))) { \
     65                        __log_msgv(level, format, args); \
     66                } \
     67        } while (false)
     68
     69extern void __log_msg(log_level_t, const char *, ...);
     70extern void __log_msgv(log_level_t, const char *, va_list);
    5471
    5572#endif
Note: See TracChangeset for help on using the changeset viewer.