]> granicus.if.org Git - icinga2/commitdiff
CLI Commands: Remove timestamp prefix when logging output
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 31 Oct 2014 21:01:36 +0000 (22:01 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 31 Oct 2014 21:01:36 +0000 (22:01 +0100)
fixes #7376

icinga-app/icinga.cpp
lib/base/logger.cpp
lib/base/logger.hpp
lib/base/streamlogger.cpp
lib/cli/daemoncommand.cpp

index 192c1e722b0621ad39cc5d1e0eac074818063554..b59ff4fd723b6f7f56f82bdf3a97a6726b034f08 100644 (file)
@@ -328,6 +328,7 @@ int Main(void)
                    &GlobalArgumentCompletion, true, autoindex);
                rc = 0;
        } else if (command) {
+               Logger::DisableTimestamp(true);
 #ifndef _WIN32
                if (command->GetImpersonationLevel() == ImpersonateRoot) {
                        if (getuid() != 0) {
index 85ec07f568f51967c53786092618913a40e53022..c3ffb5ab61b0fea278aa223e611ccc09f638b4c1 100644 (file)
@@ -36,6 +36,7 @@ INITIALIZE_ONCE(&Logger::StaticInitialize);
 std::set<Logger::Ptr> Logger::m_Loggers;
 boost::mutex Logger::m_Mutex;
 bool Logger::m_ConsoleLogEnabled = true;
+bool Logger::m_TimestampEnabled = true;
 LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
 
 void Logger::StaticInitialize(void)
@@ -198,3 +199,13 @@ LogSeverity Logger::GetConsoleLogSeverity(void)
 {
        return m_ConsoleLogSeverity;
 }
+
+void Logger::DisableTimestamp(bool disable)
+{
+       m_TimestampEnabled = !disable;
+}
+
+bool Logger::IsTimestampEnabled(void)
+{
+       return m_TimestampEnabled;
+}
index cd4c313905b84f4f1bda2de47adc424e6a4982a2..f434de7bd2d02b3e65b42cecf8040c9bca6aad9e 100644 (file)
@@ -83,6 +83,8 @@ public:
 
        static void DisableConsoleLog(void);
        static bool IsConsoleLogEnabled(void);
+       static void DisableTimestamp(bool);
+       static bool IsTimestampEnabled(void);
 
        static void SetConsoleLogSeverity(LogSeverity logSeverity);
        static LogSeverity GetConsoleLogSeverity(void);
@@ -97,6 +99,7 @@ private:
        static boost::mutex m_Mutex;
        static std::set<Logger::Ptr> m_Loggers;
        static bool m_ConsoleLogEnabled;
+       static bool m_TimestampEnabled;
        static LogSeverity m_ConsoleLogSeverity;
 };
 
index d5fd39ad0b28f8bde8aa991d2e895b54eae1afdd..fbfb6c6177debb9eff345f027dc74df64ae7648e 100644 (file)
@@ -79,7 +79,7 @@ void StreamLogger::BindStream(std::ostream *stream, bool ownsStream)
 
        m_Stream = stream;
        m_OwnsStream = ownsStream;
-       
+
        m_FlushLogTimer = make_shared<Timer>();
        m_FlushLogTimer->SetInterval(1);
        m_FlushLogTimer->OnTimerExpired.connect(boost::bind(&StreamLogger::FlushLogTimerHandler, this));
@@ -98,7 +98,8 @@ void StreamLogger::ProcessLogEntry(std::ostream& stream, const LogEntry& entry)
 
        boost::mutex::scoped_lock lock(m_Mutex);
 
-       stream << "[" << timestamp << "] ";
+       if (Logger::IsTimestampEnabled())
+               stream << "[" << timestamp << "] ";
 
        int color;
 
@@ -137,4 +138,3 @@ void StreamLogger::ProcessLogEntry(const LogEntry& entry)
 {
        ProcessLogEntry(*m_Stream, entry);
 }
-
index 0fe56ebc85d3bf471121443576514c79e9c41f45..ca4074d8b8475c7cb64d1b2ea7a2f586b6612e29 100644 (file)
@@ -312,6 +312,9 @@ std::vector<String> DaemonCommand::GetArgumentSuggestions(const String& argument
  */
 int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::string>& ap) const
 {
+       if (!vm.count("validate"))
+               Logger::DisableTimestamp(false);
+
        ScriptVariable::Set("UseVfork", true, false, true);
 
        Application::MakeVariablesConstant();