package Log; use Milkbone; use File::Path; use strict; use warnings; my $dir = user_file("log"); mkpath($dir); register_hook("msg_in", \&on_msg_in); register_hook("protocol_send_im", \&on_protocol_send_im); register_hook("buddy_in", \&on_buddy_in); register_hook("buddy_out", \&on_buddy_out); sub on_msg_in { my ($day, $month, $year, $hour, $min, $sec) = (localtime)[4, 3, 5, 2, 1, 0]; $year += 1900; $month++; mkdir "$logdir/$ARS{-user}" unless -e "$logdir/$ARS{-user}/; log_item("$logdir/$ARS{-user}/$day-$month-$year", $ARGS{-user} . " ($day-$month-$year $hour:$min:$sec) " . ": $ARGS{-msg} \n"); } sub on_buddy_in { } sub on_buddy_out { } sub on_protocol_send_im { my ($day, $month, $year, $hour, $min, $sec) = (localtime)[4, 3, 5, 2, 1, 0]; $year += 1900; $month++; log_item("$logdir/$ARS{-user}/$day-$month-$year", data("me") . " ($day-$month-$year $hour:$min:$sec) " . ": $ARGS{-msg} \n"); } sub log_item { my ($file, $text) = @_; open(LOG, ">>$file"); print LOG $text; close(LOG); } 1;