Changeset bbc7d83e in mainline for uspace/lib/usb/src/debug.c
- Timestamp:
- 2011-02-01T21:59:43Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a4a8cca
- Parents:
- 0a37e14 (diff), ec293a8 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/debug.c
r0a37e14 rbbc7d83e 1 1 /* 2 * Copyright (c) 2010 Vojtech Horky2 * Copyright (c) 2010-2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 61 61 static FIBRIL_MUTEX_INITIALIZE(tag_list_guard); 62 62 63 /** Level of logging messages. */ 64 static usb_log_level_t log_level = USB_LOG_LEVEL_WARNING; 65 /** Prefix for logging messages. */ 66 static const char *log_prefix = "usb"; 67 /** Serialization mutex for logging functions. */ 68 static FIBRIL_MUTEX_INITIALIZE(log_serializer); 69 63 70 /** Find or create new tag with given name. 64 71 * … … 155 162 } 156 163 164 /** Enable logging. 165 * 166 * @param level Maximal enabled level (including this one). 167 * @param message_prefix Prefix for each printed message. 168 */ 169 void usb_log_enable(usb_log_level_t level, const char *message_prefix) 170 { 171 log_prefix = message_prefix; 172 log_level = level; 173 } 174 175 176 static const char *log_level_name(usb_log_level_t level) 177 { 178 switch (level) { 179 case USB_LOG_LEVEL_FATAL: 180 return " FATAL"; 181 case USB_LOG_LEVEL_ERROR: 182 return " ERROR"; 183 case USB_LOG_LEVEL_WARNING: 184 return " WARN"; 185 case USB_LOG_LEVEL_INFO: 186 return " info"; 187 default: 188 return ""; 189 } 190 } 191 192 /** Print logging message. 193 * 194 * @param level Verbosity level of the message. 195 * @param format Formatting directive. 196 */ 197 void usb_log_printf(usb_log_level_t level, const char *format, ...) 198 { 199 if (level > log_level) { 200 return; 201 } 202 203 FILE *stream = NULL; 204 switch (level) { 205 case USB_LOG_LEVEL_FATAL: 206 case USB_LOG_LEVEL_ERROR: 207 stream = stderr; 208 break; 209 default: 210 stream = stdout; 211 break; 212 } 213 assert(stream != NULL); 214 215 va_list args; 216 va_start(args, format); 217 218 fibril_mutex_lock(&log_serializer); 219 fprintf(stream, "[%s]%s: ", log_prefix, log_level_name(level)); 220 vfprintf(stream, format, args); 221 fibril_mutex_unlock(&log_serializer); 222 223 va_end(args); 224 } 157 225 158 226 /**
Note:
See TracChangeset
for help on using the changeset viewer.