Remove LogAscii::logdir (6.1 deprecation)

This commit is contained in:
Tim Wojtulewicz 2023-06-02 11:05:35 +02:00 committed by Tim Wojtulewicz
parent 0110c15ee2
commit 531276cfe0
9 changed files with 26 additions and 113 deletions

View file

@ -54,14 +54,6 @@ 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;
## Define the default logging directory. If empty, logs are written
## to the current working directory.
##
## This setting is superseded by :zeek:see:`Log::default_logdir`. The
## latter applies to all file writers and also interacts better with
## log rotation.
const logdir = "" &redef &deprecated="Remove in v6.1. Use 'Log::default_logdir'.";
## 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

@ -264,12 +264,6 @@ void Ascii::InitConfigOptions()
gzip_file_extension.assign((const char*)BifConst::LogAscii::gzip_file_extension->Bytes(), gzip_file_extension.assign((const char*)BifConst::LogAscii::gzip_file_extension->Bytes(),
BifConst::LogAscii::gzip_file_extension->Len()); BifConst::LogAscii::gzip_file_extension->Len());
// Remove in v6.1: LogAscii::logdir should be gone in favor
// of using Log::default_logdir.
logdir.assign((const char*)BifConst::LogAscii::logdir->Bytes(),
BifConst::LogAscii::logdir->Len());
if ( logdir.empty() )
logdir = zeek::id::find_const<StringVal>("Log::default_logdir")->ToStdString(); logdir = zeek::id::find_const<StringVal>("Log::default_logdir")->ToStdString();
} }
@ -379,15 +373,6 @@ 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 )
{
// This doesn't play nice with leftover log rotation
// and log rotation in general. There's no documentation
// or a test for this specifically, so deprecate it.
reporter->Deprecation("Remove in v6.1. Per writer logdir is deprecated.");
logdir.assign(i->second);
}
} }
if ( ! InitFormatter() ) if ( ! InitFormatter() )
@ -763,17 +748,13 @@ static std::vector<LeftoverLog> find_leftover_logs()
auto prefix_len = strlen(shadow_file_prefix); auto prefix_len = strlen(shadow_file_prefix);
auto default_logdir = zeek::id::find_const<StringVal>("Log::default_logdir")->ToStdString(); auto default_logdir = zeek::id::find_const<StringVal>("Log::default_logdir")->ToStdString();
// Find any .shadow files within LogAscii::logdir, Log::default_logdir // Find any .shadow files within Log::default_logdir or otherwise search in
// or otherwise search in the current working directory. // the current working directory.
auto logdir = zeek::filesystem::current_path(); auto logdir = zeek::filesystem::current_path();
if ( ! default_logdir.empty() ) if ( ! default_logdir.empty() )
logdir = zeek::filesystem::absolute(default_logdir); logdir = zeek::filesystem::absolute(default_logdir);
// Remove LogAscii::logdir fallback in v6.1.
if ( BifConst::LogAscii::logdir->Len() > 0 )
logdir = zeek::filesystem::absolute(BifConst::LogAscii::logdir->ToStdString());
auto d = opendir(logdir.string().c_str()); auto d = opendir(logdir.string().c_str());
struct dirent* dp; struct dirent* dp;

View file

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

View file

@ -1,2 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/rotate-ascii-logdir-leftover-log-rotation-stale-shadow-files.zeek, line 20: deprecated (LogAscii::logdir): Remove in v6.1. Use 'Log::default_logdir'.

View file

@ -1,16 +1,15 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
test.2011-03-07-03-00-05.log test 11-03-07_03.00.05 11-03-07_04.00.05 0 ascii .<...>/test.2011-03-07-03-00-05.log test 11-03-07_03.00.05 11-03-07_04.00.05 0 ascii
test.2011-03-07-04-00-05.log test 11-03-07_04.00.05 11-03-07_05.00.05 0 ascii .<...>/test.2011-03-07-04-00-05.log test 11-03-07_04.00.05 11-03-07_05.00.05 0 ascii
test.2011-03-07-05-00-05.log test 11-03-07_05.00.05 11-03-07_06.00.05 0 ascii .<...>/test.2011-03-07-05-00-05.log test 11-03-07_05.00.05 11-03-07_06.00.05 0 ascii
test.2011-03-07-06-00-05.log test 11-03-07_06.00.05 11-03-07_07.00.05 0 ascii .<...>/test.2011-03-07-06-00-05.log test 11-03-07_06.00.05 11-03-07_07.00.05 0 ascii
test.2011-03-07-07-00-05.log test 11-03-07_07.00.05 11-03-07_08.00.05 0 ascii .<...>/test.2011-03-07-07-00-05.log test 11-03-07_07.00.05 11-03-07_08.00.05 0 ascii
test.2011-03-07-08-00-05.log test 11-03-07_08.00.05 11-03-07_09.00.05 0 ascii .<...>/test.2011-03-07-08-00-05.log test 11-03-07_08.00.05 11-03-07_09.00.05 0 ascii
test.2011-03-07-09-00-05.log test 11-03-07_09.00.05 11-03-07_10.00.05 0 ascii .<...>/test.2011-03-07-09-00-05.log test 11-03-07_09.00.05 11-03-07_10.00.05 0 ascii
test.2011-03-07-10-00-05.log test 11-03-07_10.00.05 11-03-07_11.00.05 0 ascii .<...>/test.2011-03-07-10-00-05.log test 11-03-07_10.00.05 11-03-07_11.00.05 0 ascii
test.2011-03-07-11-00-05.log test 11-03-07_11.00.05 11-03-07_12.00.05 0 ascii .<...>/test.2011-03-07-11-00-05.log test 11-03-07_11.00.05 11-03-07_12.00.05 0 ascii
test.2011-03-07-12-00-05.log test 11-03-07_12.00.05 11-03-07_12.59.55 1 ascii .<...>/test.2011-03-07-12-00-05.log test 11-03-07_12.00.05 11-03-07_12.59.55 1 ascii
warning in <...>/rotate-ascii-logdir-leftover-log-rotation.zeek, line 22: deprecated (LogAscii::logdir): Remove in v6.1. Use 'Log::default_logdir'. > logs/test.2011-03-07-03-00-05.log
> test.2011-03-07-03-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -22,7 +21,7 @@ warning in <...>/rotate-ascii-logdir-leftover-log-rotation.zeek, line 22: deprec
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1024 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1024
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 0 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 0
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-04-00-05.log > logs/test.2011-03-07-04-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -34,7 +33,7 @@ XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 0
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1025 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1025
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 1 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 1
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-05-00-05.log > logs/test.2011-03-07-05-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -46,7 +45,7 @@ XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 1
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1026 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1026
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 2 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 2
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-06-00-05.log > logs/test.2011-03-07-06-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -58,7 +57,7 @@ XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 2
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1027 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1027
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 3 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 3
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-07-00-05.log > logs/test.2011-03-07-07-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -70,7 +69,7 @@ XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 3
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1028 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1028
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 4 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 4
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-08-00-05.log > logs/test.2011-03-07-08-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -82,7 +81,7 @@ XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 4
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1029 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1029
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 5 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 5
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-09-00-05.log > logs/test.2011-03-07-09-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -94,7 +93,7 @@ XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 5
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1030 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1030
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 6 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 6
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-10-00-05.log > logs/test.2011-03-07-10-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -106,7 +105,7 @@ XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 6
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1031 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1031
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 7 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 7
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-11-00-05.log > logs/test.2011-03-07-11-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)
@ -118,7 +117,7 @@ XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 7
XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1032 XXXXXXXXXX.XXXXXX 10.0.0.1 20 10.0.0.2 1032
XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 8 XXXXXXXXXX.XXXXXX 10.0.0.2 20 10.0.0.3 8
#close XXXX-XX-XX-XX-XX-XX #close XXXX-XX-XX-XX-XX-XX
> test.2011-03-07-12-00-05.log > logs/test.2011-03-07-12-00-05.log
#separator \x09 #separator \x09
#set_separator , #set_separator ,
#empty_field (empty) #empty_field (empty)

View file

@ -1,6 +1,6 @@
# #
# @TEST-EXEC: mkdir logdir # @TEST-EXEC: mkdir logdir
# @TEST-EXEC: zeek -b %INPUT LogAscii::logdir=logdir # @TEST-EXEC: zeek -b %INPUT Log::default_logdir=logdir
# @TEST-EXEC: cat logdir/ssh.log | grep -v PREFIX.*20..- >ssh-filtered.log # @TEST-EXEC: cat logdir/ssh.log | grep -v PREFIX.*20..- >ssh-filtered.log
# @TEST-EXEC: btest-diff ssh-filtered.log # @TEST-EXEC: btest-diff ssh-filtered.log

View file

@ -1,34 +0,0 @@
# @TEST-DOC: Test that .shadow files are picked up from LogAscii::logdir.
# @TEST-EXEC: mkdir logs
# @TEST-EXEC: echo ".log" >> logs/.shadow.conn.log
# @TEST-EXEC: echo "my_rotation_postprocessor" >> logs/.shadow.conn.log
# @TEST-EXEC: echo "leftover conn log" > logs/conn.log
# @TEST-EXEC: echo ".log" >> logs/.shadow.dns.log
# @TEST-EXEC: echo "my_rotation_postprocessor" >> logs/.shadow.dns.log
# @TEST-EXEC: echo "leftover dns log" > logs/dns.log
# @TEST-EXEC: zeek -b %INPUT > out
# @TEST-EXEC: ! test -f logs/.shadow.conn.log
# @TEST-EXEC: ! test -f logs/conn.log
# @TEST-EXEC: ! test -f logs/.shadow.dns.log
# @TEST-EXEC: ! test -f logs/dns.log
# Ensure rotated logs ends-up in the current working directory: This may change in the future.
# @TEST-EXEC: cat ./conn-*.log ./dns-*.log > logs.cat
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff out
# @TEST-EXEC: btest-diff logs.cat
module GLOBAL;
function my_rotation_postprocessor(info: Log::RotationInfo) : bool
{
print fmt("running my rotation postprocessor for path '%s'", info$path);
return T;
}
redef LogAscii::logdir = "./logs";
redef LogAscii::enable_leftover_log_rotation = T;
redef Log::default_rotation_interval = 1hr;
redef Log::default_rotation_postprocessor_cmd = "echo";

View file

@ -1,23 +0,0 @@
# @TEST-DOC: Test that stale .shadow files are removed from LogAscii::logdir.
# @TEST-EXEC: mkdir logs
# @TEST-EXEC: echo ".log" >> logs/.shadow.conn.log
# @TEST-EXEC: echo "my_rotation_postprocessor" >> logs/.shadow.conn.log
# @TEST-EXEC: zeek -b %INPUT > out 2>&1
# @TEST-EXEC: ! test -f logs/.shadow.conn.log
# @TEST-EXEC: TEST_DIFF_CANONIFIER='$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-remove-timestamps' btest-diff out
module GLOBAL;
function my_rotation_postprocessor(info: Log::RotationInfo) : bool
{
print fmt("running my rotation postprocessor for path '%s'", info$path);
return T;
}
redef LogAscii::logdir = "./logs";
redef LogAscii::enable_leftover_log_rotation = T;
redef Log::default_rotation_interval = 1hr;
redef Log::default_rotation_postprocessor_cmd = "echo";

View file

@ -2,7 +2,7 @@
# @TEST-EXEC: mkdir logs # @TEST-EXEC: mkdir logs
# @TEST-EXEC: zeek -b -r ${TRACES}/rotation.trace %INPUT >zeek.out 2>&1 # @TEST-EXEC: zeek -b -r ${TRACES}/rotation.trace %INPUT >zeek.out 2>&1
# @TEST-EXEC: grep "test" zeek.out | sort >out # @TEST-EXEC: grep "test" zeek.out | sort >out
# @TEST-EXEC: for i in `ls test.*.log | sort`; do printf '> %s\n' $i; cat $i; done >>out # @TEST-EXEC: for i in `ls logs/test.*.log | sort`; do printf '> %s\n' $i; cat $i; done >>out
# @TEST-EXEC: TEST_DIFF_CANONIFIER='$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-remove-timestamps' btest-diff out # @TEST-EXEC: TEST_DIFF_CANONIFIER='$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-remove-timestamps' btest-diff out
module Test; module Test;
@ -19,8 +19,8 @@ export {
} &log; } &log;
} }
redef LogAscii::logdir = "./logs";
redef LogAscii::enable_leftover_log_rotation = T; redef LogAscii::enable_leftover_log_rotation = T;
redef Log::default_logdir = "./logs";
redef Log::default_rotation_interval = 1hr; redef Log::default_rotation_interval = 1hr;
redef Log::default_rotation_postprocessor_cmd = "echo"; redef Log::default_rotation_postprocessor_cmd = "echo";