58 lines
1.4 KiB
Perl
58 lines
1.4 KiB
Perl
#!perl
|
|
|
|
my $filename = ".revbank.log";
|
|
|
|
sub _log($tag, @message) {
|
|
@message = ("") if not @message;
|
|
|
|
append $filename, map(s/^/now() . " $tag "/rgme, @message), "\n";
|
|
}
|
|
|
|
my %buffer;
|
|
sub hook_abort(@) {
|
|
_log("ABORT");
|
|
}
|
|
sub hook_prompt($class, $cart, $prompt, @) {
|
|
$buffer{prompt} = $prompt;
|
|
}
|
|
|
|
sub hook_input($class, $cart, $input, $split_input, @) {
|
|
$input //= "(UNDEF)";
|
|
$input = "(EMPTY)" if not length $input;
|
|
_log(PROMPT => "$buffer{prompt} >> $input");
|
|
}
|
|
|
|
sub hook_reject($class, $plugin, $reason, $abort, @) {
|
|
_log(REJECT => "[$plugin] $reason");
|
|
}
|
|
|
|
sub hook_retry($class, $plugin, $reason, $abort, @) {
|
|
_log(RETRY => "[$plugin] $reason");
|
|
}
|
|
|
|
sub hook_user_created($class, $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");
|
|
}
|
|
|
|
sub hook_checkout($class, $cart, $username, $transaction_id, @) {
|
|
_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);
|
|
}
|
|
|
|
sub hook_log_info($class, $message, @) {
|
|
_log(INFO => $message);
|
|
}
|