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


Ignore:
Timestamp:
2011-02-04T13:07:32Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
97e87de
Parents:
621afdb (diff), ff244e6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge devel branch

File:
1 edited

Legend:

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

    r621afdb r74d6e90  
    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.