From: Christian Herdtweck Date: Thu, 22 Dec 2016 16:54:19 +0000 (+0100) Subject: Disambiguate enable_syslog functions by adding a enable_syslog_facility X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=refs%2Fheads%2Fenable-syslog-facility;p=libi2ncommon Disambiguate enable_syslog functions by adding a enable_syslog_facility Had determined that compiler casts Facility to bool even if given the perfect constant value; avoid this by renaming one of the functions. Also made arguments const refs (but that was not enough) --- diff --git a/src/logfunc.cpp b/src/logfunc.cpp index c6883fc..2a751c8 100644 --- a/src/logfunc.cpp +++ b/src/logfunc.cpp @@ -618,7 +618,7 @@ PartLogger::LogHelper PartLogger::debug(const SourceLocation& loc) * @param name the name used as ident. * @param facility the facility which should be used. */ -void enable_syslog( const std::string& name, Facility facility ) +void enable_syslog( const std::string& name, const Facility &facility ) { boost::recursive_mutex::scoped_lock lock(LoggerLock); @@ -635,7 +635,7 @@ void enable_syslog( const std::string& name, Facility facility ) * determined by reading the program path from /proc/\/exe. * @param facility the facility which should be used. */ -void enable_syslog( Facility facility ) +void enable_syslog_facility( const Facility &facility ) { boost::recursive_mutex::scoped_lock lock(LoggerLock); @@ -653,7 +653,7 @@ void enable_syslog( Facility facility ) * enable or disable logging to syslog. * @param enable whether the logging to syslog should be enabled or not. */ -void enable_syslog( bool enable ) +void enable_syslog( const bool enable ) { boost::recursive_mutex::scoped_lock lock(LoggerLock); @@ -661,7 +661,7 @@ void enable_syslog( bool enable ) { if (!g_syslog_opened) { - enable_syslog( g_facility ); + enable_syslog_facility( g_facility ); } } else // ! enable diff --git a/src/logfunc.hpp b/src/logfunc.hpp index 56b1814..849e700 100644 --- a/src/logfunc.hpp +++ b/src/logfunc.hpp @@ -194,9 +194,9 @@ extern PartLogger GlobalLogger; ** They work globally; i.e. they determine the loggin for the whole program! */ -void enable_syslog( const std::string& name, Facility facility= Facility::User ); -void enable_syslog( Facility facility ); -void enable_syslog( bool enable= true ); +void enable_syslog( const std::string& name, const Facility &facility= Facility::User ); +void enable_syslog_facility( const Facility &facility ); // avoid compiler casting facility to bool +void enable_syslog( const bool enable= true ); void enable_stderr_log(bool enable= true ); diff --git a/test/test_logging.cpp b/test/test_logging.cpp index 597e82b..623551b 100644 --- a/test/test_logging.cpp +++ b/test/test_logging.cpp @@ -79,7 +79,7 @@ BOOST_FIXTURE_TEST_SUITE(TestLogging, TestLoggingFixture) BOOST_AUTO_TEST_CASE(Syslog1) { //Logger::enable_syslog("I2N Unittest", Logger::Facility::User ); - Logger::enable_syslog( Logger::Facility::User ); + Logger::enable_syslog_facility( Logger::Facility::User ); Logger::PartLogger log(__func__); Logger::set_log_level( 7 ); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(Syslog1) BOOST_AUTO_TEST_CASE(TestScopeTrace1) { //Logger::enable_syslog("I2N Unittest", Logger::Facility::User ); - Logger::enable_syslog( Logger::Facility::User ); + Logger::enable_syslog_facility( Logger::Facility::User ); Logger::PartLogger log(__func__); Logger::set_log_level( 7 ); @@ -141,7 +141,7 @@ void recursive_function(int level=0) BOOST_AUTO_TEST_CASE(TestRecursiveScopeTracker) { - Logger::enable_syslog( Logger::Facility::User ); + Logger::enable_syslog_facility( Logger::Facility::User ); Logger::PartLogger log(__func__); Logger::set_log_level( 7 );