aboutsummaryrefslogtreecommitdiff
path: root/tgsend
diff options
context:
space:
mode:
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);