Changeset 1f2dd20 in mainline


Ignore:
Timestamp:
2012-07-04T12:57:00Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f47c70d4
Parents:
5e4f22b
Message:

Start working on logger service

The logger service is started as an init task and log_msg functions
sends messages to it.

Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • boot/Makefile.common

    r5e4f22b r1f2dd20  
    7474        $(USPACE_PATH)/srv/locsrv/locsrv \
    7575        $(USPACE_PATH)/srv/bd/rd/rd \
    76         $(USPACE_PATH)/srv/vfs/vfs
     76        $(USPACE_PATH)/srv/vfs/vfs \
     77        $(USPACE_PATH)/srv/logger/logger
    7778
    7879ifeq ($(RDFMT),tmpfs)
  • uspace/Makefile

    r5e4f22b r1f2dd20  
    7474        srv/clipboard \
    7575        srv/locsrv \
     76        srv/logger \
    7677        srv/devman \
    7778        srv/loader \
  • uspace/lib/c/generic/io/log.c

    r5e4f22b r1f2dd20  
    3838#include <stdlib.h>
    3939#include <stdio.h>
     40#include <async.h>
     41#include <io/log.h>
     42#include <ipc/logger.h>
     43#include <ns.h>
    4044
    41 #include <io/log.h>
    42 
    43 /** Serialization mutex for logging functions. */
    44 static FIBRIL_MUTEX_INITIALIZE(log_serializer);
    45 
    46 /** Current log level. */
    47 static log_level_t log_level;
    48 
    49 static FILE *log_stream;
    50 
     45/** Log messages are printed under this name. */
    5146static const char *log_prog_name;
    5247
    53 /** Prefixes for individual logging levels. */
    54 static const char *log_level_names[] = {
    55         [LVL_FATAL] = "Fatal error",
    56         [LVL_ERROR] = "Error",
    57         [LVL_WARN] = "Warning",
    58         [LVL_NOTE] = "Note",
    59         [LVL_DEBUG] = "Debug",
    60         [LVL_DEBUG2] = "Debug2"
    61 };
     48/** IPC session with the logger service. */
     49static async_sess_t *logger_session;
     50
     51/** Maximum length of a single log message (in bytes). */
     52#define MESSAGE_BUFFER_SIZE 4096
     53
     54static int logger_register(async_sess_t *session, const char *prog_name)
     55{
     56        async_exch_t *exchange = async_exchange_begin(session);
     57        if (exchange == NULL) {
     58                return ENOMEM;
     59        }
     60
     61        aid_t reg_msg = async_send_0(exchange, LOGGER_REGISTER, NULL);
     62        int rc = async_data_write_start(exchange, prog_name, str_size(prog_name));
     63        sysarg_t reg_msg_rc;
     64        async_wait_for(reg_msg, &reg_msg_rc);
     65
     66        async_exchange_end(exchange);
     67
     68        if (rc != EOK) {
     69                return rc;
     70        }
     71
     72        return reg_msg_rc;
     73}
     74
     75static int logger_message(async_sess_t *session, log_level_t level, const char *message)
     76{
     77        async_exch_t *exchange = async_exchange_begin(session);
     78        if (exchange == NULL) {
     79                return ENOMEM;
     80        }
     81
     82        aid_t reg_msg = async_send_1(exchange, LOGGER_MESSAGE, level, NULL);
     83        int rc = async_data_write_start(exchange, message, str_size(message));
     84        sysarg_t reg_msg_rc;
     85        async_wait_for(reg_msg, &reg_msg_rc);
     86
     87        async_exchange_end(exchange);
     88
     89        if (rc != EOK) {
     90                return rc;
     91        }
     92
     93        return reg_msg_rc;
     94}
    6295
    6396/** Initialize the logging system.
     
    69102{
    70103        assert(level < LVL_LIMIT);
    71         log_level = level;
    72104
    73         log_stream = stdout;
    74105        log_prog_name = str_dup(prog_name);
    75106        if (log_prog_name == NULL)
    76107                return ENOMEM;
    77108
    78         return EOK;
     109        logger_session = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOGGER, LOGGER_INTERFACE_SINK, 0);
     110        if (logger_session == NULL) {
     111                return ENOMEM;
     112        }
     113
     114        int rc = logger_register(logger_session, log_prog_name);
     115
     116        return rc;
    79117}
    80118
     
    106144        assert(level < LVL_LIMIT);
    107145
    108         /* Higher number means higher verbosity. */
    109         if (level <= log_level) {
    110                 fibril_mutex_lock(&log_serializer);
     146        char *message_buffer = malloc(MESSAGE_BUFFER_SIZE);
     147        if (message_buffer == NULL) {
     148                return;
     149        }
    111150
    112                 fprintf(log_stream, "%s: %s: ", log_prog_name,
    113                     log_level_names[level]);
    114                 vfprintf(log_stream, fmt, args);
    115                 fputc('\n', log_stream);
    116                 fflush(log_stream);
    117 
    118                 fibril_mutex_unlock(&log_serializer);
    119         }
     151        vsnprintf(message_buffer, MESSAGE_BUFFER_SIZE, fmt, args);
     152        logger_message(logger_session, level, message_buffer);
    120153}
    121154
  • uspace/lib/c/include/ipc/services.h

    r5e4f22b r1f2dd20  
    4545        SERVICE_VFS        = FOURCC('v', 'f', 's', ' '),
    4646        SERVICE_LOC        = FOURCC('l', 'o', 'c', ' '),
     47        SERVICE_LOGGER     = FOURCC('l', 'o', 'g', 'g'),
    4748        SERVICE_DEVMAN     = FOURCC('d', 'e', 'v', 'n'),
    4849        SERVICE_IRC        = FOURCC('i', 'r', 'c', ' '),
Note: See TracChangeset for help on using the changeset viewer.