mirror of
https://github.com/zeek/zeek.git
synced 2025-10-15 04:58:21 +00:00
Lots of infracstructure for the new logging framework.
This pretty much follows the proposal on the projects page. It includes: - A new LogMgr, maintaining the set of writers. - The abstract LogWriter API. - An initial implementation in the form of LogWriterAscii producing tab-separated columns. Note that things are only partially working right now, things are subject to change, and it's all not much tested at all. That's why I'm creating separate branch for now. Example: bro -B logging test-logging && cat debug.log 1298063168.409852/1298063168.410368 [logging] Created new logging stream 'SSH::LOG_SSH' 1298063168.409852/1298063168.410547 [logging] Created new filter 'default' for stream 'SSH::LOG_SSH' 1298063168.409852/1298063168.410564 [logging] writer : Ascii 1298063168.409852/1298063168.410574 [logging] path : ssh_log_ssh 1298063168.409852/1298063168.410584 [logging] path_func : not set 1298063168.409852/1298063168.410594 [logging] event : not set 1298063168.409852/1298063168.410604 [logging] pred : not set 1298063168.409852/1298063168.410614 [logging] field t: time 1298063168.409852/1298063168.410625 [logging] field id.orig_h: addr 1298063168.409852/1298063168.410635 [logging] field id.orig_p: port 1298063168.409852/1298063168.410645 [logging] field id.resp_h: addr 1298063168.409852/1298063168.410655 [logging] field id.resp_p: port 1298063168.409852/1298063168.410665 [logging] field status: string 1298063168.409852/1298063168.410675 [logging] field country: string 1298063168.409852/1298063168.410817 [logging] Wrote record to filter 'default' on stream 'SSH::LOG_SSH' 1298063168.409852/1298063168.410865 [logging] Wrote record to filter 'default' on stream 'SSH::LOG_SSH' 1298063168.409852/1298063168.410906 [logging] Wrote record to filter 'default' on stream 'SSH::LOG_SSH' 1298063168.409852/1298063168.410945 [logging] Wrote record to filter 'default' on stream 'SSH::LOG_SSH' 1298063168.409852/1298063168.411044 [logging] Wrote record to filter 'default' on stream 'SSH::LOG_SSH > cat ssh_log_ssh.log 1298063168.40985 1.2.3.4 66770 2.3.4.5 65616 success unknown 1298063168.40985 1.2.3.4 66770 2.3.4.5 65616 failure US 1298063168.40985 1.2.3.4 66770 2.3.4.5 65616 failure UK 1298063168.40985 1.2.3.4 66770 2.3.4.5 65616 success BR 1298063168.40985 1.2.3.4 66770 2.3.4.5 65616 failure MX
This commit is contained in:
parent
9d407d882c
commit
68062e87f1
18 changed files with 1121 additions and 218 deletions
82
src/LogMgr.h
Normal file
82
src/LogMgr.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// A class managing log writers and filters.
|
||||
|
||||
#ifndef LOGMGR_H
|
||||
#define LOGMGR_H
|
||||
|
||||
#include "Val.h"
|
||||
|
||||
// One value per writer type we have.
|
||||
namespace LogWriterType {
|
||||
enum Type {
|
||||
None,
|
||||
Ascii
|
||||
};
|
||||
};
|
||||
|
||||
struct LogField {
|
||||
LogField() { }
|
||||
LogField(const LogField& other) : name(other.name), type(other.type) { }
|
||||
string name;
|
||||
TypeTag type;
|
||||
};
|
||||
|
||||
// A string that we can directly include as part of the value union below.
|
||||
struct log_string_type {
|
||||
int len;
|
||||
char string[]; // The string starts right here.
|
||||
};
|
||||
|
||||
// All values that can be directly logged by a Writer.
|
||||
struct LogVal {
|
||||
LogVal(bool arg_present = true) : present(arg_present) {}
|
||||
|
||||
bool present; // If false, the field is unset (i.e., &optional and not initialzed).
|
||||
|
||||
// The following union is a subset of BroValUnion, including only the
|
||||
// atomic types.
|
||||
union {
|
||||
bro_int_t int_val;
|
||||
bro_uint_t uint_val;
|
||||
addr_type addr_val;
|
||||
subnet_type subnet_val;
|
||||
double double_val;
|
||||
log_string_type string_val;
|
||||
} val;
|
||||
};
|
||||
|
||||
class LogWriter;
|
||||
|
||||
class LogMgr {
|
||||
public:
|
||||
LogMgr();
|
||||
~LogMgr();
|
||||
|
||||
// These correspond to the BiFs visible on the scripting layer. The
|
||||
// actual BiFs just forward here.
|
||||
bool CreateStream(EnumVal* stream_id, RecordType* columns);
|
||||
bool AddFilter(EnumVal* stream_id, RecordVal* filter);
|
||||
bool RemoveFilter(EnumVal* stream_id, StringVal* filter);
|
||||
bool Write(EnumVal* stream_id, RecordVal* columns);
|
||||
|
||||
protected:
|
||||
friend class LogWriter;
|
||||
|
||||
/// Functions also used by the writers.
|
||||
|
||||
// Reports an error for the given writer.
|
||||
void Error(LogWriter* writer, const char* msg);
|
||||
|
||||
private:
|
||||
struct Filter;
|
||||
struct Stream;
|
||||
|
||||
bool TraverseRecord(Filter* filter, RecordType* rt, TableVal* include, TableVal* exclude, string path, list<int> indices);
|
||||
LogVal** RecordToFilterVals(Filter* filter, RecordVal* columns);
|
||||
|
||||
vector<Stream *> streams; // Indexed by stream enum.
|
||||
};
|
||||
|
||||
extern LogMgr* log_mgr;
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue