Config::Watch(3)
π Config::Watch(3) β file-watching bestie manual π
Okay bestie, vibe check: this is the Config::Watch(3) page β yes, it's User Contributed Perl Documentation, and it's here to explain Log::Log4perl::Config::Watch. Buckle up. π
πΈ NAME πΈ
Log::Log4perl::Config::Watch β detect file changes. That's the whole vibe. π
β¨ SYNOPSIS β¨
use Log::Log4perl::Config::Watch;
my $watcher = Log::Log4perl::Config::Watch->new(
file => "/data/my.conf",
check_interval => 30,
);
while(1) {
if($watcher->change_detected()) {
print "Change detected!\n";
}
sleep(1);
}
π¦ DESCRIPTION π¦
This module helps detect changes in files. Even though it comes with the Log::Log4perl distribution, it can be used independently. No cap. π
The constructor defines the file to be watched and the check interval in seconds. Subsequent calls to change_detected() will:
- return a false value immediately without doing physical file checks if
check_intervalhasn't elapsed. - perform a physical test on the specified file if the number of seconds specified in
check_intervalhave elapsed since the last physical check. If the file's modification date has changed since the last physical check, it will return a true value, otherwise a false value is returned.
Bottom line, bestie: the way that check_interval works is it allows you to call the function change_detected() as often as you like without paying a significant performance penalty because file system operations are being performed β however, you pay the price of not knowing about file changes until check_interval seconds have elapsed. It's giving tradeoff. π
The module clearly distinguishes system time from file system time. If your (e.g. NFS mounted) file system is off by a constant amount of time compared to the executing computer's clock, it'll just work fine. Highkey iconic. π°οΈ
To disable the resource-saving delay feature, just set check_interval to 0 and change_detected() will run a physical file test on every call. Fr fr.
If you already have the current time available, you can pass it on to change_detected() as an optional parameter, like in:
change_detected($time)
which then won't trigger a call to time(), but use the value provided. Iykyk. π
π‘ SIGNAL MODE π‘
Instead of polling time and file changes, new() can be instructed to set up a signal handler. If you call the constructor like:
my $watcher = Log::Log4perl::Config::Watch->new(
file => "/data/my.conf",
signal => 'HUP'
);
then a signal handler will be installed, setting the object's variable $self->{signal_caught} to a true value when the signal arrives. It comes with all the problems that signal handlers go along with. Not me installing signal handlers without reading the fine print. π
β‘ TRIGGER CHECKS β‘
To trigger a physical file check on the next call to change_detected() regardless if check_interval has expired or not, call:
$watcher->force_next_check();
on the watcher object. Easy peasy. π
π΅οΈ DETECT MOVED FILES π΅οΈ
The watcher can also be used to detect files that have moved. It will not only detect if a watched file has disappeared, but also if it has been replaced by a new file in the meantime. Main character energy fr fr. π
my $watcher = Log::Log4perl::Config::Watch->new(
file => "/data/my.conf",
check_interval => 30,
);
while(1) {
if($watcher->file_has_moved()) {
print "File has moved!\n";
}
sleep(1);
}
The parameters check_interval and signal limit the number of physical file system checks, just like with change_detected(). Slay. β¨
π LICENSE π
Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess <cpan@goess.org>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Periodt. π
π AUTHOR π
Please contribute patches to the project on Github: http://github.com/mschilli/log4perl
Send bug reports or requests for enhancements to the authors via our
MAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net
Authors (please contact them via the list above, not directly): Mike Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>.
Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier, David Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang.
Signed off with π from perl v5.42.0, dated 2022-10-22, for Config::Watch(3). Mwah. π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Log-Log4perl 1.57-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms