revbank/plugins/log

58 lines
1.3 KiB
Perl

#!perl
sub command { NEXT }
my $filename = ".revbank.log";
sub _log {
open my $fh, '>>', $filename or warn "$filename: $!";
print $fh now(), " ", @_, "\n";
close $fh or warn "$filename: $!";
}
my %buffer;
sub hook_abort {
_log("ABORT");
}
sub hook_prompt {
my ($class, $cart, $prompt) = @_;
$buffer{prompt} = $prompt;
}
sub hook_input {
my ($class, $cart, $input, $split_input) = @_;
$input //= "(UNDEF)";
_log("PROMPT $buffer{prompt} >> $input");
}
sub hook_reject {
my ($class, $plugin, $reason, $abort) = @_;
_log("REJECT [$plugin] $reason");
}
sub hook_retry {
my ($class, $plugin, $reason, $abort) = @_;
_log("RETRY [$plugin] $reason");
}
sub hook_user_created {
my ($class, $username) = @_;
_log("NEWUSER $username");
}
sub hook_user_balance {
my ($class, $user, $old, $delta, $new, $transaction_id) = @_;
my $lost = $delta < 0 ? "lost" : "got";
$delta = $delta->abs;
$_ = $_->string("+") for $old, $new;
_log("BALANCE $transaction_id $user had $old, $lost $delta, now has $new");
}
sub hook_checkout {
my ($class, $cart, $username, $transaction_id) = @_;
_log("CHECKOUT $transaction_id $_") for map $_->as_loggable, $cart->entries;
}
sub hook_register {
my ($class, $plugin) = @_;
_log("REGISTER $plugin");
}