diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 192c1e722..b59ff4fd7 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -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) { diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 85ec07f56..c3ffb5ab6 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -36,6 +36,7 @@ INITIALIZE_ONCE(&Logger::StaticInitialize); std::set 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; +} diff --git a/lib/base/logger.hpp b/lib/base/logger.hpp index cd4c31390..f434de7bd 100644 --- a/lib/base/logger.hpp +++ b/lib/base/logger.hpp @@ -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 m_Loggers; static bool m_ConsoleLogEnabled; + static bool m_TimestampEnabled; static LogSeverity m_ConsoleLogSeverity; }; diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index d5fd39ad0..fbfb6c617 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -79,7 +79,7 @@ void StreamLogger::BindStream(std::ostream *stream, bool ownsStream) m_Stream = stream; m_OwnsStream = ownsStream; - + m_FlushLogTimer = make_shared(); 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); } - diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index 0fe56ebc8..ca4074d8b 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -312,6 +312,9 @@ std::vector DaemonCommand::GetArgumentSuggestions(const String& argument */ int DaemonCommand::Run(const po::variables_map& vm, const std::vector& ap) const { + if (!vm.count("validate")) + Logger::DisableTimestamp(false); + ScriptVariable::Set("UseVfork", true, false, true); Application::MakeVariablesConstant();