From 0e3e79e3d72de5118c74b8515bcffb38e7db8fad Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Mon, 24 Jun 2019 17:40:07 +0200 Subject: TgLib.Logger --- tgsend | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tgsend') diff --git a/tgsend b/tgsend index 10a447a..d4b3445 100755 --- a/tgsend +++ b/tgsend @@ -22,6 +22,7 @@ use FindBin; use lib "$FindBin::Bin/lib"; use TgLib qw; use TgLib::Env qw<$HOME $CONFIG_HOME $CACHE_HOME>; +require TgLib::Logger; my $TOKEN; my $PRETEND; @@ -34,6 +35,8 @@ GetOptions("token=s" => \$TOKEN, "help" => \$HELP); pod2usage(-verbose => $VERBOSE+1) if $HELP or ! @ARGV; +my $logger = TgLib::Logger->new($VERBOSE); + # If token was not specified in CLI, get it from ENV/file $TOKEN ||= fetch_token() or pod2usage(-message => "ERROR: Unable to get bot token ($!).\n", @@ -51,8 +54,8 @@ sub send_message { my $req = HTTP::Request->new("POST", $URI, ["Content-Type", "application/json"], $content); if ($VERBOSE || $PRETEND) { - print STDERR "Sending to $chat_id:\n====\n$TEXT\n====\n"; - print STDERR "Request:\n", Dumper($req), "\n" if $VERBOSE > 1; + $logger->info("Sending to $chat_id:\n====\n$TEXT\n====\n"); + $logger->debug(sprintf "Request:\n%s\n", Dumper($req)); } unless ($PRETEND) { my $resp = $ua->request($req); -- cgit v1.2.3