Skip to content

Commit

Permalink
RFC: log API
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Mar 4, 2015
1 parent a03d993 commit d8a7588
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 58 deletions.
1 change: 1 addition & 0 deletions Makefile.pseudomodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PSEUDOMODULES += defaulttransceiver
PSEUDOMODULES += transport_layer
PSEUDOMODULES += pktqueue
PSEUDOMODULES += log_printfnoformat
71 changes: 71 additions & 0 deletions core/include/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2015 Kaspar Schleiser
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @addtogroup core_util
* @{
*
* @file log.h
* @brief System logging header
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/

#ifndef __LOG_H
#define __LOG_H

#ifdef __cplusplus
extern "C" {
#endif

enum {
LOG_NONE,
LOG_ERROR,
LOG_WARNING,
LOG_INFO,
LOG_DEBUG,
LOG_ALL
};

#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_ALL
#endif

/**
* @brief Log message if level <= LOG_LEVEL
*
* ... doc to come ...
*
* @{
*/

#define LOG(level, ...) if (level <= LOG_LEVEL) _log(level, __VA_ARGS__)

/** @} */

#ifdef HAVE_LOG_MODULE
#include "log_module.h"
#else

#include <stdio.h>

#define _log(level, ...) printf(__VA_ARGS__)

#define log_error(...) LOG(LOG_ERROR, __VA_ARGS__)
#define log_warning(...) LOG(LOG_WARNING, __VA_ARGS__)
#define log_info(...) LOG(LOG_INFO, __VA_ARGS__)
#define log_debug(...) LOG(LOG_DEBUG, __VA_ARGS__)

#endif

#ifdef __cplusplus
}
#endif

#endif /* __LOG_H */
/** @} */
10 changes: 5 additions & 5 deletions core/kernel_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* @}
*/

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
Expand All @@ -32,6 +31,7 @@
#include "thread.h"
#include "hwtimer.h"
#include "irq.h"
#include "log.h"

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand Down Expand Up @@ -82,19 +82,19 @@ static char idle_stack[KERNEL_CONF_STACKSIZE_IDLE];
void kernel_init(void)
{
(void) disableIRQ();
printf("kernel_init(): This is RIOT! (Version: %s)\n", RIOT_VERSION);
log_info("kernel_init(): This is RIOT! (Version: %s)\n", RIOT_VERSION);

hwtimer_init();

if (thread_create(idle_stack, sizeof(idle_stack), PRIORITY_IDLE, CREATE_WOUT_YIELD | CREATE_STACKTEST, idle_thread, NULL, idle_name) < 0) {
printf("kernel_init(): error creating idle task.\n");
log_error("kernel_init(): error creating idle task.\n");
}

if (thread_create(main_stack, sizeof(main_stack), PRIORITY_MAIN, CREATE_WOUT_YIELD | CREATE_STACKTEST, main_trampoline, NULL, main_name) < 0) {
printf("kernel_init(): error creating main task.\n");
log_error("kernel_init(): error creating main task.\n");
}

printf("kernel_init(): jumping into first task...\n");
log_info("kernel_init(): jumping into first task...\n");

cpu_switch_context_exit();
}
3 changes: 0 additions & 3 deletions sys/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
ifneq (,$(filter log_printfnoformat,$(USEMODULE)))
DIRS += log/log_printfnoformat
endif
ifneq (,$(filter pnet,$(USEMODULE)))
DIRS += posix/pnet
endif
Expand Down
5 changes: 5 additions & 0 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ ifneq (,$(filter embunit,$(USEMODULE)))
CFLAGS += -DOUTPUT=OUTPUT_COMPILER
endif
endif

ifneq (,$(filter log_printfnoformat,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/log/log_printfnoformat
CFLAGS += -DHAVE_LOG_MODULE
endif
1 change: 0 additions & 1 deletion sys/log/log_printfnoformat/Makefile

This file was deleted.

16 changes: 16 additions & 0 deletions sys/log/log_printfnoformat/log_module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __LOG_FORMAT_H
#define __LOG_FORMAT_H

#include <stdio.h>

static void _log(unsigned level, const char *format, ...) {
(void)level;
puts(format);
}

#define log_error(...) LOG(LOG_ERROR, "E: " __VA_ARGS__)
#define log_warning(...) LOG(LOG_WARNING, "W: " __VA_ARGS__)
#define log_info(...) LOG(LOG_INFO, "I: " __VA_ARGS__)
#define log_debug(...) LOG(LOG_DEBUG, "D: " __VA_ARGS__)

#endif /* __LOG_FORMAT_H */
49 changes: 0 additions & 49 deletions sys/log/log_printfnoformat/log_printfnoformat.c

This file was deleted.

0 comments on commit d8a7588

Please sign in to comment.