Appender::Synchronized - Online Linux Manual PageSection : 3
Updated : 2022-01-21
Source : perl v5.34.0
Note : User Contributed Perl Documentation

NAMELog::Log4perl::Appender::Synchronized − Synchronizing other appenders

SYNOPSIS​ use Log::Log4perl qw(:easy); ​ ​ my $conf = qq( ​ log4perl.category = WARN, Syncer ​ ​ # File appender (unsynchronized) ​ log4perl.appender.Logfile = Log::Log4perl::Appender::File ​ log4perl.appender.Logfile.autoflush = 1 ​ log4perl.appender.Logfile.filename = test.log ​ log4perl.appender.Logfile.mode = truncate ​ log4perl.appender.Logfile.layout = SimpleLayout ​ ​ # Synchronizing appender, using the file appender above ​ log4perl.appender.Syncer = Log::Log4perl::Appender::Synchronized ​ log4perl.appender.Syncer.appender = Logfile ​); ​ ​ Log::Log4perl−>init(\$conf); ​ WARN("This message is guaranteed to be complete.");

DESCRIPTIONIf multiple processes are using the same Log::Log4perl appender without synchronization, overwrites might happen. A typical scenario for this would be a process spawning children, each of which inherits the parent's Log::Log4perl configuration. In most cases, you won't need an external synchronisation tool like Log::Log4perl::Appender::Synchronized at all. Log4perl's file appender, Log::Log4perl::Appender::File, for example, provides the syswrite mechanism for making sure that even long log lines won't interleave. Short log lines won't interleave anyway, because the operating system makes sure the line gets written before a task switch occurs. In cases where you need additional synchronization, however, you can use ​Log::Log4perl::Appender::Synchronized as a gateway between your loggers and your appenders. An appender itself, ​Log::Log4perl::Appender::Synchronized just takes two additional arguments: appender Specifies the name of the appender it synchronizes access to. The appender specified must be defined somewhere in the configuration file, not necessarily before the definition of ​Log::Log4perl::Appender::Synchronized. key This optional argument specifies the key for the semaphore that ​Log::Log4perl::Appender::Synchronized uses internally to ensure atomic operations. It defaults to _l4p. If you define more than one Log::Log4perl::Appender::Synchronized appender, it is important to specify different keys for them, as otherwise every new Log::Log4perl::Appender::Synchronized appender will nuke previously defined semaphores. The maximum key length is four characters, longer keys will be truncated to 4 characters \*(-- ​mylongkey1 and mylongkey2 are interpreted to be the same: ​mylo (thanks to David Viner <dviner@yahoo−inc.com> for pointing this out). Log::Log4perl::Appender::Synchronized uses Log::Log4perl::Util::Semaphore internally to perform locking with semaphores provided by the operating system used.

Performance tipsThe Log::Log4perl::Appender::Synchronized serializes access to a protected resource globally, slowing down actions otherwise performed in parallel. Unless specified otherwise, all instances of ​Log::Log4perl::Appender::Synchronized objects in the system will use the same global IPC key _l4p. To control access to different appender instances, it often makes sense to define different keys for different synchronizing appenders. In this way, Log::Log4perl serializes access to each appender instance separately: ​ log4perl.category = WARN, Syncer1, Syncer2 ​ ​ # File appender 1 (unsynchronized) ​ log4perl.appender.Logfile1 = Log::Log4perl::Appender::File ​ log4perl.appender.Logfile1.filename = test1.log ​ log4perl.appender.Logfile1.layout = SimpleLayout ​ ​ # File appender 2 (unsynchronized) ​ log4perl.appender.Logfile2 = Log::Log4perl::Appender::File ​ log4perl.appender.Logfile2.filename = test2.log ​ log4perl.appender.Logfile2.layout = SimpleLayout ​ ​ # Synchronizing appender, using the file appender above ​ log4perl.appender.Syncer1 = Log::Log4perl::Appender::Synchronized ​ log4perl.appender.Syncer1.appender = Logfile1 ​ log4perl.appender.Syncer1.key = l4p1 ​ ​ # Synchronizing appender, using the file appender above ​ log4perl.appender.Syncer2 = Log::Log4perl::Appender::Synchronized ​ log4perl.appender.Syncer2.appender = Logfile2 ​ log4perl.appender.Syncer2.key = l4p2 Without the .key = l4p1 and .key = l4p2 lines, both Synchronized appenders would be using the default _l4p key, causing unnecessary serialization of output written to different files.

Advanced configurationTo configure the underlying Log::Log4perl::Util::Semaphore module in a different way than with the default settings provided by Log::Log4perl::Appender::Synchronized, use the following parameters: ​ log4perl.appender.Syncer1.destroy = 1 ​ log4perl.appender.Syncer1.mode = sub { 0775 } ​ log4perl.appender.Syncer1.uid = hugo ​ log4perl.appender.Syncer1.gid = 100 Valid options are ​destroy (Remove the semaphore on exit), ​mode (permissions on the semaphore), ​uid (uid or user name the semaphore is owned by), and ​gid (group id the semaphore is owned by), Note that mode is usually given in octal and therefore needs to be specified as a perl sub {}, unless you want to calculate what 0755 means in decimal. Changing ownership or group settings for a semaphore will obviously only work if the current user ID owns the semaphore already or if the current user is root. The destroy option causes the current process to destroy the semaphore on exit. Spawned children of the process won't inherit this behavior.

Semaphore user and group IDs with mod_perlSetting user and group IDs is especially important when the Synchronized appender is used with mod_perl. If Log4perl gets initialized by a startup handler, which runs as root, and not as the user who will later use the semaphore, the settings for uid, gid, and mode can help establish matching semaphore ownership and access rights.

DEVELOPMENT NOTESLog::Log4perl::Appender::Synchronized is a composite appender. Unlike other appenders, it doesn't log any messages, it just passes them on to its attached sub-appender. For this reason, it doesn't need a layout (contrary to regular appenders). If it defines none, messages are passed on unaltered. Custom filters are also applied to the composite appender only. They are not applied to the sub-appender. Same applies to appender thresholds. This behaviour might change in the future.

LICENSECopyright 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.

AUTHORPlease 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.
0
Johanes Gumabo
Data Size   :   18,253 byte
man-Log::Log4perl::Appender::Synchronized.3pmBuild   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   4 / 183,951
Visitor ID   :     :  
Visitor IP   :   18.221.160.29   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.

ERROR : Need New Coding :         (parse_manual_page_|249|Log::Log4perl::Appender::Synchronized.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\| )         (htmlprn|149|Log::Log4perl::Appender::Synchronized.3pm|36/37|.el══─{─══. ds --  —  |.el══─{─══. ds -- \|\(em\| )         (parse_manual_page_|249|Log::Log4perl::Appender::Synchronized.3pm|43|br══─}─══|'br══─}─══ )         (htmlprn|149|Log::Log4perl::Appender::Synchronized.3pm|43|'br══─}─══ |'br══─}─══ )         (rof_escape_sequence|91|Log::Log4perl::Appender::Synchronized.3pm|140|\*(-- |characters, longer keys will be truncated to 4 characters \*(-- )