Move logging code to zeek namespaces

This commit is contained in:
Tim Wojtulewicz 2020-08-01 10:48:05 -07:00
parent 9a800265ff
commit 45b5c6e619
25 changed files with 135 additions and 114 deletions

View file

@ -127,7 +127,7 @@ void zeek::usage(const char* prog, int code)
fprintf(stderr, " $ZEEK_PREFIXES | prefix list (%s)\n", bro_prefixes().c_str()); fprintf(stderr, " $ZEEK_PREFIXES | prefix list (%s)\n", bro_prefixes().c_str());
fprintf(stderr, " $ZEEK_DNS_FAKE | disable DNS lookups (%s)\n", zeek::fake_dns() ? "on" : "off"); fprintf(stderr, " $ZEEK_DNS_FAKE | disable DNS lookups (%s)\n", zeek::fake_dns() ? "on" : "off");
fprintf(stderr, " $ZEEK_SEED_FILE | file to load seeds from (not set)\n"); fprintf(stderr, " $ZEEK_SEED_FILE | file to load seeds from (not set)\n");
fprintf(stderr, " $ZEEK_LOG_SUFFIX | ASCII log file extension (.%s)\n", logging::writer::Ascii::LogExt().c_str()); fprintf(stderr, " $ZEEK_LOG_SUFFIX | ASCII log file extension (.%s)\n", zeek::logging::writer::detail::Ascii::LogExt().c_str());
fprintf(stderr, " $ZEEK_PROFILER_FILE | Output file for script execution statistics (not set)\n"); fprintf(stderr, " $ZEEK_PROFILER_FILE | Output file for script execution statistics (not set)\n");
fprintf(stderr, " $ZEEK_DISABLE_ZEEKYGEN | Disable Zeekygen documentation support (%s)\n", zeekenv("ZEEK_DISABLE_ZEEKYGEN") ? "set" : "not set"); fprintf(stderr, " $ZEEK_DISABLE_ZEEKYGEN | Disable Zeekygen documentation support (%s)\n", zeekenv("ZEEK_DISABLE_ZEEKYGEN") ? "set" : "not set");
fprintf(stderr, " $ZEEK_DNS_RESOLVER | IPv4/IPv6 address of DNS resolver to use (%s)\n", zeekenv("ZEEK_DNS_RESOLVER") ? zeekenv("ZEEK_DNS_RESOLVER") : "not set, will use first IPv4 address from /etc/resolv.conf"); fprintf(stderr, " $ZEEK_DNS_RESOLVER | IPv4/IPv6 address of DNS resolver to use (%s)\n", zeekenv("ZEEK_DNS_RESOLVER") ? zeekenv("ZEEK_DNS_RESOLVER") : "not set, will use first IPv4 address from /etc/resolv.conf");

View file

@ -235,7 +235,7 @@ static void print_log(const std::vector<ValPtr>& vals)
record->Assign(0, zeek::make_intrusive<zeek::TimeVal>(network_time)); record->Assign(0, zeek::make_intrusive<zeek::TimeVal>(network_time));
record->Assign(1, std::move(vec)); record->Assign(1, std::move(vec));
log_mgr->Write(plval.get(), record.get()); zeek::log_mgr->Write(plval.get(), record.get());
} }
ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals, ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals,

View file

@ -493,7 +493,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id)
} }
bool Manager::PublishLogCreate(zeek::EnumVal* stream, zeek::EnumVal* writer, bool Manager::PublishLogCreate(zeek::EnumVal* stream, zeek::EnumVal* writer,
const logging::WriterBackend::WriterInfo& info, const zeek::logging::WriterBackend::WriterInfo& info,
int num_fields, const threading::Field* const * fields, int num_fields, const threading::Field* const * fields,
const broker::endpoint_info& peer) const broker::endpoint_info& peer)
{ {
@ -1243,7 +1243,7 @@ bool bro_broker::Manager::ProcessLogCreate(broker::zeek::LogCreate lc)
return false; return false;
} }
auto writer_info = std::unique_ptr<logging::WriterBackend::WriterInfo>(new logging::WriterBackend::WriterInfo); auto writer_info = std::make_unique<zeek::logging::WriterBackend::WriterInfo>();
if ( ! writer_info->FromBroker(std::move(lc.writer_info())) ) if ( ! writer_info->FromBroker(std::move(lc.writer_info())) )
{ {
zeek::reporter->Warning("failed to unpack remote log writer info"); zeek::reporter->Warning("failed to unpack remote log writer info");
@ -1274,7 +1274,7 @@ bool bro_broker::Manager::ProcessLogCreate(broker::zeek::LogCreate lc)
} }
} }
if ( ! log_mgr->CreateWriterForRemoteLog(stream_id->AsEnumVal(), writer_id->AsEnumVal(), writer_info.release(), num_fields, fields) ) if ( ! zeek::log_mgr->CreateWriterForRemoteLog(stream_id->AsEnumVal(), writer_id->AsEnumVal(), writer_info.release(), num_fields, fields) )
{ {
zeek::ODesc d; zeek::ODesc d;
stream_id->Describe(&d); stream_id->Describe(&d);
@ -1362,7 +1362,7 @@ bool bro_broker::Manager::ProcessLogWrite(broker::zeek::LogWrite lw)
} }
} }
log_mgr->WriteFromRemote(stream_id->AsEnumVal(), writer_id->AsEnumVal(), zeek::log_mgr->WriteFromRemote(stream_id->AsEnumVal(), writer_id->AsEnumVal(),
std::move(*path), num_fields, vals); std::move(*path), num_fields, vals);
fmt.EndRead(); fmt.EndRead();
return true; return true;
@ -1419,7 +1419,7 @@ void Manager::ProcessStatus(broker::status stat)
case broker::sc::peer_added: case broker::sc::peer_added:
++peer_count; ++peer_count;
assert(ctx); assert(ctx);
log_mgr->SendAllWritersTo(*ctx); zeek::log_mgr->SendAllWritersTo(*ctx);
event = Broker::peer_added; event = Broker::peer_added;
break; break;

View file

@ -187,7 +187,7 @@ public:
* @return true if the message is sent successfully. * @return true if the message is sent successfully.
*/ */
bool PublishLogCreate(zeek::EnumVal* stream, zeek::EnumVal* writer, bool PublishLogCreate(zeek::EnumVal* stream, zeek::EnumVal* writer,
const logging::WriterBackend::WriterInfo& info, const zeek::logging::WriterBackend::WriterInfo& info,
int num_fields, int num_fields,
const threading::Field* const * fields, const threading::Field* const * fields,
const broker::endpoint_info& peer = NoPeer); const broker::endpoint_info& peer = NoPeer);

View file

@ -5,7 +5,7 @@
#include "../Desc.h" #include "../Desc.h"
#include "../util.h" #include "../util.h"
using namespace logging; namespace zeek::logging {
Component::Component(const std::string& name, factory_callback arg_factory) Component::Component(const std::string& name, factory_callback arg_factory)
: zeek::plugin::Component(zeek::plugin::component::WRITER, name) : zeek::plugin::Component(zeek::plugin::component::WRITER, name)
@ -28,3 +28,5 @@ void Component::DoDescribe(zeek::ODesc* d) const
d->Add("Log::WRITER_"); d->Add("Log::WRITER_");
d->Add(CanonicalName()); d->Add(CanonicalName());
} }
} // namespace zeek::logging

View file

@ -6,16 +6,16 @@
#include "plugin/Component.h" #include "plugin/Component.h"
#include "plugin/TaggedComponent.h" #include "plugin/TaggedComponent.h"
namespace logging { ZEEK_FORWARD_DECLARE_NAMESPACED(WriterFrontend, zeek, logging);
ZEEK_FORWARD_DECLARE_NAMESPACED(WriterBackend, zeek, logging);
class WriterFrontend; namespace zeek::logging {
class WriterBackend;
/** /**
* Component description for plugins providing log writers. * Component description for plugins providing log writers.
*/ */
class Component : public zeek::plugin::Component, class Component : public zeek::plugin::Component,
public plugin::TaggedComponent<logging::Tag> { public zeek::plugin::TaggedComponent<logging::Tag> {
public: public:
typedef WriterBackend* (*factory_callback)(WriterFrontend* frontend); typedef WriterBackend* (*factory_callback)(WriterFrontend* frontend);
@ -60,4 +60,4 @@ private:
factory_callback factory; factory_callback factory;
}; };
} } // namespace zeek::logging

View file

@ -28,7 +28,8 @@
#include <broker/endpoint_info.hh> #include <broker/endpoint_info.hh>
using namespace std; using namespace std;
using namespace logging;
namespace zeek::logging {
struct Manager::Filter { struct Manager::Filter {
zeek::Val* fval; zeek::Val* fval;
@ -1621,3 +1622,5 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con
return result; return result;
} }
} // namespace zeek::logging

View file

@ -16,17 +16,19 @@
namespace broker { struct endpoint_info; } namespace broker { struct endpoint_info; }
ZEEK_FORWARD_DECLARE_NAMESPACED(SerializationFormat, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(SerializationFormat, zeek::detail);
class RotationTimer;
ZEEK_FORWARD_DECLARE_NAMESPACED(WriterFrontend, zeek, logging);
ZEEK_FORWARD_DECLARE_NAMESPACED(RotationFinishedMessage, zeek, logging);
namespace zeek {
namespace logging { namespace logging {
class WriterFrontend; class RotationTimer;
class RotationFinishedMessage;
/** /**
* Singleton class for managing log streams. * Singleton class for managing log streams.
*/ */
class Manager : public plugin::ComponentManager<Tag, Component> { class Manager : public zeek::plugin::ComponentManager<Tag, Component> {
public: public:
/** /**
@ -251,7 +253,7 @@ protected:
friend class WriterFrontend; friend class WriterFrontend;
friend class RotationFinishedMessage; friend class RotationFinishedMessage;
friend class RotationFailedMessage; friend class RotationFailedMessage;
friend class ::RotationTimer; friend class RotationTimer;
// Instantiates a new WriterBackend of the given type (note that // Instantiates a new WriterBackend of the given type (note that
// doing so creates a new thread!). // doing so creates a new thread!).
@ -298,6 +300,14 @@ private:
zeek::FuncPtr rotation_format_func; zeek::FuncPtr rotation_format_func;
}; };
} } // namespace logging;
extern logging::Manager* log_mgr; extern logging::Manager* log_mgr;
} // namespace zeek
extern zeek::logging::Manager*& log_mgr [[deprecated("Remove in v4.1. Use zeek::log_mgr.")]];
namespace logging {
using Manager [[deprecated("Remove in v4.1. Use zeek::logging::Manager.")]] = zeek::logging::Manager;
}

View file

@ -3,39 +3,43 @@
#include "Tag.h" #include "Tag.h"
#include "Manager.h" #include "Manager.h"
const logging::Tag logging::Tag::Error; namespace zeek::logging {
logging::Tag::Tag(type_t type, subtype_t subtype) const Tag Tag::Error;
Tag::Tag(type_t type, subtype_t subtype)
: zeek::Tag(log_mgr->GetTagType(), type, subtype) : zeek::Tag(log_mgr->GetTagType(), type, subtype)
{ {
} }
logging::Tag& logging::Tag::operator=(const logging::Tag& other) Tag& Tag::operator=(const Tag& other)
{ {
zeek::Tag::operator=(other); zeek::Tag::operator=(other);
return *this; return *this;
} }
logging::Tag& logging::Tag::operator=(const logging::Tag&& other) noexcept Tag& Tag::operator=(const Tag&& other) noexcept
{ {
zeek::Tag::operator=(other); zeek::Tag::operator=(other);
return *this; return *this;
} }
const zeek::EnumValPtr& logging::Tag::AsVal() const const zeek::EnumValPtr& Tag::AsVal() const
{ {
return zeek::Tag::AsVal(log_mgr->GetTagType()); return zeek::Tag::AsVal(log_mgr->GetTagType());
} }
zeek::EnumVal* logging::Tag::AsEnumVal() const zeek::EnumVal* Tag::AsEnumVal() const
{ {
return AsVal().get(); return AsVal().get();
} }
logging::Tag::Tag(zeek::EnumValPtr val) Tag::Tag(zeek::EnumValPtr val)
: zeek::Tag(std::move(val)) : zeek::Tag(std::move(val))
{ } { }
logging::Tag::Tag(zeek::EnumVal* val) Tag::Tag(zeek::EnumVal* val)
: zeek::Tag({zeek::NewRef{}, val}) : zeek::Tag({zeek::NewRef{}, val})
{ } { }
} // namespace zeek::logging

View file

@ -20,10 +20,10 @@ namespace plugin {
zeek::plugin::ComponentManager<T, C>; zeek::plugin::ComponentManager<T, C>;
} }
namespace logging { ZEEK_FORWARD_DECLARE_NAMESPACED(Manager, zeek, logging);
ZEEK_FORWARD_DECLARE_NAMESPACED(Component, zeek, logging);
class Manager; namespace zeek::logging {
class Component;
/** /**
* Class to identify a writer type. * Class to identify a writer type.
@ -128,4 +128,8 @@ protected:
explicit Tag(zeek::EnumVal* val); explicit Tag(zeek::EnumVal* val);
}; };
} // namespace zeek::logging
namespace logging {
using Tag [[deprecated("Remove in v4.1. Use zeek::logging::Tag.")]] = zeek::logging::Tag;
} }

View file

@ -14,7 +14,7 @@
using threading::Value; using threading::Value;
using threading::Field; using threading::Field;
namespace logging { namespace zeek::logging {
class RotationFinishedMessage final : public threading::OutputMessage<WriterFrontend> class RotationFinishedMessage final : public threading::OutputMessage<WriterFrontend>
{ {
@ -63,12 +63,8 @@ public:
bool Process() override { Object()->SetDisable(); return true; } bool Process() override { Object()->SetDisable(); return true; }
}; };
}
// Backend methods. // Backend methods.
using namespace logging;
broker::data WriterBackend::WriterInfo::ToBroker() const broker::data WriterBackend::WriterInfo::ToBroker() const
{ {
auto t = broker::table(); auto t = broker::table();
@ -331,3 +327,5 @@ bool WriterBackend::OnHeartbeat(double network_time, double current_time)
SendOut(new FlushWriteBufferMessage(frontend)); SendOut(new FlushWriteBufferMessage(frontend));
return DoHeartbeat(network_time, current_time); return DoHeartbeat(network_time, current_time);
} }
} // namespace zeek::logging

View file

@ -10,9 +10,9 @@
namespace broker { class data; } namespace broker { class data; }
namespace logging { ZEEK_FORWARD_DECLARE_NAMESPACED(WriterFrontend, zeek, logging);
class WriterFrontend; namespace zeek::logging {
/** /**
* Base class for writer implementation. When the logging::Manager creates a * Base class for writer implementation. When the logging::Manager creates a
@ -398,5 +398,8 @@ private:
int rotation_counter; // Tracks FinishedRotation() calls. int rotation_counter; // Tracks FinishedRotation() calls.
}; };
} // namespace zeek::logging
namespace logging {
using WriterBackend [[deprecated("Remove in v4.1. Use zeek::logging::WriterBackend.")]] = zeek::logging::WriterBackend;
} }

View file

@ -10,7 +10,7 @@
using threading::Value; using threading::Value;
using threading::Field; using threading::Field;
namespace logging { namespace zeek::logging {
// Messages sent from frontend to backend (i.e., "InputMessages"). // Messages sent from frontend to backend (i.e., "InputMessages").
@ -22,7 +22,6 @@ public:
num_fields(num_fields), fields(fields) num_fields(num_fields), fields(fields)
{} {}
bool Process() override { return Object()->Init(num_fields, fields); } bool Process() override { return Object()->Init(num_fields, fields); }
private: private:
@ -92,12 +91,8 @@ private:
double network_time; double network_time;
}; };
}
// Frontend methods. // Frontend methods.
using namespace logging;
WriterFrontend::WriterFrontend(const WriterBackend::WriterInfo& arg_info, zeek::EnumVal* arg_stream, WriterFrontend::WriterFrontend(const WriterBackend::WriterInfo& arg_info, zeek::EnumVal* arg_stream,
zeek::EnumVal* arg_writer, bool arg_local, bool arg_remote) zeek::EnumVal* arg_writer, bool arg_local, bool arg_remote)
{ {
@ -299,3 +294,5 @@ void WriterFrontend::DeleteVals(int num_fields, Value** vals)
delete [] vals; delete [] vals;
} }
} // namespace zeek::logging

View file

@ -4,9 +4,9 @@
#include "WriterBackend.h" #include "WriterBackend.h"
namespace logging { ZEEK_FORWARD_DECLARE_NAMESPACED(Manager, zeek, logging);
class Manager; namespace zeek::logging {
/** /**
* Bridge class between the logging::Manager and backend writer threads. The * Bridge class between the logging::Manager and backend writer threads. The
@ -209,4 +209,8 @@ protected:
threading::Value*** write_buffer; // Buffer of size WRITER_BUFFER_SIZE. threading::Value*** write_buffer; // Buffer of size WRITER_BUFFER_SIZE.
}; };
} // namespace zeek::logging
namespace logging {
using WriterFrontend [[deprecated("Remove in v4.1. Use zeek::logging::WriterFrontend.")]] = zeek::logging::WriterFrontend;
} }

View file

@ -19,54 +19,54 @@ enum PrintLogType %{
function Log::__create_stream%(id: Log::ID, stream: Log::Stream%) : bool function Log::__create_stream%(id: Log::ID, stream: Log::Stream%) : bool
%{ %{
bool result = log_mgr->CreateStream(id->AsEnumVal(), stream->AsRecordVal()); bool result = zeek::log_mgr->CreateStream(id->AsEnumVal(), stream->AsRecordVal());
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}
function Log::__remove_stream%(id: Log::ID%) : bool function Log::__remove_stream%(id: Log::ID%) : bool
%{ %{
bool result = log_mgr->RemoveStream(id->AsEnumVal()); bool result = zeek::log_mgr->RemoveStream(id->AsEnumVal());
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}
function Log::__enable_stream%(id: Log::ID%) : bool function Log::__enable_stream%(id: Log::ID%) : bool
%{ %{
bool result = log_mgr->EnableStream(id->AsEnumVal()); bool result = zeek::log_mgr->EnableStream(id->AsEnumVal());
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}
function Log::__disable_stream%(id: Log::ID%) : bool function Log::__disable_stream%(id: Log::ID%) : bool
%{ %{
bool result = log_mgr->DisableStream(id->AsEnumVal()); bool result = zeek::log_mgr->DisableStream(id->AsEnumVal());
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}
function Log::__add_filter%(id: Log::ID, filter: Log::Filter%) : bool function Log::__add_filter%(id: Log::ID, filter: Log::Filter%) : bool
%{ %{
bool result = log_mgr->AddFilter(id->AsEnumVal(), filter->AsRecordVal()); bool result = zeek::log_mgr->AddFilter(id->AsEnumVal(), filter->AsRecordVal());
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}
function Log::__remove_filter%(id: Log::ID, name: string%) : bool function Log::__remove_filter%(id: Log::ID, name: string%) : bool
%{ %{
bool result = log_mgr->RemoveFilter(id->AsEnumVal(), name); bool result = zeek::log_mgr->RemoveFilter(id->AsEnumVal(), name);
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}
function Log::__write%(id: Log::ID, columns: any%) : bool function Log::__write%(id: Log::ID, columns: any%) : bool
%{ %{
bool result = log_mgr->Write(id->AsEnumVal(), columns->AsRecordVal()); bool result = zeek::log_mgr->Write(id->AsEnumVal(), columns->AsRecordVal());
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}
function Log::__set_buf%(id: Log::ID, buffered: bool%): bool function Log::__set_buf%(id: Log::ID, buffered: bool%): bool
%{ %{
bool result = log_mgr->SetBuf(id->AsEnumVal(), buffered); bool result = zeek::log_mgr->SetBuf(id->AsEnumVal(), buffered);
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}
function Log::__flush%(id: Log::ID%): bool function Log::__flush%(id: Log::ID%): bool
%{ %{
bool result = log_mgr->Flush(id->AsEnumVal()); bool result = zeek::log_mgr->Flush(id->AsEnumVal());
return zeek::val_mgr->Bool(result); return zeek::val_mgr->Bool(result);
%} %}

View file

@ -23,13 +23,14 @@
#include "ascii.bif.h" #include "ascii.bif.h"
using namespace std; using namespace std;
using namespace logging::writer;
using namespace threading; using namespace threading;
using threading::Value; using threading::Value;
using threading::Field; using threading::Field;
static constexpr auto shadow_file_prefix = ".shadow."; static constexpr auto shadow_file_prefix = ".shadow.";
namespace zeek::logging::writer::detail {
/** /**
* Information about an leftover log file: that is, one that a previous * Information about an leftover log file: that is, one that a previous
* process was in the middle of writing, but never completed a rotation * process was in the middle of writing, but never completed a rotation
@ -190,7 +191,7 @@ static std::optional<LeftoverLog> parse_shadow_log(const std::string& fname)
return rval; return rval;
} }
Ascii::Ascii(WriterFrontend* frontend) : WriterBackend(frontend) Ascii::Ascii(zeek::logging::WriterFrontend* frontend) : zeek::logging::WriterBackend(frontend)
{ {
fd = 0; fd = 0;
ascii_done = false; ascii_done = false;
@ -783,7 +784,7 @@ void Ascii::RotateLeftoverLogs()
ll.filename.data(), ll.post_proc_func.data()); ll.filename.data(), ll.post_proc_func.data());
} }
auto rotation_path = log_mgr->FormatRotationPath( auto rotation_path = zeek::log_mgr->FormatRotationPath(
writer_val, ll.Path(), ll.open_time, ll.close_time, false, ppf); writer_val, ll.Path(), ll.open_time, ll.close_time, false, ppf);
rotation_path += ll.extension; rotation_path += ll.extension;
@ -908,3 +909,5 @@ bool Ascii::InternalClose(int fd)
return false; return false;
} }
} // namespace zeek::logging::writer::detail

View file

@ -10,18 +10,18 @@
#include "Desc.h" #include "Desc.h"
#include "zlib.h" #include "zlib.h"
namespace plugin::Zeek_AsciiWriter { class Plugin; } namespace zeek::plugin::Zeek_AsciiWriter { class Plugin; }
namespace logging { namespace writer { namespace zeek::logging::writer::detail {
class Ascii : public WriterBackend { class Ascii : public zeek::logging::WriterBackend {
public: public:
explicit Ascii(WriterFrontend* frontend); explicit Ascii(zeek::logging::WriterFrontend* frontend);
~Ascii() override; ~Ascii() override;
static std::string LogExt(); static std::string LogExt();
static WriterBackend* Instantiate(WriterFrontend* frontend) static zeek::logging::WriterBackend* Instantiate(zeek::logging::WriterFrontend* frontend)
{ return new Ascii(frontend); } { return new Ascii(frontend); }
protected: protected:
@ -79,5 +79,4 @@ private:
bool init_options; bool init_options;
}; };
} } // namespace zeek::logging::writer::detail
}

View file

@ -5,14 +5,13 @@
#include "Ascii.h" #include "Ascii.h"
namespace plugin { namespace zeek::plugin::Zeek_AsciiWriter {
namespace Zeek_AsciiWriter {
class Plugin : public zeek::plugin::Plugin { class Plugin : public zeek::plugin::Plugin {
public: public:
zeek::plugin::Configuration Configure() override zeek::plugin::Configuration Configure() override
{ {
AddComponent(new ::logging::Component("Ascii", ::logging::writer::Ascii::Instantiate)); AddComponent(new zeek::logging::Component("Ascii", zeek::logging::writer::detail::Ascii::Instantiate));
zeek::plugin::Configuration config; zeek::plugin::Configuration config;
config.name = "Zeek::AsciiWriter"; config.name = "Zeek::AsciiWriter";
@ -20,13 +19,11 @@ public:
return config; return config;
} }
protected: protected:
void InitPostScript() override; void InitPostScript() override
{
zeek::logging::writer::detail::Ascii::RotateLeftoverLogs();
}
} plugin; } plugin;
void Plugin::InitPostScript() } // namespace zeek::plugin::Zeek_AsciiWriter
{
::logging::writer::Ascii::RotateLeftoverLogs();
}
}
}

View file

@ -1,13 +1,11 @@
#include <algorithm> #include <algorithm>
#include <iostream>
#include "None.h" #include "None.h"
#include "none.bif.h" #include "none.bif.h"
#include <iostream> namespace zeek::logging::writer::detail {
using namespace logging;
using namespace writer;
bool None::DoInit(const WriterInfo& info, int num_fields, bool None::DoInit(const WriterInfo& info, int num_fields,
const threading::Field* const * fields) const threading::Field* const * fields)
@ -54,3 +52,5 @@ bool None::DoRotate(const char* rotated_path, double open, double close, bool te
return true; return true;
} }
} // namespace zeek::logging::writer::detail

View file

@ -6,14 +6,14 @@
#include "logging/WriterBackend.h" #include "logging/WriterBackend.h"
namespace logging { namespace writer { namespace zeek::logging::writer::detail {
class None : public WriterBackend { class None : public zeek::logging::WriterBackend {
public: public:
explicit None(WriterFrontend* frontend) : WriterBackend(frontend) {} explicit None(zeek::logging::WriterFrontend* frontend) : zeek::logging::WriterBackend(frontend) {}
~None() override {}; ~None() override {};
static WriterBackend* Instantiate(WriterFrontend* frontend) static zeek::logging::WriterBackend* Instantiate(zeek::logging::WriterFrontend* frontend)
{ return new None(frontend); } { return new None(frontend); }
protected: protected:
@ -29,5 +29,4 @@ protected:
bool DoHeartbeat(double network_time, double current_time) override { return true; } bool DoHeartbeat(double network_time, double current_time) override { return true; }
}; };
} } // namespace zeek::logging::writer::detail
}

View file

@ -5,14 +5,13 @@
#include "None.h" #include "None.h"
namespace plugin { namespace zeek::plugin::Zeek_NoneWriter {
namespace Zeek_NoneWriter {
class Plugin : public zeek::plugin::Plugin { class Plugin : public zeek::plugin::Plugin {
public: public:
zeek::plugin::Configuration Configure() override zeek::plugin::Configuration Configure() override
{ {
AddComponent(new ::logging::Component("None", ::logging::writer::None::Instantiate)); AddComponent(new zeek::logging::Component("None", zeek::logging::writer::detail::None::Instantiate));
zeek::plugin::Configuration config; zeek::plugin::Configuration config;
config.name = "Zeek::NoneWriter"; config.name = "Zeek::NoneWriter";
@ -21,5 +20,4 @@ public:
} }
} plugin; } plugin;
} } // namespace zeek::plugin::Zeek_NoneWriter
}

View file

@ -5,14 +5,13 @@
#include "SQLite.h" #include "SQLite.h"
namespace plugin { namespace zeek::plugin::Zeek_SQLiteWriter {
namespace Zeek_SQLiteWriter {
class Plugin : public zeek::plugin::Plugin { class Plugin : public zeek::plugin::Plugin {
public: public:
zeek::plugin::Configuration Configure() override zeek::plugin::Configuration Configure() override
{ {
AddComponent(new ::logging::Component("SQLite", ::logging::writer::SQLite::Instantiate)); AddComponent(new zeek::logging::Component("SQLite", zeek::logging::writer::detail::SQLite::Instantiate));
zeek::plugin::Configuration config; zeek::plugin::Configuration config;
config.name = "Zeek::SQLiteWriter"; config.name = "Zeek::SQLiteWriter";
@ -21,5 +20,4 @@ public:
} }
} plugin; } plugin;
} } // namespace zeek::plugin::Zeek_SQLiteWriter
}

View file

@ -12,13 +12,13 @@
#include "sqlite.bif.h" #include "sqlite.bif.h"
using namespace std; using namespace std;
using namespace logging;
using namespace writer;
using threading::Value; using threading::Value;
using threading::Field; using threading::Field;
SQLite::SQLite(WriterFrontend* frontend) namespace zeek::logging::writer::detail {
: WriterBackend(frontend),
SQLite::SQLite(zeek::logging::WriterFrontend* frontend)
: zeek::logging::WriterBackend(frontend),
fields(), num_fields(), db(), st() fields(), num_fields(), db(), st()
{ {
set_separator.assign( set_separator.assign(
@ -365,3 +365,5 @@ bool SQLite::DoRotate(const char* rotated_path, double open, double close, bool
return true; return true;
} }
} // namespace zeek::logging::writer::detail

View file

@ -11,14 +11,14 @@
#include "3rdparty/sqlite3.h" #include "3rdparty/sqlite3.h"
#include "Desc.h" #include "Desc.h"
namespace logging { namespace writer { namespace zeek::logging::writer::detail {
class SQLite : public WriterBackend { class SQLite : public zeek::logging::WriterBackend {
public: public:
explicit SQLite(WriterFrontend* frontend); explicit SQLite(zeek::logging::WriterFrontend* frontend);
~SQLite() override; ~SQLite() override;
static WriterBackend* Instantiate(WriterFrontend* frontend) static zeek::logging::WriterBackend* Instantiate(zeek::logging::WriterFrontend* frontend)
{ return new SQLite(frontend); } { return new SQLite(frontend); }
protected: protected:
@ -52,5 +52,4 @@ private:
threading::formatter::Ascii* io; threading::formatter::Ascii* io;
}; };
} } // namespace zeek::logging::writer::detail
}

View file

@ -102,7 +102,8 @@ zeek::detail::DNS_Mgr*& dns_mgr = zeek::detail::dns_mgr;
zeek::detail::TimerMgr* zeek::detail::timer_mgr = nullptr; zeek::detail::TimerMgr* zeek::detail::timer_mgr = nullptr;
zeek::detail::TimerMgr*& timer_mgr = zeek::detail::timer_mgr; zeek::detail::TimerMgr*& timer_mgr = zeek::detail::timer_mgr;
logging::Manager* log_mgr = nullptr; zeek::logging::Manager* zeek::log_mgr = nullptr;
zeek::logging::Manager*& log_mgr = zeek::log_mgr;
threading::Manager* thread_mgr = nullptr; threading::Manager* thread_mgr = nullptr;
zeek::input::Manager* zeek::input_mgr = nullptr; zeek::input::Manager* zeek::input_mgr = nullptr;
zeek::input::Manager*& input_mgr = zeek::input_mgr; zeek::input::Manager*& input_mgr = zeek::input_mgr;
@ -305,7 +306,7 @@ void terminate_bro()
zeek::event_mgr.Drain(); zeek::event_mgr.Drain();
notifier::registry.Terminate(); notifier::registry.Terminate();
log_mgr->Terminate(); zeek::log_mgr->Terminate();
zeek::input_mgr->Terminate(); zeek::input_mgr->Terminate();
thread_mgr->Terminate(); thread_mgr->Terminate();
broker_mgr->Terminate(); broker_mgr->Terminate();
@ -321,7 +322,7 @@ void terminate_bro()
// broker_mgr, timer_mgr, and supervisor are deleted via iosource_mgr // broker_mgr, timer_mgr, and supervisor are deleted via iosource_mgr
delete iosource_mgr; delete iosource_mgr;
delete zeek::event_registry; delete zeek::event_registry;
delete log_mgr; delete zeek::log_mgr;
delete zeek::reporter; delete zeek::reporter;
delete zeek::plugin_mgr; delete zeek::plugin_mgr;
delete zeek::val_mgr; delete zeek::val_mgr;
@ -581,7 +582,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
iosource_mgr = new iosource::Manager(); iosource_mgr = new iosource::Manager();
event_registry = new EventRegistry(); event_registry = new EventRegistry();
zeek::analyzer_mgr = new analyzer::Manager(); zeek::analyzer_mgr = new analyzer::Manager();
log_mgr = new logging::Manager(); zeek::log_mgr = new logging::Manager();
zeek::input_mgr = new input::Manager(); zeek::input_mgr = new input::Manager();
zeek::file_mgr = new file_analysis::Manager(); zeek::file_mgr = new file_analysis::Manager();
auto broker_real_time = ! options.pcap_file && ! options.deterministic_mode; auto broker_real_time = ! options.pcap_file && ! options.deterministic_mode;
@ -659,7 +660,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
exit(1); exit(1);
iosource_mgr->InitPostScript(); iosource_mgr->InitPostScript();
log_mgr->InitPostScript(); zeek::log_mgr->InitPostScript();
zeek::plugin_mgr->InitPostScript(); zeek::plugin_mgr->InitPostScript();
zeekygen_mgr->InitPostScript(); zeekygen_mgr->InitPostScript();
broker_mgr->InitPostScript(); broker_mgr->InitPostScript();