diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 4dd2020d2fe94e57864667c8ebeb52d046f9c45f..c52658277b99bbaeb046b967165695124d35c216 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -72,6 +72,7 @@ #include <arpa/inet.h> #include <resolv.h> #include <istream> +// #include <fstream> #include <utility> // for std::pair #include <map> @@ -83,6 +84,9 @@ bool SIPVoIPLink::destroyed_ = false; namespace { +/** Environment variable used to set pjsip's logging level */ +#define SIPLOGLEVEL "SIPLOGLEVEL" + /** A map to retreive SFLphone internal call id * Given a SIP call ID (usefull for transaction sucha as transfer)*/ static std::map<std::string, std::string> transferCallID; @@ -417,8 +421,8 @@ SIPVoIPLink::SIPVoIPLink() : sipTransport(endpt_, cp_, pool_), evThread_(this) TRY(pj_init()); TRY(pjlib_util_init()); - // From 0 (min) to 6 (max) - pj_log_set_level(6); + + setSipLogLevel(); TRY(pjnath_init()); pj_caching_pool_init(cp_, &pj_pool_factory_default_policy, 0); @@ -521,6 +525,22 @@ void SIPVoIPLink::destroy() instance_ = 0; } +void SIPVoIPLink::setSipLogLevel() +{ + std::string loglevel = getenv(SIPLOGLEVEL); + int level = 0; + + if(!loglevel.empty()) { + if ( ! (std::istringstream(loglevel) >> level) ) level = 0; + + level = level > 6 ? 6 : level; + level = level < 0 ? 0 : level; + } + + // From 0 (min) to 6 (max) + pj_log_set_level(level); +} + // Called from EventThread::run (not main thread) bool SIPVoIPLink::getEvent() { diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index 1b8617cdddea35e60c7494f800a8dbaf02e1e8cf..44995e039c8f7ec5c48103c7446b6ab19ae11191 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -78,6 +78,13 @@ class SIPVoIPLink : public VoIPLink { */ static void destroy(); + /** + * Set pjsip's log level based on the SIPLOGLEVEL environment variable. + * SIPLOGLEVEL = 0 minimum logging + * SIPLOGLEVEL = 6 maximum logging + */ + static void setSipLogLevel(); + /** * Event listener. Each event send by the call manager is received and handled from here */