mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 11:08:20 +00:00
Merge remote branch 'origin/topic/jsiwek/ascii-log-rotate-fix'
* origin/topic/jsiwek/ascii-log-rotate-fix: Change ASCII writer to delay creation of log after rotation until next write. Closes #570.
This commit is contained in:
commit
0d202962bc
2 changed files with 11 additions and 4 deletions
|
@ -216,6 +216,9 @@ bool LogWriterAscii::DoWriteOne(ODesc* desc, LogVal* val, const LogField* field)
|
||||||
bool LogWriterAscii::DoWrite(int num_fields, const LogField* const * fields,
|
bool LogWriterAscii::DoWrite(int num_fields, const LogField* const * fields,
|
||||||
LogVal** vals)
|
LogVal** vals)
|
||||||
{
|
{
|
||||||
|
if ( ! file )
|
||||||
|
DoInit(Path(), NumFields(), Fields());
|
||||||
|
|
||||||
ODesc desc(DESC_READABLE);
|
ODesc desc(DESC_READABLE);
|
||||||
desc.SetEscape(separator, separator_len);
|
desc.SetEscape(separator, separator_len);
|
||||||
|
|
||||||
|
@ -245,19 +248,23 @@ bool LogWriterAscii::DoWrite(int num_fields, const LogField* const * fields,
|
||||||
bool LogWriterAscii::DoRotate(string rotated_path, double open,
|
bool LogWriterAscii::DoRotate(string rotated_path, double open,
|
||||||
double close, bool terminating)
|
double close, bool terminating)
|
||||||
{
|
{
|
||||||
if ( IsSpecial(Path()) )
|
// Don't rotate special files or if there's not one currently open.
|
||||||
// Don't rotate special files.
|
if ( ! file || IsSpecial(Path()) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
file = 0;
|
||||||
|
|
||||||
string nname = rotated_path + ".log";
|
string nname = rotated_path + ".log";
|
||||||
rename(fname.c_str(), nname.c_str());
|
rename(fname.c_str(), nname.c_str());
|
||||||
|
|
||||||
if ( ! FinishedRotation(nname, fname, open, close, terminating) )
|
if ( ! FinishedRotation(nname, fname, open, close, terminating) )
|
||||||
|
{
|
||||||
Error(Fmt("error rotating %s to %s", fname.c_str(), nname.c_str()));
|
Error(Fmt("error rotating %s to %s", fname.c_str(), nname.c_str()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return DoInit(Path(), NumFields(), Fields());
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LogWriterAscii::DoSetBuf(bool enabled)
|
bool LogWriterAscii::DoSetBuf(bool enabled)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# @TEST-EXEC: bro -r %DIR/rotation.trace %INPUT 2>&1 | grep "test" >out
|
# @TEST-EXEC: bro -b -r %DIR/rotation.trace %INPUT 2>&1 | grep "test" >out
|
||||||
# @TEST-EXEC: for i in test.*.log; do printf '> %s\n' $i; cat $i; done >>out
|
# @TEST-EXEC: for i in test.*.log; do printf '> %s\n' $i; cat $i; done >>out
|
||||||
# @TEST-EXEC: btest-diff out
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue