mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 15:18:20 +00:00
Rotation support.
This follows rather closely how rotation currently works in rotate-logs.bro. logging.bro now defines: # Default rotation interval; zero disables rotation. const default_rotation_interval = 0secs &redef; # Default naming suffix format. const default_rotation_date_format = "%y-%m-%d_%H.%M.%S" &redef; # Default postprocessor for writers outputting into files. const default_rotation_postprocessor = "" &redef; # Default function to construct the name of the rotated file. # The default implementation includes # default_rotation_date_format into the file name. global default_rotation_path_func: function(info: RotationInfo) : string &redef; Writer support for rotation is optional, usually it will only make sense for file-based writers. TODO: Currently, there's no way to customize rotation on a per file basis, there are only the global defaults as described above. Individual customization is coming next.
This commit is contained in:
parent
90af0d06c3
commit
d6cef16f77
16 changed files with 387 additions and 68 deletions
|
@ -18,7 +18,7 @@ LogWriter::~LogWriter()
|
|||
delete [] fields;
|
||||
}
|
||||
|
||||
bool LogWriter::Init(string arg_path, int arg_num_fields, LogField** arg_fields)
|
||||
bool LogWriter::Init(string arg_path, int arg_num_fields, const LogField* const * arg_fields)
|
||||
{
|
||||
path = arg_path;
|
||||
num_fields = arg_num_fields;
|
||||
|
@ -75,6 +75,17 @@ bool LogWriter::SetBuf(bool enabled)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool LogWriter::Rotate(string rotated_path, string postprocessor, double open, double close, bool terminating)
|
||||
{
|
||||
if ( ! DoRotate(rotated_path, postprocessor, open, close, terminating) )
|
||||
{
|
||||
disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LogWriter::Flush()
|
||||
{
|
||||
if ( ! DoFlush() )
|
||||
|
@ -126,4 +137,45 @@ void LogWriter::DeleteVals(LogVal** vals)
|
|||
delete vals[i];
|
||||
}
|
||||
|
||||
bool LogWriter::RunPostProcessor(string fname, string postprocessor, string old_name, double open, double close, bool terminating)
|
||||
{
|
||||
// This function operates in way backwards-compatible with the old Bro
|
||||
// log rotation scheme.
|
||||
|
||||
if ( ! postprocessor.size() )
|
||||
return true;
|
||||
|
||||
const char* const fmt = "%y-%m-%d_%H.%M.%S";
|
||||
|
||||
struct tm tm1;
|
||||
struct tm tm2;
|
||||
|
||||
time_t tt1 = (time_t)open;
|
||||
time_t tt2 = (time_t)close;
|
||||
|
||||
localtime_r(&tt1, &tm1);
|
||||
localtime_r(&tt2, &tm2);
|
||||
|
||||
char buf1[128];
|
||||
char buf2[128];
|
||||
|
||||
strftime(buf1, sizeof(buf1), fmt, &tm1);
|
||||
strftime(buf2, sizeof(buf2), fmt, &tm2);
|
||||
|
||||
string cmd = postprocessor;
|
||||
cmd += " " + fname;
|
||||
cmd += " " + old_name;
|
||||
cmd += " " + string(buf1);
|
||||
cmd += " " + string(buf2);
|
||||
cmd += " " + string(terminating ? "1" : "0");
|
||||
cmd += " &";
|
||||
|
||||
system(cmd.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue