Changeset 2bf781a in mainline
- Timestamp:
- 2012-08-16T21:50:52Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f50a756
- Parents:
- cba45af
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/stdio/logger2.c
rcba45af r2bf781a 36 36 const char *test_logger2(void) 37 37 { 38 log_t log_alpha = log_create("alpha" );39 log_t log_bravo = log_create("bravo" );38 log_t log_alpha = log_create("alpha", LOG_DEFAULT); 39 log_t log_bravo = log_create("bravo", log_alpha); 40 40 41 TPRINTF("Alpha contextis %" PRIlogctx ".\n", log_alpha);42 TPRINTF("Bravo contextis %" PRIlogctx ".\n", log_bravo);41 TPRINTF("Alpha is %" PRIlogctx ".\n", log_alpha); 42 TPRINTF("Bravo is %" PRIlogctx ".\n", log_bravo); 43 43 44 44 while (true) { … … 54 54 (int) level, log_level_str(level)); 55 55 log_log_msg(log_bravo, level, 56 "Printing level %d (%s) into bravo log.",56 "Printing level %d (%s) into bravo sub-log.", 57 57 (int) level, log_level_str(level)); 58 58 async_usleep(1000 * 100); -
uspace/lib/c/generic/io/log.c
rcba45af r2bf781a 43 43 #include <ns.h> 44 44 45 typedef struct { 46 char *name; 47 sysarg_t top_log_id; 48 sysarg_t log_id; 49 } log_info_t; 50 51 static log_info_t default_log = { 52 .name = NULL, 53 .top_log_id = 0, 54 .log_id = 0 55 }; 56 57 static sysarg_t default_top_log_id; 58 45 59 /** Log messages are printed under this name. */ 46 60 static const char *log_prog_name; … … 62 76 #define MESSAGE_BUFFER_SIZE 4096 63 77 64 static sysarg_t toplog_id;65 78 66 79 static int logger_register(async_sess_t *session, const char *prog_name) … … 86 99 return reg_msg_rc; 87 100 88 toplog_id = IPC_GET_ARG1(answer); 101 default_top_log_id = IPC_GET_ARG1(answer); 102 default_log.top_log_id = default_top_log_id; 89 103 90 104 return EOK; … … 97 111 return ENOMEM; 98 112 } 113 log_info_t *log_info = ctx != 0 ? (log_info_t *) ctx : &default_log; 99 114 100 115 aid_t reg_msg = async_send_3(exchange, LOGGER_WRITER_MESSAGE, 101 toplog_id, ctx, level, NULL);116 log_info->top_log_id, log_info->log_id, level, NULL); 102 117 int rc = async_data_write_start(exchange, message, str_size(message)); 103 118 sysarg_t reg_msg_rc; … … 184 199 * This function always returns a valid context. 185 200 */ 186 log_t log_create(const char *name) 187 { 201 log_t log_create(const char *name, log_t parent) 202 { 203 log_info_t *info = malloc(sizeof(log_info_t)); 204 if (info == NULL) 205 return LOG_DEFAULT; 206 207 if (parent == LOG_DEFAULT) { 208 info->name = str_dup(name); 209 if (info->name == NULL) { 210 free(info); 211 return LOG_DEFAULT; 212 } 213 info->top_log_id = default_top_log_id; 214 } else { 215 log_info_t *parent_info = (log_info_t *) parent; 216 int rc = asprintf(&info->name, "%s/%s", 217 parent_info->name, name); 218 if (rc < 0) { 219 free(info); 220 return LOG_DEFAULT; 221 } 222 info->top_log_id = parent_info->top_log_id; 223 } 224 188 225 async_exch_t *exchange = async_exchange_begin(logger_session); 189 226 if (exchange == NULL) 190 return LOG_DEFAULT;227 goto error; 191 228 192 229 ipc_call_t answer; 193 aid_t reg_msg = async_send_1(exchange, LOGGER_WRITER_CREATE_SUB_LOG, toplog_id, &answer); 194 int rc = async_data_write_start(exchange, name, str_size(name)); 230 aid_t reg_msg = async_send_1(exchange, LOGGER_WRITER_CREATE_SUB_LOG, 231 info->top_log_id, &answer); 232 int rc = async_data_write_start(exchange, info->name, str_size(info->name)); 195 233 sysarg_t reg_msg_rc; 196 234 async_wait_for(reg_msg, ®_msg_rc); … … 199 237 200 238 if ((rc != EOK) || (reg_msg_rc != EOK)) 201 return LOG_DEFAULT; 202 203 return IPC_GET_ARG1(answer); 239 goto error; 240 241 info->log_id = IPC_GET_ARG1(answer); 242 return (sysarg_t) info; 243 244 error: 245 free(info->name); 246 free(info); 247 return LOG_DEFAULT; 204 248 } 205 249 -
uspace/lib/c/include/io/log.h
rcba45af r2bf781a 59 59 60 60 extern int log_init(const char *, log_level_t); 61 62 extern log_t log_create(const char *); 61 extern log_t log_create(const char *, log_t); 63 62 64 63 #define log_msg(level, format, ...) \
Note:
See TracChangeset
for help on using the changeset viewer.