2017-06-20 09:51:42 +00:00
|
|
|
/*
|
2017-06-10 12:35:39 +00:00
|
|
|
* Copyright (c) 2017, Inria.
|
2017-06-20 09:51:42 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Header file for the logging system
|
|
|
|
* \author
|
2017-06-10 12:35:39 +00:00
|
|
|
* Simon Duquennoy <simon.duquennoy@inria.fr>
|
2017-06-20 09:51:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \addtogroup sys
|
|
|
|
* @{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup log Per-module, per-level logging
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* The log module performs per-module, per-level logging
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LOG_H__
|
|
|
|
#define __LOG_H__
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "net/linkaddr.h"
|
|
|
|
#include "sys/log-conf.h"
|
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2017-09-22 13:06:44 +00:00
|
|
|
#include "net/ipv6/uip.h"
|
2017-06-20 09:51:42 +00:00
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
|
|
|
|
2017-06-26 12:24:47 +00:00
|
|
|
/* The different log levels available */
|
2017-06-20 09:51:42 +00:00
|
|
|
#define LOG_LEVEL_NONE 0 /* No log */
|
|
|
|
#define LOG_LEVEL_ERR 1 /* Errors */
|
|
|
|
#define LOG_LEVEL_WARN 2 /* Warnings */
|
|
|
|
#define LOG_LEVEL_INFO 3 /* Basic info */
|
2017-06-20 16:26:31 +00:00
|
|
|
#define LOG_LEVEL_DBG 4 /* Detailled debug */
|
2017-06-20 09:51:42 +00:00
|
|
|
|
2017-07-15 13:19:09 +00:00
|
|
|
/* Per-module log level */
|
|
|
|
|
|
|
|
struct log_module {
|
|
|
|
const char *name;
|
|
|
|
int *curr_log_level;
|
|
|
|
int max_log_level;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern int curr_log_level_rpl;
|
|
|
|
extern int curr_log_level_tcpip;
|
|
|
|
extern int curr_log_level_ipv6;
|
|
|
|
extern int curr_log_level_6lowpan;
|
2017-09-15 15:31:45 +00:00
|
|
|
extern int curr_log_level_nullnet;
|
2017-07-15 13:19:09 +00:00
|
|
|
extern int curr_log_level_mac;
|
|
|
|
extern int curr_log_level_framer;
|
2017-07-11 15:26:40 +00:00
|
|
|
extern int curr_log_level_6top;
|
2017-07-15 13:19:09 +00:00
|
|
|
|
|
|
|
extern struct log_module all_modules[];
|
|
|
|
|
|
|
|
#define LOG_LEVEL_RPL MIN((LOG_CONF_LEVEL_RPL), curr_log_level_rpl)
|
|
|
|
#define LOG_LEVEL_TCPIP MIN((LOG_CONF_LEVEL_TCPIP), curr_log_level_tcpip)
|
|
|
|
#define LOG_LEVEL_IPV6 MIN((LOG_CONF_LEVEL_IPV6), curr_log_level_ipv6)
|
|
|
|
#define LOG_LEVEL_6LOWPAN MIN((LOG_CONF_LEVEL_6LOWPAN), curr_log_level_6lowpan)
|
2017-09-15 15:31:45 +00:00
|
|
|
#define LOG_LEVEL_NULLNET MIN((LOG_CONF_LEVEL_NULLNET), curr_log_level_nullnet)
|
2017-07-15 13:19:09 +00:00
|
|
|
#define LOG_LEVEL_MAC MIN((LOG_CONF_LEVEL_MAC), curr_log_level_mac)
|
|
|
|
#define LOG_LEVEL_FRAMER MIN((LOG_CONF_LEVEL_FRAMER), curr_log_level_framer)
|
2017-07-11 15:26:40 +00:00
|
|
|
#define LOG_LEVEL_6TOP MIN((LOG_CONF_LEVEL_6TOP), curr_log_level_6top)
|
2017-07-15 13:19:09 +00:00
|
|
|
|
2017-06-20 09:51:42 +00:00
|
|
|
/* Main log function */
|
2017-06-26 12:24:47 +00:00
|
|
|
|
2017-06-23 19:12:36 +00:00
|
|
|
#define LOG(newline, level, levelstr, ...) do { \
|
2017-07-15 13:19:09 +00:00
|
|
|
if(level <= (LOG_LEVEL)) { \
|
2017-06-23 07:21:31 +00:00
|
|
|
if(newline) { \
|
2017-06-23 19:12:36 +00:00
|
|
|
LOG_OUTPUT("[%-4s: %-10s] ", levelstr, LOG_MODULE); \
|
2017-06-23 07:21:31 +00:00
|
|
|
if(LOG_WITH_LOC) { \
|
2017-06-23 19:12:36 +00:00
|
|
|
LOG_OUTPUT("[%s: %d] ", __FILE__, __LINE__); \
|
2017-06-23 07:21:31 +00:00
|
|
|
} \
|
2017-06-20 09:51:42 +00:00
|
|
|
} \
|
|
|
|
LOG_OUTPUT(__VA_ARGS__); \
|
|
|
|
} \
|
2017-06-23 07:21:31 +00:00
|
|
|
} while (0)
|
2017-06-20 09:51:42 +00:00
|
|
|
|
|
|
|
/* For Cooja annotations */
|
|
|
|
#define LOG_ANNOTATE(...) do { \
|
2017-06-21 15:14:05 +00:00
|
|
|
if(LOG_WITH_ANNOTATE) { \
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_OUTPUT(__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* Link-layer address */
|
|
|
|
#define LOG_LLADDR(level, lladdr) do { \
|
2017-07-15 13:19:09 +00:00
|
|
|
if(level <= (LOG_LEVEL)) { \
|
2017-06-23 19:12:36 +00:00
|
|
|
if(LOG_WITH_COMPACT_ADDR) { \
|
|
|
|
log_lladdr_compact(lladdr); \
|
|
|
|
} else { \
|
2017-06-26 12:24:47 +00:00
|
|
|
log_lladdr(lladdr); \
|
2017-06-23 19:12:36 +00:00
|
|
|
} \
|
2017-06-20 09:51:42 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* IPv6 address */
|
2017-06-23 19:12:36 +00:00
|
|
|
#define LOG_6ADDR(level, ipaddr) do { \
|
2017-07-15 13:19:09 +00:00
|
|
|
if(level <= (LOG_LEVEL)) { \
|
2017-06-23 19:12:36 +00:00
|
|
|
if(LOG_WITH_COMPACT_ADDR) { \
|
|
|
|
log_6addr_compact(ipaddr); \
|
|
|
|
} else { \
|
2017-06-26 12:24:47 +00:00
|
|
|
log_6addr(ipaddr); \
|
2017-06-23 19:12:36 +00:00
|
|
|
} \
|
2017-06-20 09:51:42 +00:00
|
|
|
} \
|
2017-06-23 19:12:36 +00:00
|
|
|
} while (0)
|
2017-06-20 09:51:42 +00:00
|
|
|
|
|
|
|
/* More compact versions of LOG macros */
|
2017-06-23 19:12:36 +00:00
|
|
|
#define LOG_ERR(...) LOG(1, LOG_LEVEL_ERR, "ERR", __VA_ARGS__)
|
|
|
|
#define LOG_WARN(...) LOG(1, LOG_LEVEL_WARN, "WARN", __VA_ARGS__)
|
|
|
|
#define LOG_INFO(...) LOG(1, LOG_LEVEL_INFO, "INFO", __VA_ARGS__)
|
|
|
|
#define LOG_DBG(...) LOG(1, LOG_LEVEL_DBG, "DBG", __VA_ARGS__)
|
|
|
|
|
|
|
|
#define LOG_ERR_(...) LOG(0, LOG_LEVEL_ERR, "ERR", __VA_ARGS__)
|
|
|
|
#define LOG_WARN_(...) LOG(0, LOG_LEVEL_WARN, "WARN", __VA_ARGS__)
|
|
|
|
#define LOG_INFO_(...) LOG(0, LOG_LEVEL_INFO, "INFO", __VA_ARGS__)
|
|
|
|
#define LOG_DBG_(...) LOG(0, LOG_LEVEL_DBG, "DBG", __VA_ARGS__)
|
2017-06-20 09:51:42 +00:00
|
|
|
|
|
|
|
#define LOG_ERR_LLADDR(...) LOG_LLADDR(LOG_LEVEL_ERR, __VA_ARGS__)
|
|
|
|
#define LOG_WARN_LLADDR(...) LOG_LLADDR(LOG_LEVEL_WARN, __VA_ARGS__)
|
|
|
|
#define LOG_INFO_LLADDR(...) LOG_LLADDR(LOG_LEVEL_INFO, __VA_ARGS__)
|
2017-06-20 16:26:31 +00:00
|
|
|
#define LOG_DBG_LLADDR(...) LOG_LLADDR(LOG_LEVEL_DBG, __VA_ARGS__)
|
2017-06-20 09:51:42 +00:00
|
|
|
|
|
|
|
#define LOG_ERR_6ADDR(...) LOG_6ADDR(LOG_LEVEL_ERR, __VA_ARGS__)
|
|
|
|
#define LOG_WARN_6ADDR(...) LOG_6ADDR(LOG_LEVEL_WARN, __VA_ARGS__)
|
|
|
|
#define LOG_INFO_6ADDR(...) LOG_6ADDR(LOG_LEVEL_INFO, __VA_ARGS__)
|
2017-06-20 16:26:31 +00:00
|
|
|
#define LOG_DBG_6ADDR(...) LOG_6ADDR(LOG_LEVEL_DBG, __VA_ARGS__)
|
2017-06-20 09:51:42 +00:00
|
|
|
|
|
|
|
/* For testing log level */
|
2017-07-06 17:43:44 +00:00
|
|
|
#define LOG_ERR_ENABLED (MIN(LOG_LEVEL, curr_log_level) >= LOG_LEVEL_ERR)
|
|
|
|
#define LOG_WARN_ENABLED (MIN(LOG_LEVEL, curr_log_level) >= LOG_LEVEL_WARN)
|
|
|
|
#define LOG_INFO_ENABLED (MIN(LOG_LEVEL, curr_log_level) >= LOG_LEVEL_INFO)
|
|
|
|
#define LOG_DBG_ENABLED (MIN(LOG_LEVEL, curr_log_level) >= LOG_LEVEL_DBG)
|
|
|
|
|
2017-06-26 12:24:47 +00:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs an IPv6 address
|
|
|
|
* \param ipaddr The IPv6 address
|
|
|
|
*/
|
|
|
|
void log_6addr(const uip_ipaddr_t *ipaddr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs an IPv6 address with a compact format
|
|
|
|
* \param ipaddr The IPv6 address
|
|
|
|
*/
|
|
|
|
void log_6addr_compact(const uip_ipaddr_t *ipaddr);
|
|
|
|
|
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs a link-layer address
|
|
|
|
* \param lladdr The link-layer address
|
|
|
|
*/
|
|
|
|
void log_lladdr(const linkaddr_t *lladdr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs a link-layer address with a compact format
|
|
|
|
* \param lladdr The link-layer address
|
|
|
|
*/
|
|
|
|
void log_lladdr_compact(const linkaddr_t *lladdr);
|
|
|
|
|
2017-07-06 17:43:44 +00:00
|
|
|
/**
|
|
|
|
* Sets a log level at run-time. Logs are included in the firmware via
|
|
|
|
* the compile-time flags in log-conf.h, but this allows to force lower log
|
|
|
|
* levels, system-wide.
|
2017-07-15 13:19:09 +00:00
|
|
|
* \param module The target module string descriptor
|
2017-07-06 17:43:44 +00:00
|
|
|
* \param level The log level
|
|
|
|
*/
|
2017-07-15 13:19:09 +00:00
|
|
|
void log_set_level(const char *module, int level);
|
2017-07-06 17:43:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current log level.
|
2017-07-15 13:19:09 +00:00
|
|
|
* \param module The target module string descriptor
|
2017-07-06 17:43:44 +00:00
|
|
|
* \return The current log level
|
|
|
|
*/
|
2017-07-15 13:19:09 +00:00
|
|
|
int log_get_level(const char *module);
|
2017-07-06 17:43:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a textual description of a log level
|
|
|
|
* \param level log level
|
|
|
|
* \return The textual description
|
|
|
|
*/
|
|
|
|
const char *log_level_to_str(int level);
|
|
|
|
|
2017-06-20 09:51:42 +00:00
|
|
|
#endif /* __LOG_H__ */
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
/** @} */
|