Log::A...Rotate(3pm)

πŸ’– NAME πŸ’–

Log::Agent::File::Rotate β€” it's giving rotating logfile set, bestie 🌸


✨ SYNOPSIS ✨

#
# This class is not user-visible.
#
# It is documented only for programmers wishing to inherit
# from it to further extend its behaviour.
#

require Log::Agent::Driver::File;
require Log::Agent::Rotate;
require Log::Agent::File::Rotate;

my $config = Log::Agent::Rotate->make(...);
my $driver = Log::Agent::Driver::File->make(...);
my $fh = Log::Agent::File::Rotate->make("file", $config, $driver);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so picture this: this class represents a rotating logfile and it's the one drivers call on when they wanna rotate their logfiles on a schedule. From the outside? It's lowkey chill β€” it exports a single print routine, exactly like Log::Agent::File::Native does. Same energy, no cap. πŸ’…

But internally?? That's where the main character work happens. It takes the parameters you hand it in a Log::Agent::Rotate object and uses them to transparently close the current logfile and cycle the older logs. Iconic behaviour, honestly.

And before it rotates the current logfile, it emits this string:

*** LOGFILE ROTATED ON <local date>

so the people out there monitoring the file with tail -f actually know what's happening and aren't just sitting there like 😭 wondering why the messages suddenly stopped. Not on our watch. We tell them. Communication queen. πŸŽ€

Its exported interface is:

πŸ’œ make file, config

This is the creation routine, the origin story, the birth of the whole thing. The config object is an instance of Log::Agent::Rotate.

Prints args to the file. But it's not just printing and dipping β€” oh no. After it's printed the data, it monitors the file against the thresholds defined in the configuration, and then possibly rotates the logfiles according to the parameters held in that same configuration object. She checks herself before she wrecks herself.

Now, when the is_alone flag is not set in the configuration, the logfile gets checked every single time a print is issued, just to see if its inode changed. Why, you ask? Because when several instances of the same program using rotating logfiles are running at once, any one of them might decide to cycle the logs at some point in time β€” and that means our opened handle could be pointing at a file that's already been renamed or unlinked. πŸ’€ Sneaky. So yeah, we check. Every time.


πŸ‘‘ AUTHORS πŸ‘‘

Originally written by Raphael Manfredi <Raphael_Manfredi@pobox.com>, and currently maintained by Mark Rogaski <mrogaski@pobox.com>. Legends, both of them, fr fr. 🫢


🌟 SEE ALSO 🌟

Log::Agent::Rotate(3), Log::Agent::Driver::File(3).


perl v5.32.1 β€” 2021-09-27 β€” that's the version and date on this page, bestie, and that's the whole vibe check. You understood the assignment. Slay. βœ¨πŸ’–πŸŽ€