diff --git a/include/logging/sys_log.h b/include/logging/sys_log.h deleted file mode 100644 index 45b306356f4..00000000000 --- a/include/logging/sys_log.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** @file sys_log.h - * @brief Logging macros. - */ -#ifndef ZEPHYR_INCLUDE_LOGGING_SYS_LOG_H_ -#define ZEPHYR_INCLUDE_LOGGING_SYS_LOG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#define SYS_LOG_LEVEL_OFF 0 -#define SYS_LOG_LEVEL_ERROR 1 -#define SYS_LOG_LEVEL_WARNING 2 -#define SYS_LOG_LEVEL_INFO 3 -#define SYS_LOG_LEVEL_DEBUG 4 - -/* Determine this compile unit log level */ -#if !defined(SYS_LOG_LEVEL) -/* Use default */ -#define SYS_LOG_LEVEL CONFIG_SYS_LOG_DEFAULT_LEVEL -#elif (SYS_LOG_LEVEL < CONFIG_SYS_LOG_OVERRIDE_LEVEL) -/* Use override */ -#undef SYS_LOG_LEVEL -#define SYS_LOG_LEVEL CONFIG_SYS_LOG_OVERRIDE_LEVEL -#endif - -/** - * @brief System Log - * @defgroup system_log System Log - * @ingroup logging - * @{ - */ -#if defined(CONFIG_SYS_LOG) && (SYS_LOG_LEVEL > SYS_LOG_LEVEL_OFF) - -extern void (*syslog_hook)(const char *fmt, ...); -void syslog_hook_install(void (*hook)(const char *, ...)); - -/* decide print func */ -#if defined(CONFIG_SYS_LOG_EXT_HOOK) -#define SYS_LOG_BACKEND_FN syslog_hook -#else -#include -#define SYS_LOG_BACKEND_FN printk -#endif - -/* Should use color? */ -#if defined(CONFIG_SYS_LOG_SHOW_COLOR) -#define SYS_LOG_COLOR_OFF "\x1B[0m" -#define SYS_LOG_COLOR_RED "\x1B[0;31m" -#define SYS_LOG_COLOR_YELLOW "\x1B[0;33m" -#else -#define SYS_LOG_COLOR_OFF "" -#define SYS_LOG_COLOR_RED "" -#define SYS_LOG_COLOR_YELLOW "" -#endif /* CONFIG_SYS_LOG_SHOW_COLOR */ - -/* Should use log lv tags? */ -#if defined(CONFIG_SYS_LOG_SHOW_TAGS) -#define SYS_LOG_TAG_ERR " [ERR]" -#define SYS_LOG_TAG_WRN " [WRN]" -#define SYS_LOG_TAG_INF " [INF]" -#define SYS_LOG_TAG_DBG " [DBG]" -#else -#define SYS_LOG_TAG_ERR "" -#define SYS_LOG_TAG_WRN "" -#define SYS_LOG_TAG_INF "" -#define SYS_LOG_TAG_DBG "" -#endif /* CONFIG_SYS_LOG_SHOW_TAGS */ - -/* Log domain name */ -#if !defined(SYS_LOG_DOMAIN) -#define SYS_LOG_DOMAIN "general" -#endif /* SYS_LOG_DOMAIN */ - -/** - * @def SYS_LOG_NO_NEWLINE - * - * @brief Specifies whether SYS_LOG should add newline at the end of line - * or not. - * - * @details User can define SYS_LOG_NO_NEWLINE no prevent the header file - * from adding newline if the debug print already has a newline character. - */ -#if !defined(SYS_LOG_NO_NEWLINE) -#define SYS_LOG_NL "\n" -#else -#define SYS_LOG_NL "" -#endif - -/* [domain] [level] function: */ -#define LOG_LAYOUT "[%s]%s %s: %s" -#define LOG_BACKEND_CALL(log_lv, log_color, log_format, color_off, ...) \ - SYS_LOG_BACKEND_FN(LOG_LAYOUT log_format "%s" SYS_LOG_NL, \ - SYS_LOG_DOMAIN, log_lv, __func__, log_color, ##__VA_ARGS__, color_off) - -#define LOG_NO_COLOR(log_lv, log_format, ...) \ - LOG_BACKEND_CALL(log_lv, "", log_format, "", ##__VA_ARGS__) -#define LOG_COLOR(log_lv, log_color, log_format, ...) \ - LOG_BACKEND_CALL(log_lv, log_color, log_format, \ - SYS_LOG_COLOR_OFF, ##__VA_ARGS__) - -#define SYS_LOG_ERR(...) __DEPRECATED_MACRO \ - LOG_COLOR(SYS_LOG_TAG_ERR, SYS_LOG_COLOR_RED, ##__VA_ARGS__) - -#if (SYS_LOG_LEVEL >= SYS_LOG_LEVEL_WARNING) -#define SYS_LOG_WRN(...) __DEPRECATED_MACRO LOG_COLOR(SYS_LOG_TAG_WRN, \ - SYS_LOG_COLOR_YELLOW, ##__VA_ARGS__) -#endif - -#if (SYS_LOG_LEVEL >= SYS_LOG_LEVEL_INFO) -#define SYS_LOG_INF(...) __DEPRECATED_MACRO \ - LOG_NO_COLOR(SYS_LOG_TAG_INF, ##__VA_ARGS__) -#endif - -#if (SYS_LOG_LEVEL == SYS_LOG_LEVEL_DEBUG) -#define SYS_LOG_DBG(...) __DEPRECATED_MACRO \ - LOG_NO_COLOR(SYS_LOG_TAG_DBG, ##__VA_ARGS__) -#endif - -#else -/** - * @def SYS_LOG_ERR - * - * @brief Writes an ERROR level message to the log. - * - * @details Lowest logging level, these messages are logged whenever sys log is - * active. it's meant to report severe errors, such as those from which it's - * not possible to recover. - * - * @param ... A string optionally containing printk valid conversion specifier, - * followed by as many values as specifiers. - * @deprecated Use LOG_ERR - */ -#define SYS_LOG_ERR(...) { ; } -#endif /* CONFIG_SYS_LOG */ - -/* create dummy macros */ -#if !defined(SYS_LOG_WRN) -/** - * @def SYS_LOG_WRN - * - * @brief Writes a WARNING level message to the log. - * - * @details available if SYS_LOG_LEVEL is SYS_LOG_LEVEL_WARNING or higher. - * It's meant to register messages related to unusual situations that are - * not necessarily errors. - * - * @param ... A string optionally containing printk valid conversion specifier, - * followed by as many values as specifiers. - * @deprecated Use LOG_WRN - */ -#define SYS_LOG_WRN(...) { ; } -#endif - -#if !defined(SYS_LOG_INF) -/** - * @def SYS_LOG_INF - * - * @brief Writes an INFO level message to the log. - * - * @details available if SYS_LOG_LEVEL is SYS_LOG_LEVEL_INFO or higher. - * It's meant to write generic user oriented messages. - * - * @param ... A string optionally containing printk valid conversion specifier, - * followed by as many values as specifiers. - * - * @deprecated Use LOG_INF - */ -#define SYS_LOG_INF(...) { ; } -#endif - -#if !defined(SYS_LOG_DBG) -/** - * @def SYS_LOG_DBG - * - * @brief Writes a DEBUG level message to the log. - * - * @details highest logging level, available if SYS_LOG_LEVEL is - * SYS_LOG_LEVEL_DEBUG. It's meant to write developer oriented information. - * - * @param ... A string optionally containing printk valid conversion specifier, - * followed by as many values as specifiers. - * - * @deprecated Use LOG_DBG - */ -#define SYS_LOG_DBG(...) { ; } -#endif -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_INCLUDE_LOGGING_SYS_LOG_H_ */ diff --git a/samples/net/google_iot_mqtt/prj.conf b/samples/net/google_iot_mqtt/prj.conf index eabb78c0edf..34bca908b30 100644 --- a/samples/net/google_iot_mqtt/prj.conf +++ b/samples/net/google_iot_mqtt/prj.conf @@ -20,8 +20,6 @@ CONFIG_NET_MGMT=y CONFIG_NET_MGMT_EVENT=y CONFIG_LOG=y -CONFIG_SYS_LOG=y -CONFIG_SYS_LOG_DEFAULT_LEVEL=4 # This shouldn't need to be set, but isn't selected properly. CONFIG_NEWLIB_LIBC=y diff --git a/subsys/logging/CMakeLists.txt b/subsys/logging/CMakeLists.txt index 03dff816ec6..dae98605e32 100644 --- a/subsys/logging/CMakeLists.txt +++ b/subsys/logging/CMakeLists.txt @@ -1,6 +1,3 @@ -zephyr_sources_ifdef(CONFIG_SYS_LOG sys_log.c) -zephyr_sources_ifdef(CONFIG_SYS_LOG_BACKEND_NET sys_log_net.c) - zephyr_sources_ifdef( CONFIG_LOG log_list.c diff --git a/subsys/logging/sys_log.c b/subsys/logging/sys_log.c deleted file mode 100644 index dcbc63f2149..00000000000 --- a/subsys/logging/sys_log.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -void syslog_hook_default(const char *fmt, ...) -{ - (void)(fmt); /* Prevent warning about unused argument */ -} - -void (*syslog_hook)(const char *fmt, ...) = syslog_hook_default; - -void syslog_hook_install(void (*hook)(const char *, ...)) -{ - syslog_hook = hook; -} diff --git a/subsys/logging/sys_log_net.c b/subsys/logging/sys_log_net.c deleted file mode 100644 index dbd6428cb5b..00000000000 --- a/subsys/logging/sys_log_net.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2018 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include - -/* Set this to 1 if you want to see what is being sent to server */ -#define DEBUG_PRINTING 0 - -static struct net_context *ctx; -static struct sockaddr server_addr; - -/* FIXME: As there is no way to figure out these values in the hook - * function, use some pre-defined values. Change this to use the - * real facility and severity of the logging call when that info is - * available. - */ -static const int facility = 16; /* local0 */ -static const int severity = 6; /* info */ - -#define DATE_EPOCH "1970-01-01T00:00:00.000000-00:00" -static char date[sizeof(DATE_EPOCH)]; - -#if defined(CONFIG_NET_IPV6) || CONFIG_NET_HOSTNAME_ENABLE -#define MAX_HOSTNAME_LEN NET_IPV6_ADDR_LEN -#else -#define MAX_HOSTNAME_LEN NET_IPV4_ADDR_LEN -#endif - -static char hostname[MAX_HOSTNAME_LEN + 1]; - -NET_PKT_SLAB_DEFINE(syslog_tx_pkts, CONFIG_SYS_LOG_BACKEND_NET_MAX_BUF); -NET_BUF_POOL_DEFINE(syslog_tx_bufs, CONFIG_SYS_LOG_BACKEND_NET_MAX_BUF, - CONFIG_SYS_LOG_BACKEND_NET_MAX_BUF_SIZE, - CONFIG_NET_BUF_USER_DATA_SIZE, NULL); - -static struct k_mem_slab *get_tx_slab(void) -{ - return &syslog_tx_pkts; -} - -struct net_buf_pool *get_data_pool(void) -{ - return &syslog_tx_bufs; -} - -static void fill_header(struct net_buf *buf) -{ - snprintk(net_buf_tail(buf), - net_buf_tailroom(buf), - "<%d>1 %s %s - - - - ", - facility * 8 + severity, - date, - hostname); - - net_buf_add(buf, strlen(buf->data)); -} - -static void syslog_hook_net(const char *fmt, ...) -{ - struct net_buf *buf; - va_list vargs; - u8_t *ptr; - int ret; - - buf = net_buf_alloc(&syslog_tx_bufs, K_NO_WAIT); - if (!buf) { - return; - } - - fill_header(buf); - - va_start(vargs, fmt); - - ptr = net_buf_tail(buf); - - ret = vsnprintk(ptr, (net_buf_tailroom(buf) - 1), fmt, vargs); - if (ret < 0) { - return; - } - - va_end(vargs); - - if (ret > 0 && ptr[ret - 1] == '\n') { - /* No need to send \n to peer so strip it away */ - ret--; - } - - net_buf_add(buf, ret); - -#if DEBUG_PRINTING - { - static u32_t count; - - printk("%d:%s", ++count, buf->data); - } -#endif - net_context_send(ctx, buf->data, buf->len, NULL, K_NO_WAIT, NULL); - - net_buf_unref(buf); -} - -void syslog_net_hook_install(void) -{ -#if defined(CONFIG_NET_IPV6) - struct sockaddr_in6 local_addr6 = { - .sin6_family = AF_INET6, - .sin6_port = 0, - }; -#endif -#if defined(CONFIG_NET_IPV4) - struct sockaddr_in local_addr4 = { - .sin_family = AF_INET, - .sin_port = 0, - }; -#endif - struct sockaddr *local_addr = NULL; - socklen_t local_addr_len = 0; - socklen_t server_addr_len = 0; - int ret; - - net_sin(&server_addr)->sin_port = htons(514); - - ret = net_ipaddr_parse(CONFIG_SYS_LOG_BACKEND_NET_SERVER, - sizeof(CONFIG_SYS_LOG_BACKEND_NET_SERVER) - 1, - &server_addr); - if (ret == 0) { - SYS_LOG_ERR("Cannot configure syslog server address"); - return; - } - -#if defined(CONFIG_NET_IPV4) - if (server_addr.sa_family == AF_INET) { - local_addr = (struct sockaddr *)&local_addr4; - local_addr_len = sizeof(struct sockaddr_in); - server_addr_len = sizeof(struct sockaddr_in); - } -#endif - -#if defined(CONFIG_NET_IPV6) - if (server_addr.sa_family == AF_INET6) { - local_addr = (struct sockaddr *)&local_addr6; - local_addr_len = sizeof(struct sockaddr_in6); - server_addr_len = sizeof(struct sockaddr_in6); - } -#endif - - ret = net_context_get(server_addr.sa_family, SOCK_DGRAM, IPPROTO_UDP, - &ctx); - if (ret < 0) { - SYS_LOG_ERR("Cannot get context (%d)", ret); - return; - } - -#if CONFIG_NET_HOSTNAME_ENABLE - (void)memcpy(hostname, net_hostname_get(), MAX_HOSTNAME_LEN); -#else /* CONFIG_NET_HOSTNAME_ENABLE */ - if (server_addr.sa_family == AF_INET6) { -#if defined(CONFIG_NET_IPV6) - const struct in6_addr *src; - - src = net_if_ipv6_select_src_addr( - NULL, &net_sin6(&server_addr)->sin6_addr); - if (src) { - net_addr_ntop(AF_INET6, src, hostname, - MAX_HOSTNAME_LEN); - - net_ipaddr_copy(&local_addr6.sin6_addr, src); - } else { - goto unknown; - } -#else - goto unknown; -#endif - } else if (server_addr.sa_family == AF_INET) { -#if defined(CONFIG_NET_IPV4) - struct net_if_ipv4 *ipv4; - struct net_if *iface; - - iface = net_if_ipv4_select_src_iface( - &net_sin(&server_addr)->sin_addr); - ipv4 = iface->config.ip.ipv4; - - net_ipaddr_copy(&local_addr4.sin_addr, - &ipv4->unicast[0].address.in_addr); - - net_addr_ntop(AF_INET, &local_addr4.sin_addr, hostname, - MAX_HOSTNAME_LEN); -#else - goto unknown; -#endif - } else { - unknown: - strncpy(hostname, "zephyr", MAX_HOSTNAME_LEN); - } -#endif /* CONFIG_NET_HOSTNAME_ENABLE */ - - ret = net_context_bind(ctx, local_addr, local_addr_len); - if (ret < 0) { - SYS_LOG_ERR("Cannot bind context (%d)", ret); - return; - } - - ret = net_context_connect(ctx, &server_addr, server_addr_len, - NULL, K_NO_WAIT, NULL); - - /* We do not care about return value for this UDP connect call that - * basically does nothing. Calling the connect is only useful so that - * we can see the syslog connection in net-shell. - */ - - net_context_setup_pools(ctx, get_tx_slab, get_data_pool); - - syslog_hook_install(syslog_hook_net); -}