Log::Log4perl::Config::Watch - Detect file changes
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); }
This module helps detecting changes in files. Although it comes with the
Log::Log4perl
distribution, it can be used independly.
The constructor defines the file to be watched and the check interval
in seconds. Subsequent calls to change_detected()
will
check_interval
hasn't elapsed.
perform a physical test on the specified file if the number
of seconds specified in check_interval
have 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: check_interval
allows you to call the function
change_detected()
as often as you like, without paying the performing
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).
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.
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.
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.
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. Comes with all the problems that signal handlers
go along with.
eg::L4pResurrectable, Log::Log4perl, Log::Log4perl::NDC, Log::Log4perl::Config, Log::Log4perl::Appender, Log::Log4perl::Util, Log::Log4perl::Level, Log::Log4perl::Filter, Log::Log4perl::Logger, Log::Log4perl::Layout, Log::Log4perl::JavaMap, Log::Log4perl::FAQ, Log::Log4perl::MDC, Log::Log4perl::Resurrector, Log::Log4perl::DateFormat, Log::Log4perl::Filter::Boolean, Log::Log4perl::Filter::LevelRange, Log::Log4perl::Filter::LevelMatch, Log::Log4perl::Filter::StringMatch, Log::Log4perl::Config::Watch, Log::Log4perl::Config::PropertyConfigurator, Log::Log4perl::Config::DOMConfigurator, Log::Log4perl::Config::BaseConfigurator, Log::Log4perl::JavaMap::FileAppender, Log::Log4perl::JavaMap::RollingFileAppender, Log::Log4perl::JavaMap::NTEventLogAppender, Log::Log4perl::JavaMap::TestBuffer, Log::Log4perl::JavaMap::JDBCAppender, Log::Log4perl::JavaMap::ConsoleAppender, Log::Log4perl::JavaMap::SyslogAppender, Log::Log4perl::Util::Semaphore, Log::Log4perl::Appender::Synchronized, Log::Log4perl::Appender::RRDs, Log::Log4perl::Appender::Screen, Log::Log4perl::Appender::DBI, Log::Log4perl::Appender::TestBuffer, Log::Log4perl::Appender::ScreenColoredLevels, Log::Log4perl::Appender::Socket, Log::Log4perl::Appender::Buffer, Log::Log4perl::Appender::Limit, Log::Log4perl::Appender::File, Log::Log4perl::Appender::TestFileCreeper, Log::Log4perl::Appender::TestArrayBuffer, Log::Log4perl::Appender::String, Log::Log4perl::Layout::PatternLayout, Log::Log4perl::Layout::SimpleLayout, Log::Log4perl::Layout::NoopLayout, Log::Log4perl::Layout::PatternLayout::Multiline
Source Code: Log::Log4perl::Config::Watch
Mike Schilli, <log4perl@perlmeister.com>
Copyright 2003 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.