Extending the log writer DoInit() API.

We now pass in a Info struct that contains:

    - the path name (as before)
    - the rotation interval
    - the log_rotate_base_time in seconds
    - a table of key/value pairs with further configuration options.

To fill the table, log filters have a new field "config: table[string]
of strings". This gives a way to pass arbitrary values from
script-land to writers. Interpretation is left up to the writer.

Also splits calc_next_rotate() into two functions, one of which is
thread-safe and can be used with the log_rotate_base_time value from
DoInit().

Includes also updates to the None writer:

    - It gets its own script writers/none.bro.

    - New bool option LogNone::debug to enable debug output. It then
      prints out all the values passed to DoInit(). That's used by a
      btest test to ensure the new DoInit() values are right.

    - Fixed a bug that prevented Bro from terminating..

(scripts.base.frameworks.logging.rotate-custom currently fails.
Haven't yet investigated why.)
This commit is contained in:
Robin Sommer 2012-06-21 17:42:33 -07:00
parent b38d1e1ec2
commit 19eea409c3
16 changed files with 231 additions and 23 deletions

View file

@ -1082,18 +1082,8 @@ const char* log_file_name(const char* tag)
return fmt("%s.%s", tag, (env ? env : "log"));
}
double calc_next_rotate(double interval, const char* rotate_base_time)
double parse_rotate_base_time(const char* rotate_base_time)
{
double current = network_time;
// Calculate start of day.
time_t teatime = time_t(current);
struct tm t;
t = *localtime(&teatime);
t.tm_hour = t.tm_min = t.tm_sec = 0;
double startofday = mktime(&t);
double base = -1;
if ( rotate_base_time && rotate_base_time[0] != '\0' )
@ -1105,6 +1095,19 @@ double calc_next_rotate(double interval, const char* rotate_base_time)
base = t.tm_min * 60 + t.tm_hour * 60 * 60;
}
return base;
}
double calc_next_rotate(double current, double interval, double base)
{
// Calculate start of day.
time_t teatime = time_t(current);
struct tm t;
t = *localtime_r(&teatime, &t);
t.tm_hour = t.tm_min = t.tm_sec = 0;
double startofday = mktime(&t);
if ( base < 0 )
// No base time given. To get nice timestamps, we round
// the time up to the next multiple of the rotation interval.