CLI Commands: Remove timestamp prefix when logging output

fixes #7376
This commit is contained in:
Michael Friedrich 2014-10-31 22:01:36 +01:00
parent 78140fa1c8
commit bc83c9a698
5 changed files with 21 additions and 3 deletions

View 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) {

View 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;
}

View 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;
};

View 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);
}

View 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();