Introduce script-land variable that can be used to set logdir.

Addresses GH-772
This commit is contained in:
Henrik Kramselund Jereminsen 2021-05-11 09:25:24 +02:00 committed by Johanna Amann
parent 672504e265
commit 6bde33aca7
4 changed files with 22 additions and 1 deletions

View file

@ -54,6 +54,11 @@ export {
## This option is also available as a per-filter ``$config`` option. ## This option is also available as a per-filter ``$config`` option.
const gzip_file_extension = "gz" &redef; const gzip_file_extension = "gz" &redef;
## Default logs to current directory
## Can be redefined to send files into logging directory
##
const logdir = "." &redef;
## Format of timestamps when writing out JSON. By default, the JSON ## Format of timestamps when writing out JSON. By default, the JSON
## formatter will use double values for timestamps which represent the ## formatter will use double values for timestamps which represent the
## number of seconds from the UNIX epoch. ## number of seconds from the UNIX epoch.

View file

@ -252,6 +252,12 @@ void Ascii::InitConfigOptions()
(const char*) BifConst::LogAscii::gzip_file_extension->Bytes(), (const char*) BifConst::LogAscii::gzip_file_extension->Bytes(),
BifConst::LogAscii::gzip_file_extension->Len() BifConst::LogAscii::gzip_file_extension->Len()
); );
logdir.assign(
(const char*) BifConst::LogAscii::logdir->Bytes(),
BifConst::LogAscii::logdir->Len()
);
} }
bool Ascii::InitFilterOptions() bool Ascii::InitFilterOptions()
@ -344,6 +350,9 @@ bool Ascii::InitFilterOptions()
else if ( strcmp(i->first, "gzip_file_extension") == 0 ) else if ( strcmp(i->first, "gzip_file_extension") == 0 )
gzip_file_extension.assign(i->second); gzip_file_extension.assign(i->second);
else if ( strcmp(i->first, "logdir") == 0 )
logdir.assign(i->second);
} }
if ( ! InitFormatter() ) if ( ! InitFormatter() )
@ -448,6 +457,11 @@ bool Ascii::DoInit(const WriterInfo& info, int num_fields, const threading::Fiel
ext += gzip_file_extension.empty() ? "gz" : gzip_file_extension; ext += gzip_file_extension.empty() ? "gz" : gzip_file_extension;
} }
if ( ! logdir.empty() )
{
fname = logdir.empty() ? fname : logdir + "/" + fname;
}
fname += ext; fname += ext;
bool use_shadow = BifConst::LogAscii::enable_leftover_log_rotation && Info().rotation_interval > 0; bool use_shadow = BifConst::LogAscii::enable_leftover_log_rotation && Info().rotation_interval > 0;

View file

@ -75,6 +75,7 @@ private:
bool use_json; bool use_json;
bool enable_utf_8; bool enable_utf_8;
std::string json_timestamps; std::string json_timestamps;
std::string logdir;
threading::Formatter* formatter; threading::Formatter* formatter;
bool init_options; bool init_options;

View file

@ -16,3 +16,4 @@ const enable_utf_8: bool;
const json_timestamps: JSON::TimestampFormat; const json_timestamps: JSON::TimestampFormat;
const gzip_level: count; const gzip_level: count;
const gzip_file_extension: string; const gzip_file_extension: string;
const logdir: string;