diff --git a/subsys/net/lib/http/Kconfig b/subsys/net/lib/http/Kconfig index 73be70e6126..246c858b0de 100644 --- a/subsys/net/lib/http/Kconfig +++ b/subsys/net/lib/http/Kconfig @@ -67,11 +67,11 @@ config HTTP_CLIENT_NETWORK_TIMEOUT Default network activity timeout in seconds. This setting is used for TCP connection timeout. -config NET_DEBUG_HTTP - bool "Debug HTTP" - depends on HTTP && NET_LOG - help - Enables HTTP output debug messages +module=HTTP +module-dep=NET_LOG +module-str=Log level for HTTP +module-help=Enables routing engine debug messages. +source "subsys/net/Kconfig.template.log_config.net" config NET_DEBUG_HTTP_CONN bool "Debug HTTP connections" diff --git a/subsys/net/lib/http/http.c b/subsys/net/lib/http/http.c index d1fb84e8cf3..68afd32942a 100644 --- a/subsys/net/lib/http/http.c +++ b/subsys/net/lib/http/http.c @@ -4,11 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#if defined(CONFIG_NET_DEBUG_HTTP) -#define SYS_LOG_DOMAIN "http" -#define NET_SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG -#define NET_LOG_ENABLED 1 -#endif +#define LOG_MODULE_NAME net_http +#define NET_LOG_LEVEL CONFIG_HTTP_LOG_LEVEL #include #include diff --git a/subsys/net/lib/http/http_client.c b/subsys/net/lib/http/http_client.c index 34f90902c40..938c8387564 100644 --- a/subsys/net/lib/http/http_client.c +++ b/subsys/net/lib/http/http_client.c @@ -4,15 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -#if defined(CONFIG_NET_DEBUG_HTTP) #if defined(CONFIG_HTTPS) -#define SYS_LOG_DOMAIN "https/client" +#define LOG_MODULE_NAME net_https_client #else -#define SYS_LOG_DOMAIN "http/client" -#endif -#define NET_SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG -#define NET_LOG_ENABLED 1 +#define LOG_MODULE_NAME net_http_client #endif +#define NET_LOG_LEVEL CONFIG_HTTP_LOG_LEVEL #include #include @@ -168,7 +165,6 @@ out: return ret; } -#if defined(CONFIG_NET_DEBUG_HTTP) static void sprint_addr(char *buf, int len, sa_family_t family, struct sockaddr *addr) @@ -181,27 +177,28 @@ static void sprint_addr(char *buf, int len, NET_DBG("Invalid protocol family"); } } -#endif static inline void print_info(struct http_ctx *ctx, enum http_method method) { -#if defined(CONFIG_NET_DEBUG_HTTP) - char local[NET_IPV6_ADDR_LEN]; - char remote[NET_IPV6_ADDR_LEN]; + if (NET_LOG_LEVEL >= LOG_LEVEL_INF) { + char local[NET_IPV6_ADDR_LEN]; + char remote[NET_IPV6_ADDR_LEN]; - sprint_addr(local, NET_IPV6_ADDR_LEN, - ctx->app_ctx.default_ctx->local.sa_family, - &ctx->app_ctx.default_ctx->local); + sprint_addr(local, NET_IPV6_ADDR_LEN, + ctx->app_ctx.default_ctx->local.sa_family, + &ctx->app_ctx.default_ctx->local); - sprint_addr(remote, NET_IPV6_ADDR_LEN, - ctx->app_ctx.default_ctx->remote.sa_family, - &ctx->app_ctx.default_ctx->remote); + sprint_addr(remote, NET_IPV6_ADDR_LEN, + ctx->app_ctx.default_ctx->remote.sa_family, + &ctx->app_ctx.default_ctx->remote); - NET_DBG("HTTP %s (%s) %s -> %s port %d", - http_method_str(method), ctx->http.req.host, local, remote, - ntohs(net_sin(&ctx->app_ctx.default_ctx->remote)->sin_port)); -#endif + NET_DBG("HTTP %s (%s) %s -> %s port %d", + http_method_str(method), ctx->http.req.host, local, + remote, + ntohs(net_sin(&ctx->app_ctx.default_ctx->remote)-> + sin_port)); + } } int http_client_send_req(struct http_ctx *ctx, @@ -273,21 +270,21 @@ out: static void print_header_field(size_t len, const char *str) { -#if defined(CONFIG_NET_DEBUG_HTTP) + if (NET_LOG_LEVEL >= LOG_LEVEL_INF) { #define MAX_OUTPUT_LEN 128 - char output[MAX_OUTPUT_LEN]; + char output[MAX_OUTPUT_LEN]; - /* The value of len does not count \0 so we need to increase it - * by one. - */ - if ((len + 1) > sizeof(output)) { - len = sizeof(output) - 1; + /* The value of len does not count \0 so we need to increase it + * by one. + */ + if ((len + 1) > sizeof(output)) { + len = sizeof(output) - 1; + } + + snprintk(output, len + 1, "%s", str); + + NET_DBG("[%zd] %s", len, output); } - - snprintk(output, len + 1, "%s", str); - - NET_DBG("[%zd] %s", len, output); -#endif } static int on_url(struct http_parser *parser, const char *at, size_t length) @@ -435,16 +432,15 @@ static int on_headers_complete(struct http_parser *parser) static int on_message_begin(struct http_parser *parser) { -#if defined(CONFIG_NET_DEBUG_HTTP) && (CONFIG_SYS_LOG_NET_LEVEL > 2) - struct http_ctx *ctx = CONTAINER_OF(parser, - struct http_ctx, - http.parser); + if (NET_LOG_LEVEL >= LOG_LEVEL_INF) { + struct http_ctx *ctx = CONTAINER_OF(parser, + struct http_ctx, + http.parser); + + NET_DBG("-- HTTP %s response (headers) --", + http_method_str(ctx->http.req.method)); + } - NET_DBG("-- HTTP %s response (headers) --", - http_method_str(ctx->http.req.method)); -#else - ARG_UNUSED(parser); -#endif return 0; } diff --git a/subsys/net/lib/http/http_server.c b/subsys/net/lib/http/http_server.c index 2e56279fdd1..5586086a6cc 100644 --- a/subsys/net/lib/http/http_server.c +++ b/subsys/net/lib/http/http_server.c @@ -4,15 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -#if defined(CONFIG_NET_DEBUG_HTTP) #if defined(CONFIG_HTTPS) -#define SYS_LOG_DOMAIN "https/server" +#define LOG_MODULE_NAME net_https_server #else -#define SYS_LOG_DOMAIN "http/server" -#endif -#define NET_SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG -#define NET_LOG_ENABLED 1 +#define LOG_MODULE_NAME net_http_server #endif +#define NET_LOG_LEVEL CONFIG_HTTP_LOG_LEVEL #include #include @@ -81,7 +78,7 @@ void http_server_conn_monitor(http_server_cb_t cb, void *user_data) const char * const http_state_str(enum http_state state) { -#if defined(CONFIG_NET_DEBUG_HTTP) +#if NET_LOG_LEVEL >= LOG_LEVEL_DBG switch (state) { case HTTP_STATE_CLOSED: return "CLOSED"; @@ -94,14 +91,14 @@ const char * const http_state_str(enum http_state state) case HTTP_STATE_OPEN: return "OPEN"; } -#else /* CONFIG_NET_DEBUG_HTTP */ +#else ARG_UNUSED(state); -#endif /* CONFIG_NET_DEBUG_HTTP */ +#endif return ""; } -#if defined(CONFIG_NET_DEBUG_HTTP) +#if NET_LOG_LEVEL >= LOG_LEVEL_DBG static void validate_state_transition(struct http_ctx *ctx, enum http_state current, enum http_state new) @@ -127,7 +124,7 @@ static void validate_state_transition(struct http_ctx *ctx, http_state_str(new), new); } } -#endif /* CONFIG_NET_DEBUG_HTTP */ +#endif /* NET_LOG_LEVEL */ void _http_change_state(struct http_ctx *ctx, enum http_state new_state, @@ -145,9 +142,9 @@ void _http_change_state(struct http_ctx *ctx, http_state_str(new_state), new_state, func, line); -#if defined(CONFIG_NET_DEBUG_HTTP) +#if NET_LOG_LEVEL >= LOG_LEVEL_DBG validate_state_transition(ctx, ctx->state, new_state); -#endif /* CONFIG_NET_DEBUG_HTTP */ +#endif ctx->state = new_state; } @@ -217,7 +214,7 @@ quit: return ret; } -#if defined(CONFIG_NET_DEBUG_HTTP) && (CONFIG_SYS_LOG_NET_LEVEL > 2) +#if NET_LOG_LEVEL >= LOG_LEVEL_INF static char *sprint_ipaddr(char *buf, int buflen, const struct sockaddr *addr) { if (addr->sa_family == AF_INET6) { @@ -300,14 +297,14 @@ static struct net_context *get_server_ctx(struct net_app_ctx *ctx, return NULL; } -#endif /* CONFIG_NET_DEBUG_HTTP */ +#endif /* NET_LOG_LEVEL */ static inline void new_client(struct http_ctx *ctx, enum http_connection_type type, struct net_app_ctx *app_ctx, const struct sockaddr *dst) { -#if defined(CONFIG_NET_DEBUG_HTTP) && (CONFIG_SYS_LOG_NET_LEVEL > 2) +#if NET_LOG_LEVEL >= LOG_LEVEL_INF #if defined(CONFIG_NET_IPV6) #define PORT_LEN sizeof("[]:xxxxx") #define ADDR_LEN NET_IPV6_ADDR_LEN @@ -331,7 +328,7 @@ static inline void new_client(struct http_ctx *ctx, } else { NET_INFO("[%p] %s connection", ctx, type_str); } -#endif /* CONFIG_NET_DEBUG_HTTP */ +#endif /* NET_LOG_LEVEL */ } static void url_connected(struct http_ctx *ctx, @@ -996,7 +993,7 @@ static inline void new_server(struct http_ctx *ctx, const char *server_banner, const struct sockaddr *addr) { -#if defined(CONFIG_NET_DEBUG_HTTP) && (CONFIG_SYS_LOG_NET_LEVEL > 2) +#if NET_LOG_LEVEL >= LOG_LEVEL_INF #if defined(CONFIG_NET_IPV6) #define PORT_STR sizeof("[]:xxxxx") char buf[NET_IPV6_ADDR_LEN + PORT_STR]; @@ -1011,7 +1008,7 @@ static inline void new_server(struct http_ctx *ctx, } else { NET_INFO("%s (%p)", server_banner, ctx); } -#endif /* CONFIG_NET_DEBUG_HTTP */ +#endif /* NET_LOG_LEVEL */ } static void init_net(struct http_ctx *ctx,