sub debug {
my ($config, $module, @args) = @_;
- say STDERR "$module: @args" if $config->{setting}{debug};
+ return if not $config->{setting}{debug};
+
+ state $fh; # only open the file once per run
+ if (not defined $fh) {
+ # Ignore errors if the directory doesn't exist.
+ if (not open $fh, '>', "$ENV{HOME}/.config/fcscs/log") {
+ $fh = undef; # a failed open still writes a value to $fh
+ return;
+ }
+ }
+
+ say $fh "$module: @args";
return;
}
my $pid = fork;
defined $pid or die $!;
if ($pid == 0) { # child
- # Disable debug mode as writing will fail with closed STDERR.
- $config->{setting}{debug} = 0;
-
$sub->();
}
exit;
=over
-=item B<debug> enable debug mode (redirect stderr when enabling) (C<0>)
+=item B<debug> enable debug mode, writes to I<~/.config/fcscs/log> (C<0>)
=item B<initial_mode> start in this mode, must be a valid mode mapping (C<\&mapping_mode_url>)