Improve Log

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-11-12 17:43:05 +08:00
parent deefdd2f9d
commit 8e90fd0e2b
8 changed files with 26 additions and 9 deletions

View File

@ -5,7 +5,6 @@ project(libuhttp C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
#set(CMAKE_VERBOSE_MAKEFILE ON)
#add_definitions(-DUH_DEBUG)
add_definitions(-O -Wall -Werror --std=gnu99 -D_GNU_SOURCE)

View File

@ -56,6 +56,10 @@ Explicit use OpenSSL as its SSL backend
Explicit use CyaSSl(wolfssl) as its SSL backend
~/libuhttp/build$ cmake .. -DUHTTP_USE_CYASSL=1
Turn on debug
~/libuhttp/build$ cmake .. -DUHTTP_DEBUG=1
## Build and install libuhttp

View File

@ -14,6 +14,12 @@ include_directories(${LIBEV_INCLUDE_DIRS} ${HTTPPARSER_INCLUDE_DIRS})
set(EXTRA_LIBS ${LIBEV_LIBRARIES} ${HTTPPARSER_LIBRARIES})
set(SOURCE_FILES uhttp.c uhttp_log.c uhttp_buf.c uhttp_ssl.c)
set(UHTTP_DEBUG_CONFIG 0)
option(UHTTP_DEBUG "Turn on debug" OFF)
if(UHTTP_DEBUG)
set(UHTTP_DEBUG_CONFIG 1)
endif()
option(UHTTP_DISABLE_SSL "Disable ssl support" OFF)
option(UHTTP_USE_OPENSSL "Explicit use OpenSSL as SSL backend" OFF)
option(UHTTP_USE_CYASSL "Explicit use CyaSSL as SSL backend" OFF)
@ -91,4 +97,5 @@ message(STATUS "UHTTP_SSL_ENABLED: OpenSSL")
elseif(UHTTP_USE_CYASSL_CONFIG)
message(STATUS "UHTTP_SSL_ENABLED: CyaSSL")
endif()
message(STATUS "DEBUG: ${UHTTP_DEBUG}")
message("")

View File

@ -148,18 +148,18 @@ static int on_message_complete(http_parser *parser)
{
struct uh_connection *con = container_of(parser, struct uh_connection, parser);
struct uh_route *r;
#ifdef UH_DEBUG
#if (UHTTP_DEBUG)
int i;
struct uh_header *header = con->req.header;
printf("Url:[%.*s]\n", (int)con->req.url.len, con->req.url.at);
uh_log_debug("Url:[%.*s]\n", (int)con->req.url.len, con->req.url.at);
for (i = 0; i < con->req.header_num; i++) {
printf("[%.*s:%.*s]\n", (int)header[i].field.len, header[i].field.at,
uh_log_debug("[%.*s:%.*s]\n", (int)header[i].field.len, header[i].field.at,
(int)header[i].value.len, header[i].value.at);
}
printf("Body:[%.*s]\n", (int)con->req.body.len, con->req.body.at);
uh_log_debug("Body:[%.*s]\n", (int)con->req.body.len, con->req.body.at);
#endif
list_for_each_entry(r, &con->srv->routes, list) {
@ -217,8 +217,8 @@ handshake_done:
buf->len += len;
#ifdef UH_DEBUG
printf("read:[%.*s]\n", len, base);
#if (UHTTP_DEBUG)
uh_log_debug("read:[%.*s]\n", len, base);
#endif
parsered = http_parser_execute(&con->parser, &parser_settings, base, len);

View File

@ -1,6 +1,7 @@
#include <assert.h>
#include <string.h>
#include "uhttp_buf.h"
#include "uhttp_log.h"
int uh_buf_init(struct uh_buf *buf, size_t initial_size)
{
@ -29,6 +30,9 @@ int uh_buf_grow(struct uh_buf *buf, size_t size)
buf->base = base;
buf->size += size;
uh_log_debug("uh_buf_grow:%p +%d", buf, size);
return 0;
}

View File

@ -5,6 +5,8 @@
#define UHTTP_VERSION_MINOR @UHTTP_VERSION_MINOR@
#define UHTTP_VERSION_STRING "@UHTTP_VERSION_MAJOR@.@UHTTP_VERSION_MINOR@"
#define UHTTP_DEBUG @UHTTP_DEBUG_CONFIG@
#define UHTTP_SSL_ENABLED @UHTTP_SSL_ENABLED_CONFIG@
#define UHTTP_USE_OPENSSL @UHTTP_USE_OPENSSL_CONFIG@
#define UHTTP_USE_CYASSL @UHTTP_USE_CYASSL_CONFIG@

View File

@ -20,7 +20,7 @@ void __uh_log(const char *filename, int line, int priority, const char *format,
#ifdef UH_DEBUG
#if (UHTTP_DEBUG)
fprintf(stderr, "%s\n", buf);
#else
if (priority == LOG_ERR)

View File

@ -6,6 +6,7 @@
#include <stdarg.h>
#include <errno.h>
#include <syslog.h>
#include "uhttp_config.h"
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
@ -14,7 +15,7 @@
*/
#define uh_log(priority, format...) __uh_log(__FILENAME__, __LINE__, priority, format)
#ifdef UH_DEBUG
#if (UHTTP_DEBUG)
#define uh_log_debug(format...) uh_log(LOG_DEBUG, format)
#else
#define uh_log_debug(format...)