diff --git a/src/XrdCl/XrdClDefaultEnv.cc b/src/XrdCl/XrdClDefaultEnv.cc index 8436401864b..bfa31a94007 100644 --- a/src/XrdCl/XrdClDefaultEnv.cc +++ b/src/XrdCl/XrdClDefaultEnv.cc @@ -221,6 +221,56 @@ namespace XrdCl return sLog; } + //---------------------------------------------------------------------------- + // Set log level + //---------------------------------------------------------------------------- + void DefaultEnv::SetLogLevel( const std::string &level ) + { + Log *log = GetLog(); + log->SetLevel( level ); + } + + //---------------------------------------------------------------------------- + // Set log file + //---------------------------------------------------------------------------- + bool DefaultEnv::SetLogFile( const std::string &filepath ) + { + Log *log = GetLog(); + LogOutFile *out = new LogOutFile(); + + if( out->Open( filepath ) ) + { + log->SetOutput( out ); + return true; + } + + delete out; + return false; + } + + //---------------------------------------------------------------------------- + //! Set log mask. + //------------------------------------------------------------------------ + void DefaultEnv::SetLogMask( const std::string &level, + const std::string &mask ) + { + Log *log = GetLog(); + MaskTranslator translator; + uint64_t topicMask = translator.translateMask( mask ); + + if( level == "All" ) + { + log->SetMask( Log::ErrorMsg, topicMask ); + log->SetMask( Log::WarningMsg, topicMask ); + log->SetMask( Log::InfoMsg, topicMask ); + log->SetMask( Log::DebugMsg, topicMask ); + log->SetMask( Log::DumpMsg, topicMask ); + return; + } + + log->SetMask( level, topicMask ); + } + //---------------------------------------------------------------------------- // Get fork handler //---------------------------------------------------------------------------- diff --git a/src/XrdCl/XrdClDefaultEnv.hh b/src/XrdCl/XrdClDefaultEnv.hh index 7c3f6d0d834..e5051112131 100644 --- a/src/XrdCl/XrdClDefaultEnv.hh +++ b/src/XrdCl/XrdClDefaultEnv.hh @@ -63,6 +63,45 @@ namespace XrdCl //------------------------------------------------------------------------ static Log *GetLog(); + //------------------------------------------------------------------------ + //! Set log level + //! + //! @param level Dump, Debug, Info, Warning or Error + //------------------------------------------------------------------------ + static void SetLogLevel( const std::string &level ); + + //------------------------------------------------------------------------ + //! Set log file + //! + //! @param filepath path to the log file + //------------------------------------------------------------------------ + static bool SetLogFile( const std::string &filepath ); + + //------------------------------------------------------------------------ + //! Set log mask. + //! Determines which diagnostics topics should be printed. It's a + //! "|" separated list of topics. The first element may be "All" in which + //! case all the topics are enabled and the subsequent elements may turn + //! them off, or "None" in which case all the topics are disabled and + //! the subsequent flags may turn them on. If the topic name is prefixed + //! with "^", then it means that the topic should be disabled. If the + //! topic name is not prefixed, then it means that the topic should be + //! enabled. + //! + //! The default for each level is "All", except for the "Dump" level, + //! where the default is "All|^PollerMsg". This means that, at the + //! "Dump" level, all the topics but "PollerMsg" are enabled. + //! + //! Available topics: AppMsg, UtilityMsg, FileMsg, PollerMsg, + //! PostMasterMsg, XRootDTransportMsg, TaskMgrMsg, XRootDMsg, + //! FileSystemMsg, AsyncSockMsg + //! + //! @param level log level or "All" for all levels + //! @param mask log mask + //------------------------------------------------------------------------ + static void SetLogMask( const std::string &level, + const std::string &mask ); + //------------------------------------------------------------------------ //! Get the fork handler //------------------------------------------------------------------------