Logdir: Change requested by 0xxon, no problem

Suggestion from 0xxon to look at Input Framework inspired this change
This commit is contained in:
Henrik Kramselund Jereminsen 2021-05-15 09:53:51 +02:00 committed by Johanna Amann
parent 6bde33aca7
commit 74561e922f
2 changed files with 11 additions and 4 deletions

View file

@ -57,7 +57,7 @@ export {
## Default logs to current directory ## Default logs to current directory
## Can be redefined to send files into logging 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 ## 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

View file

@ -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; 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; fname += ext;