From 9541ac1e352eacc316ff278c0753c5b245f218d5 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 19 Oct 2013 09:10:17 +0800 Subject: [PATCH] add log macro use __PRETTY_FUNCTION__ for c++ --- trunk/src/core/srs_core_client.cpp | 2 +- trunk/src/core/srs_core_log.hpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/trunk/src/core/srs_core_client.cpp b/trunk/src/core/srs_core_client.cpp index bc9baca39..a8624b2ed 100755 --- a/trunk/src/core/srs_core_client.cpp +++ b/trunk/src/core/srs_core_client.cpp @@ -105,7 +105,7 @@ int SrsClient::get_peer_ip() ip = new char[strlen(buf) + 1]; strcpy(ip, buf); - srs_info("get peer ip success. ip=%s, fd=%d", ip, fd); + srs_trace("get peer ip success. ip=%s, fd=%d", ip, fd); return ret; } diff --git a/trunk/src/core/srs_core_log.hpp b/trunk/src/core/srs_core_log.hpp index 22ea13bb3..262add9ab 100755 --- a/trunk/src/core/srs_core_log.hpp +++ b/trunk/src/core/srs_core_log.hpp @@ -51,18 +51,34 @@ public: // user must implements the LogContext and define a global instance. extern ILogContext* log_context; +// donot print method #if 0 #define srs_verbose(msg, ...) printf("[%s][%d][verbs] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") #define srs_info(msg, ...) printf("[%s][%d][infos] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") #define srs_trace(msg, ...) printf("[%s][%d][trace] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") #define srs_warn(msg, ...) printf("[%s][%d][warns] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") #define srs_error(msg, ...) printf("[%s][%d][error] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") -#else +// use __FUNCTION__ to print c method +#elif 1 #define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") #define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") #define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") #define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") #define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") +// use __PRETTY_FUNCTION__ to print c++ class:method +#else + #define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") + #define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") + #define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") + #define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") + #define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") +#endif + +#if 0 + #undef srs_verbose + #define srs_verbose(msg, ...) (void)0 + #undef srs_info + #define srs_info(msg, ...) (void)0 #endif #endif