Adding a dummy log writer WRITER_NONE that just discards everything.

This can be handy when oen doesn't want any output but still get
access to filter functionality, including rotation; and also for
general testing.
This commit is contained in:
Robin Sommer 2011-10-26 10:18:05 -07:00
parent f98dac9571
commit 2f2fad1f80
5 changed files with 50 additions and 0 deletions

View file

@ -335,6 +335,7 @@ set(bro_SRCS
LogMgr.cc LogMgr.cc
LogWriter.cc LogWriter.cc
LogWriterAscii.cc LogWriterAscii.cc
LogWriterNone.cc
Login.cc Login.cc
MIME.cc MIME.cc
NCP.cc NCP.cc

View file

@ -9,6 +9,7 @@
#include "Net.h" #include "Net.h"
#include "LogWriterAscii.h" #include "LogWriterAscii.h"
#include "LogWriterNone.h"
// Structure describing a log writer type. // Structure describing a log writer type.
struct LogWriterDefinition { struct LogWriterDefinition {
@ -20,6 +21,7 @@ struct LogWriterDefinition {
// Static table defining all availabel log writers. // Static table defining all availabel log writers.
LogWriterDefinition log_writers[] = { LogWriterDefinition log_writers[] = {
{ BifEnum::Log::WRITER_NONE, "None", 0, LogWriterNone::Instantiate },
{ BifEnum::Log::WRITER_ASCII, "Ascii", 0, LogWriterAscii::Instantiate }, { BifEnum::Log::WRITER_ASCII, "Ascii", 0, LogWriterAscii::Instantiate },
// End marker, don't touch. // End marker, don't touch.

16
src/LogWriterNone.cc Normal file
View file

@ -0,0 +1,16 @@
#include "LogWriterNone.h"
bool LogWriterNone::DoRotate(string rotated_path, double open,
double close, bool terminating)
{
if ( ! FinishedRotation(string("/dev/null"), Path(), open, close, terminating))
{
Error(Fmt("error rotating %s", Path().c_str()));
return false;
}
return true;
}

30
src/LogWriterNone.h Normal file
View file

@ -0,0 +1,30 @@
// See the file "COPYING" in the main distribution directory for copyright.
//
// Dummy log writer that just discards everything (but still pretends to rotate).
#ifndef LOGWRITERNONE_H
#define LOGWRITERNONE_H
#include "LogWriter.h"
class LogWriterNone : public LogWriter {
public:
LogWriterNone() {}
~LogWriterNone() {};
static LogWriter* Instantiate() { return new LogWriterNone; }
protected:
virtual bool DoInit(string path, int num_fields,
const LogField* const * fields) { return true; }
virtual bool DoWrite(int num_fields, const LogField* const * fields,
LogVal** vals) { return true; }
virtual bool DoSetBuf(bool enabled) { return true; }
virtual bool DoRotate(string rotated_path, double open, double close,
bool terminating);
virtual bool DoFlush() { return true; }
virtual void DoFinish() {}
};
#endif

View file

@ -159,6 +159,7 @@ module Log;
enum Writer %{ enum Writer %{
WRITER_DEFAULT, WRITER_DEFAULT,
WRITER_NONE,
WRITER_ASCII, WRITER_ASCII,
%} %}