Changes in uspace/lib/usb/src/debug.c [6028ec8:ef7f043] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/debug.c
r6028ec8 ref7f043 67 67 /** Serialization mutex for logging functions. */ 68 68 static FIBRIL_MUTEX_INITIALIZE(log_serializer); 69 static FILE *log_stream = NULL; 69 70 70 71 /** Find or create new tag with given name. … … 171 172 log_prefix = message_prefix; 172 173 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 } 173 182 } 174 183 … … 197 206 void usb_log_printf(usb_log_level_t level, const char *format, ...) 198 207 { 199 if (level > log_level) { 200 return; 201 } 202 203 FILE *stream = NULL; 208 FILE *screen_stream = NULL; 204 209 switch (level) { 205 210 case USB_LOG_LEVEL_FATAL: 206 211 case USB_LOG_LEVEL_ERROR: 207 s tream = stderr;212 screen_stream = stderr; 208 213 break; 209 214 default: 210 s tream = stdout;215 screen_stream = stdout; 211 216 break; 212 217 } 213 assert(s tream != NULL);218 assert(screen_stream != NULL); 214 219 215 220 va_list args; 216 va_start(args, format); 217 221 222 /* 223 * Serialize access to log files. 224 * Always print to log file, to screen print only when the enabled 225 * log level is high enough. 226 */ 218 227 fibril_mutex_lock(&log_serializer); 219 fprintf(stream, "[%s]%s: ", log_prefix, log_level_name(level)); 220 vfprintf(stream, format, args); 228 229 const char *level_name = log_level_name(level); 230 231 if (log_stream != NULL) { 232 va_start(args, format); 233 234 fprintf(log_stream, "[%s]%s: ", log_prefix, level_name); 235 vfprintf(log_stream, format, args); 236 fflush(log_stream); 237 238 va_end(args); 239 } 240 241 if (level <= log_level) { 242 va_start(args, format); 243 244 fprintf(screen_stream, "[%s]%s: ", log_prefix, level_name); 245 vfprintf(screen_stream, format, args); 246 fflush(screen_stream); 247 248 va_end(args); 249 } 250 221 251 fibril_mutex_unlock(&log_serializer); 222 223 va_end(args);224 252 } 225 253
Note:
See TracChangeset
for help on using the changeset viewer.