Scrappy::Logger(3pm)

πŸ“¦
version 0.94112090 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Scrappy::Logger πŸ’–

okay bestie, gather round, because this is Scrappy::Logger β€” the Scrappy Scraper Event Logging module, a.k.a. the little diary your scraper writes in. it's version 0.94112090 and it lives in the Perl docs as a 3pm page, so like, it's a library, not a command. no cap. πŸŽ€


✨ NAME ✨

Scrappy::Logger β€” Scrappy Scraper Event Logging πŸ’…


🌸 VERSION 🌸

version 0.94112090 β€” yes that's the whole number, she's specific like that. ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the vibe, copy-paste and go:

#!/usr/bin/perl
use Scrappy::Logger;

my  $logger = Scrappy::Logger->new;

    -f 'scraper.log' ?
    $logger->load('scraper.log');
    $logger->write('scraper.log');

    $logger->stash('foo' => 'bar');
    $logger->stash('abc' => [('a'..'z')]);

πŸ‘‘ DESCRIPTION πŸ‘‘

Scrappy::Logger hands you YAML-Based event-log handling for recording the events you bump into while you're out here using the Scrappy framework. it's giving "my scraper keeps a receipts folder and every receipt is YAML." iconic. 🫢


πŸŽ€ ATTRIBUTES πŸŽ€

the following is a list of object attributes available with every Scrappy::Logger instance. every single one, we're not skipping. πŸ’–

  • auto_save β€” this attribute is a boolean, and it decides whether your event data gets auto-saved to the log file whenever it updates. turn it off and you're on your own, bestie, you'll have to write explicitly.
my  $logger = Scrappy::Logger->new;

    $logger->load('scraper.log');

    # turn auto-saving off
    $logger->auto_save(0);
    $logger->event('...', 'yada yada yada');
    $logger->write; # explicit write
  • file β€” this attribute gets/sets the filename of the current event-log file. it's literally just "which file are we yapping into right now."
my  $logger = Scrappy::Logger->new;

    $logger->load('scraper.log');
    $logger->write('scraper.log.bak');
    $logger->file('scraper.log');
  • verbose β€” this attribute is a boolean and it tells the logger to write very detailed logs. she's not being vague, she's being thorough. main character energy fr fr.
my  $logger = Scrappy::Logger->new;
    $logger->verbose(1);

🌈 METHODS 🌈

⭐ load ⭐

the load method reads in an event-log file, and it returns its data in the structure it was saved-in. it gives back exactly what you gave it. periodt.

my  $logger = Scrappy::Logger->new;
my  $data = $logger->load('scraper.log');

⭐ timestamp ⭐

the timestamp method returns the current date/timestamp in string form. and when you feed it a properly formatted date/timestamp, it hands you back a corresponding DateTime object instead. glow-up incoming. ✨

my  $logger = Scrappy::Logger->new;
my  $date = $logger->timestamp;
my  $dt = $logger->timestamp($date);

⭐ info ⭐

the info method captures informational events and returns the event data. just vibes, but logged.

my  $logger = Scrappy::Logger->new;
my  %data = (foo => 'bar', baz => 'xyz');
my  $event = $logger->info('This is an informational message', %data);

    $logger->info('This is an informational message');

⭐ warn ⭐

the warn method captures warning events and returns the event data. like, hmm, something's a little off bestie. πŸ‘€

my  $logger = Scrappy::Logger->new;
my  %data = (foo => 'bar', baz => 'xyz');
my  $event = $logger->warn('This is a warning message', %data);

    $logger->info('This is an warning message');

⭐ error ⭐

the error method captures error events and returns the event data. this is the "it's so over" branch of the log. πŸ’€

my  $logger = Scrappy::Logger->new;
my  %data = (foo => 'bar', baz => 'xyz');
my  $event = $logger->error('This is a n error message', %data);

    $logger->info('This is an error message');

⭐ event ⭐

the event method captures custom events and returns the event data. your app, your rules, your little label. 😌

my  $logger = Scrappy::Logger->new;
my  %data = (foo => 'bar', baz => 'xyz');
my  $event = $logger->event('myapp', 'This is a user-defined message', %data);

    $logger->event('myapp', 'This is a user-defined message');

⭐ write ⭐

the write method writes-out an event-log file. this is the "hitting send" of the whole operation. 🫢

my  $logger = Scrappy::Logger->new;

    $logger->info('This is very cool', 'foo' => 'bar');
    $logger->warn('Somethin aint right here');
    $logger->error('It broke, I cant believe it broke');

    $logger->write('scraper.log');

πŸ’œ AUTHOR πŸ’œ

Al Newkirk <awncorp@cpan.org> 🧚


this software is copyright (c) 2010 by awncorp.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay, go forth and remix. πŸ’–


no cap, that's the whole page, bestie β€” you ate. πŸ’…

perl v5.34.0 Β· 2022-06-17 β€” that's the source/version and the date, right there in the cute sign-off, so we're not leaving the footer out. πŸŽ€ bye pookie! 🌸

πŸ“¦ where this page comes from