<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<blockquote type="cite"
cite="mid:99E0B2A7-CFE3-4100-9237-46D468B7C996@univ-lyon2.fr">
<pre class="moz-quote-pre" wrap="">It would be really nice to have a setting like sa_debug_sampling (or sa_debug_ratio, sa_debug_sample, etc.) taking an integer value (eg. 100) that would trigger debug logging for 1 email message every sa_debug_sampling messages (eg. 1 message every 100 messages).
The sampling can be fuzzy, for a sa_debug_sampling value of 100 I would not mind getting a debug output every 90 to 110 messages.
Another way to address that could be time-based with a setting like sa_debug_interval taking an integer value in seconds (eg. 10) that would trigger debug logging for 1 email message every sa_debug_interval seconds (eg. 1 message every 10 secondes).
</pre>
</blockquote>
<p>The implementation of such feature might have an impact on
performance even when it is disabled. The $sa_debug level is used
inside SpamAssassin to decide when to callback registered logging
methods. Without monkeypatching SA, Amavis would have to run SA
with enabled debugging all the time and filter-out dbg-loglines
for non-sample messages afterwards.</p>
<p>With amavis 2.13 you can prototype it yourself. Place a modified
version of Amavislog.pm inside a high-priority @INC directory,
e.g:</p>
<p>
<blockquote type="cite"># diff -u0
/usr/share/perl5/Mail/SpamAssassin/Logger/Amavislog.pm
/etc/perl/Mail/SpamAssassin/Logger/Amavislog.pm<br>
--- /usr/share/perl5/Mail/SpamAssassin/Logger/Amavislog.pm
2023-05-12 00:52:23.000000000 +0200<br>
+++ /etc/perl/Mail/SpamAssassin/Logger/Amavislog.pm
2023-06-26 18:45:41.114752331 +0200<br>
@@ -24 +23,0 @@<br>
- if ($args{debug}) { for (keys %llmap) { $llmap{$_} = 1 if
$llmap{$_} > 1 } }<br>
@@ -32 +31 @@<br>
- my $ll = $self->{llmap}->{$level};<br>
+ my $ll = $self->is_sample(4) ? 1 :
$self->{llmap}{$level};<br>
@@ -37,0 +37,8 @@<br>
+# sampling per amavis child<br>
+sub is_sample {<br>
+ my ($self, $every_nth) = @_;<br>
+ return unless $Amavis::MSGINFO;<br>
+ my $log_id = $Amavis::MSGINFO->log_id;<br>
+ $self->{samples}{$log_id} = 1;<br>
+ return %{$self->{samples}} % $every_nth == 0;<br>
+}<br>
</blockquote>
</p>
</body>
</html>