Changeset aa389fd in mainline for uspace/lib/usb/src/debug.c


Ignore:
Timestamp:
2011-02-02T12:01:29Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9f5667a
Parents:
93f8da1
Message:

USB logging goes into file as well

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/debug.c

    r93f8da1 raa389fd  
    6767/** Serialization mutex for logging functions. */
    6868static FIBRIL_MUTEX_INITIALIZE(log_serializer);
     69static FILE *log_stream = NULL;
    6970
    7071/** Find or create new tag with given name.
     
    171172        log_prefix = message_prefix;
    172173        log_level = level;
     174        if (log_stream == NULL) {
     175                char *fname;
     176                int rc = asprintf(&fname, "/log/%s", message_prefix);
     177                if (rc > 0) {
     178                        log_stream = fopen(fname, "w");
     179                        free(fname);
     180                }
     181        }
    173182}
    174183
     
    197206void usb_log_printf(usb_log_level_t level, const char *format, ...)
    198207{
    199         if (level > log_level) {
    200                 return;
    201         }
    202 
    203208        FILE *stream = NULL;
    204209        switch (level) {
     
    216221        va_start(args, format);
    217222
     223        /*
     224         * Serialize access to log files.
     225         * Always print to log file, to screen print only when the enabled
     226         * log level is high enough.
     227         */
    218228        fibril_mutex_lock(&log_serializer);
    219         fprintf(stream, "[%s]%s: ", log_prefix, log_level_name(level));
    220         vfprintf(stream, format, args);
     229
     230        const char *level_name = log_level_name(level);
     231
     232        if (log_stream != NULL) {
     233                fprintf(log_stream, "[%s]%s: ", log_prefix, level_name);
     234                vfprintf(log_stream, format, args);
     235        }
     236
     237        if (level <= log_level) {
     238                fprintf(stream, "[%s]%s: ", log_prefix, level_name);
     239                vfprintf(stream, format, args);
     240        }
     241
    221242        fibril_mutex_unlock(&log_serializer);
    222243
Note: See TracChangeset for help on using the changeset viewer.