mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Test case for a dynamic log writer.
This commit is contained in:
parent
aa731eeaec
commit
f45526f373
9 changed files with 159 additions and 1 deletions
31
testing/btest/plugins/writer-plugin/src/Foo.cc
Normal file
31
testing/btest/plugins/writer-plugin/src/Foo.cc
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
#include "Foo.h"
|
||||
|
||||
using namespace logging;
|
||||
using namespace writer;
|
||||
|
||||
bool Foo::DoInit(const WriterInfo& info, int num_fields,
|
||||
const threading::Field* const * fields)
|
||||
{
|
||||
desc.EnableEscaping();
|
||||
desc.AddEscapeSequence("|");
|
||||
threading::formatter::Ascii::SeparatorInfo sep_info("|", ",", "-", "");
|
||||
formatter = new threading::formatter::Ascii(this, sep_info);
|
||||
path = info.path;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Foo::DoWrite(int num_fields, const threading::Field* const* fields,
|
||||
threading::Value** vals)
|
||||
{
|
||||
desc.Clear();
|
||||
|
||||
if ( ! formatter->Describe(&desc, num_fields, fields, vals) )
|
||||
return false;
|
||||
|
||||
printf("[%s] %s\n", path.c_str(), desc.Description());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
39
testing/btest/plugins/writer-plugin/src/Foo.h
Normal file
39
testing/btest/plugins/writer-plugin/src/Foo.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
#ifndef BRO_PLUGIN_DEMO_FOO_H
|
||||
#define BRO_PLUGIN_DEMO_FOO_H
|
||||
|
||||
#include "logging/WriterBackend.h"
|
||||
#include "threading/formatters/Ascii.h"
|
||||
|
||||
namespace logging { namespace writer {
|
||||
|
||||
class Foo : public WriterBackend {
|
||||
public:
|
||||
Foo(WriterFrontend* frontend) : WriterBackend(frontend) {}
|
||||
~Foo() {};
|
||||
|
||||
static WriterBackend* Instantiate(WriterFrontend* frontend)
|
||||
{ return new Foo(frontend); }
|
||||
|
||||
protected:
|
||||
virtual bool DoInit(const WriterInfo& info, int num_fields,
|
||||
const threading::Field* const * fields);
|
||||
|
||||
virtual bool DoWrite(int num_fields, const threading::Field* const* fields,
|
||||
threading::Value** vals);
|
||||
virtual bool DoSetBuf(bool enabled) { return true; }
|
||||
virtual bool DoRotate(const char* rotated_path, double open,
|
||||
double close, bool terminating) { return true; }
|
||||
virtual bool DoFlush(double network_time) { return true; }
|
||||
virtual bool DoFinish(double network_time) { return true; }
|
||||
virtual bool DoHeartbeat(double network_time, double current_time) { return true; }
|
||||
|
||||
private:
|
||||
string path;
|
||||
ODesc desc;
|
||||
threading::formatter::Formatter* formatter;
|
||||
};
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
19
testing/btest/plugins/writer-plugin/src/Plugin.cc
Normal file
19
testing/btest/plugins/writer-plugin/src/Plugin.cc
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "Plugin.h"
|
||||
|
||||
#include "Foo.h"
|
||||
|
||||
namespace plugin { namespace Demo_Foo { Plugin plugin; } }
|
||||
|
||||
using namespace plugin::Demo_Foo;
|
||||
|
||||
plugin::Configuration Plugin::Configure()
|
||||
{
|
||||
AddComponent(new ::logging::Component("Foo", ::logging::writer::Foo::Instantiate));
|
||||
|
||||
plugin::Configuration config;
|
||||
config.name = "Demo::Foo";
|
||||
config.description = "A Foo test logging writer";
|
||||
config.version.major = 1;
|
||||
config.version.minor = 0;
|
||||
return config;
|
||||
}
|
22
testing/btest/plugins/writer-plugin/src/Plugin.h
Normal file
22
testing/btest/plugins/writer-plugin/src/Plugin.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
#ifndef BRO_PLUGIN_DEMO_FOO
|
||||
#define BRO_PLUGIN_DEMO_FOO
|
||||
|
||||
#include <plugin/Plugin.h>
|
||||
|
||||
namespace plugin {
|
||||
namespace Demo_Foo {
|
||||
|
||||
class Plugin : public ::plugin::Plugin
|
||||
{
|
||||
protected:
|
||||
// Overridden from plugin::Plugin.
|
||||
virtual plugin::Configuration Configure();
|
||||
};
|
||||
|
||||
extern Plugin plugin;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue