New functions Log::disable_stream() and Log::enable_stream().

When disabled, all outout to a stream will be ignored (but no error
raised).
This commit is contained in:
Robin Sommer 2011-03-08 17:54:11 -08:00
parent 88d114053c
commit 4b7c5905f1
6 changed files with 96 additions and 4 deletions

View file

@ -48,6 +48,7 @@ struct LogMgr::WriterInfo {
struct LogMgr::Stream {
EnumVal* id;
bool enabled;
string name;
RecordType* columns;
EventHandlerPtr event;
@ -335,6 +336,7 @@ bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
// Create new stream.
streams[idx] = new Stream;
streams[idx]->id = id->Ref()->AsEnumVal();
streams[idx]->enabled = true;
streams[idx]->name = id->Type()->AsEnumType()->Lookup(idx);
streams[idx]->event = event ? event_registry->Lookup(event->GetID()->Name()) : 0;
streams[idx]->columns = columns->Ref()->AsRecordType();
@ -344,6 +346,36 @@ bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
return true;
}
bool LogMgr::EnableStream(EnumVal* id)
{
Stream* stream = FindStream(id);
if ( ! stream )
return false;
if ( stream->enabled )
return true;
stream->enabled = true;
DBG_LOG(DBG_LOGGING, "Reenabled logging stream '%s'", stream->name.c_str());
return true;
}
bool LogMgr::DisableStream(EnumVal* id)
{
Stream* stream = FindStream(id);
if ( ! stream )
return false;
if ( ! stream->enabled )
return true;
stream->enabled = false;
DBG_LOG(DBG_LOGGING, "Disabled logging stream '%s'", stream->name.c_str());
return true;
}
// Helper for recursive record field unrolling.
bool LogMgr::TraverseRecord(Filter* filter, RecordType* rt, TableVal* include, TableVal* exclude, string path, list<int> indices)
{
@ -554,6 +586,9 @@ bool LogMgr::Write(EnumVal* id, RecordVal* columns)
if ( ! stream )
return false;
if ( ! stream->enabled )
return true;
columns = columns->CoerceTo(stream->columns);
if ( ! columns )
@ -833,6 +868,9 @@ bool LogMgr::Write(EnumVal* id, EnumVal* writer, string path, int num_fields, Lo
return false;
}
if ( ! stream->enabled )
return true;
Stream::WriterMap::iterator w = stream->writers.find(Stream::WriterPathPair(writer->AsEnum(), path));
if ( w == stream->writers.end() )
@ -891,6 +929,9 @@ bool LogMgr::Flush(EnumVal* id)
if ( ! stream )
return false;
if ( ! stream->enabled )
return true;
for ( Stream::WriterMap::iterator i = stream->writers.begin(); i != stream->writers.end(); i++ )
i->second->writer->Flush();