aboutsummaryrefslogtreecommitdiff
path: root/tgsend
diff options
context:
space:
mode:
authorGuillermo Ramos2019-06-24 17:40:07 +0200
committerGuillermo Ramos2019-06-24 17:40:25 +0200
commit0e3e79e3d72de5118c74b8515bcffb38e7db8fad (patch)
tree064c55fa83358148b799c67f8f170a5c840ae0ac /tgsend
parent57f8e009519b305294d002784967239e7a41ef5e (diff)
downloadtgutils-0e3e79e3d72de5118c74b8515bcffb38e7db8fad.tar.gz
TgLib.Logger
Diffstat (limited to 'tgsend')
-rwxr-xr-xtgsend7
1 files changed, 5 insertions, 2 deletions
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<fetch_token>;
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);