Prepare for future removal of support for unbalanced transactions

Don't worry, that won't happen for at least months. First we'll just log
warnings for a while.
This commit is contained in:
Juerd Waalboer 2022-06-12 21:49:22 +02:00
parent 507d368947
commit 65566349f6
4 changed files with 55 additions and 25 deletions

View file

@ -2,9 +2,11 @@
my $filename = ".revbank.log";
sub _log {
sub _log($tag, @message) {
@message = ("") if not @message;
open my $fh, '>>', $filename or warn "$filename: $!";
print $fh now(), " ", @_, "\n";
print $fh map(s/^/now() . " $tag "/rgme, @message), "\n";
close $fh or warn "$filename: $!";
}
@ -18,28 +20,37 @@ sub hook_prompt($class, $cart, $prompt, @) {
sub hook_input($class, $cart, $input, $split_input, @) {
$input //= "(UNDEF)";
_log("PROMPT $buffer{prompt} >> $input");
$input = "(EMPTY)" if not length $input;
_log(PROMPT => "$buffer{prompt} >> $input");
}
sub hook_reject($class, $plugin, $reason, $abort, @) {
_log("REJECT [$plugin] $reason");
_log(REJECT => "[$plugin] $reason");
}
sub hook_retry($class, $plugin, $reason, $abort, @) {
_log("RETRY [$plugin] $reason");
_log(RETRY => "[$plugin] $reason");
}
sub hook_user_created($class, $username, @) {
_log("NEWUSER $username");
_log(NEWUSER => "$username");
}
sub hook_user_balance($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");
_log(BALANCE => "$transaction_id $user had $old, $lost $delta, now has $new");
}
sub hook_checkout($class, $cart, $username, $transaction_id, @) {
_log("CHECKOUT $transaction_id $_") for map $_->as_loggable, $cart->entries;
_log(CHECKOUT => "$transaction_id $_") for map $_->as_loggable, $cart->entries;
}
sub hook_log_warning($class, $message, @) {
_log(WARNING => $message);
}
sub hook_log_error($class, $message, @) {
_log(ERROR => $message);
}