diff --git a/scripts/base/frameworks/logging/writers/ascii.zeek b/scripts/base/frameworks/logging/writers/ascii.zeek index 483656e578..628cf92a83 100644 --- a/scripts/base/frameworks/logging/writers/ascii.zeek +++ b/scripts/base/frameworks/logging/writers/ascii.zeek @@ -57,7 +57,7 @@ export { ## Default logs to current directory ## Can be redefined to send files into logging directory ## - const logdir = "." &redef; + const logdir = "" &redef; ## Format of timestamps when writing out JSON. By default, the JSON ## formatter will use double values for timestamps which represent the diff --git a/src/logging/writers/ascii/Ascii.cc b/src/logging/writers/ascii/Ascii.cc index 5f1da6d68b..a9e1691376 100644 --- a/src/logging/writers/ascii/Ascii.cc +++ b/src/logging/writers/ascii/Ascii.cc @@ -457,10 +457,17 @@ bool Ascii::DoInit(const WriterInfo& info, int num_fields, const threading::Fiel ext += gzip_file_extension.empty() ? "gz" : gzip_file_extension; } - if ( ! logdir.empty() ) + if ( fname.front() != '/' && ! logdir.empty() ) { - fname = logdir.empty() ? fname : logdir + "/" + fname; - } + string path = logdir; + std::size_t last = path.find_last_not_of('/'); + + if ( last == string::npos ) // Nothing but slashes -- weird but ok... + path = "/"; + else + path.erase(last + 1); + fname = path + "/" + fname; + } fname += ext;