3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 11:12:42 +01:00

Logger: Add milliseconds to timestamp

This commit is contained in:
Pragmatic Software 2021-07-16 19:08:28 -07:00
parent 329709ab4c
commit a7cedd2354

View File

@ -12,6 +12,8 @@ use PBot::Imports;
use Scalar::Util qw/openhandle/;
use File::Basename;
use File::Copy;
use Time::HiRes qw/gettimeofday/;
use POSIX;
sub new {
my ($class, %args) = @_;
@ -54,7 +56,9 @@ sub log {
my ($self, $text) = @_;
# get current time
my $time = localtime;
my ($sec, $usec) = gettimeofday;
my $time = strftime "%a %b %e %Y %H:%M:%S", localtime $sec;
$time .= sprintf ".%03d", $usec / 1000;
# replace potentially log-corrupting characters (colors, gibberish, etc)
$text =~ s/(\P{PosixGraph})/my $ch = $1; if ($ch =~ m{[\s]}) { $ch } else { sprintf "\\x%02X", ord $ch }/ge;