Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset f039dba in mainline for uspace/lib/c/generic/io/log.c


Ignore:
Timestamp:
2012-08-17T09:57:27Z (9 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
b1912b0c
Parents:
f72ae3b
Message:

Logger also works with hierarchy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/log.c

    rf72ae3b rf039dba  
    4343#include <ns.h>
    4444
    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;
     45static sysarg_t default_log_id;
    5846
    5947/** Log messages are printed under this name. */
     
    8573
    8674        ipc_call_t answer;
    87         aid_t reg_msg = async_send_0(exchange, LOGGER_WRITER_CREATE_TOPLEVEL_LOG, &answer);
     75        aid_t reg_msg = async_send_1(exchange, LOGGER_WRITER_CREATE_LOG, LOG_NO_PARENT, &answer);
    8876        int rc = async_data_write_start(exchange, prog_name, str_size(prog_name));
    8977        sysarg_t reg_msg_rc;
     
    9987                return reg_msg_rc;
    10088
    101         default_top_log_id = IPC_GET_ARG1(answer);
    102         default_log.top_log_id = default_top_log_id;
     89        default_log_id = IPC_GET_ARG1(answer);
    10390
    10491        return EOK;
    10592}
    10693
    107 static int logger_message(async_sess_t *session, log_t ctx, log_level_t level, const char *message)
     94static int logger_message(async_sess_t *session, log_t log, log_level_t level, const char *message)
    10895{
    10996        async_exch_t *exchange = async_exchange_begin(session);
     
    11198                return ENOMEM;
    11299        }
    113         log_info_t *log_info = ctx != 0 ? (log_info_t *) ctx : &default_log;
    114 
    115         aid_t reg_msg = async_send_3(exchange, LOGGER_WRITER_MESSAGE,
    116             log_info->top_log_id, log_info->log_id, level, NULL);
     100        if (log == LOG_DEFAULT)
     101                log = default_log_id;
     102
     103        aid_t reg_msg = async_send_2(exchange, LOGGER_WRITER_MESSAGE,
     104            log, level, NULL);
    117105        int rc = async_data_write_start(exchange, message, str_size(message));
    118106        sysarg_t reg_msg_rc;
     
    206194log_t log_create(const char *name, log_t parent)
    207195{
    208         log_info_t *info = malloc(sizeof(log_info_t));
    209         if (info == NULL)
    210                 return LOG_DEFAULT;
    211         info->name = NULL;
    212 
    213         if (parent == LOG_DEFAULT) {
    214                 info->name = str_dup(name);
    215                 if (info->name == NULL)
    216                         goto error;
    217                 info->top_log_id = default_top_log_id;
    218         } else {
    219                 log_info_t *parent_info = (log_info_t *) parent;
    220                 int rc = asprintf(&info->name, "%s/%s",
    221                     parent_info->name, name);
    222                 if (rc < 0)
    223                         goto error;
    224                 info->top_log_id = parent_info->top_log_id;
    225         }
    226 
    227196        async_exch_t *exchange = async_exchange_begin(logger_session);
    228197        if (exchange == NULL)
    229                 goto error;
     198                return parent;
     199
     200        if (parent == LOG_DEFAULT)
     201                parent = default_log_id;
    230202
    231203        ipc_call_t answer;
    232         aid_t reg_msg = async_send_1(exchange, LOGGER_WRITER_CREATE_SUB_LOG,
    233             info->top_log_id, &answer);
    234         int rc = async_data_write_start(exchange, info->name, str_size(info->name));
     204        aid_t reg_msg = async_send_1(exchange, LOGGER_WRITER_CREATE_LOG,
     205            parent, &answer);
     206        int rc = async_data_write_start(exchange, name, str_size(name));
    235207        sysarg_t reg_msg_rc;
    236208        async_wait_for(reg_msg, &reg_msg_rc);
     
    239211
    240212        if ((rc != EOK) || (reg_msg_rc != EOK))
    241                 goto error;
    242 
    243         info->log_id = IPC_GET_ARG1(answer);
    244         return (sysarg_t) info;
    245 
    246 error:
    247         free(info->name);
    248         free(info);
    249         return parent;
     213                return parent;
     214
     215        return IPC_GET_ARG1(answer);
    250216}
    251217
Note: See TracChangeset for help on using the changeset viewer.