Changeset 6028ec8 in mainline
- Timestamp:
- 2011-02-01T11:28:09Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0b31409
- Parents:
- 632ed68
- Location:
- uspace/lib/usb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/debug.h
r632ed68 r6028ec8 1 1 /* 2 * Copyright (c) 2010 Vojtech Horky2 * Copyright (c) 2010-2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 37 37 #include <stdio.h> 38 38 #include <usb/usb.h> 39 #include <assert.h> 39 40 40 41 void usb_dprintf(const char *tag, int level, const char *format, ...); … … 44 45 const uint8_t *, size_t); 45 46 47 /** Logging level. */ 48 typedef enum { 49 USB_LOG_LEVEL_FATAL, 50 USB_LOG_LEVEL_ERROR, 51 USB_LOG_LEVEL_WARNING, 52 USB_LOG_LEVEL_INFO, 53 USB_LOG_LEVEL_DEBUG, 54 USB_LOG_LEVEL_DEBUG2 55 } usb_log_level_t; 56 57 58 void usb_log_enable(usb_log_level_t, const char *); 59 60 void usb_log_printf(usb_log_level_t, const char *, ...); 61 62 #define usb_log_fatal(format, ...) \ 63 usb_log_printf(USB_LOG_LEVEL_FATAL, format, ##__VA_ARGS__) 64 65 #define usb_log_error(format, ...) \ 66 usb_log_printf(USB_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) 67 68 #define usb_log_warning(format, ...) \ 69 usb_log_printf(USB_LOG_LEVEL_WARNING, format, ##__VA_ARGS__) 70 71 #define usb_log_info(format, ...) \ 72 usb_log_printf(USB_LOG_LEVEL_INFO, format, ##__VA_ARGS__) 73 74 #define usb_log_debug(format, ...) \ 75 usb_log_printf(USB_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) 76 77 #define usb_log_debug2(format, ...) \ 78 usb_log_printf(USB_LOG_LEVEL_DEBUG2, format, ##__VA_ARGS__) 79 80 81 46 82 #endif 47 83 /** -
uspace/lib/usb/src/debug.c
r632ed68 r6028ec8 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.