mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-23 04:19:27 +01:00
Logger: Add milliseconds to timestamp
This commit is contained in:
parent
329709ab4c
commit
a7cedd2354
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user