Log4perl Mike Schilli, Yahoo! OSCON, 07/24/2008. Logging – why? Debug during development Go back in time and figure out what happened. Measure performance.

Slides:



Advertisements
Similar presentations
Error HandlingPHPMay-2007 : [#] PHP Error Handling.
Advertisements

IPS of Boston Checks On Demand! ® Welcome! To navigate this presentation, first click in this window, then use the arrow keys on your keyboard. Welcome!
3/17 Dividend Street, Mansfield, 4122, Queensland, Australia phone: web: The SuperCycler A Software.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Week 6: Chapter 6 Agenda Automation of SQL Server tasks using: SQL Server Agent Scheduling Scripting Technologies.
1 Unit & District Tools Phase 1. 2 To access the new Unit and District Tools, you will need to click on the link embedded in the MyScouting Flash page.
1 Generic logging layer for the distributed computing by Gene Van Buren Valeri Fine Jerome Lauret.
Log4perl Mike Schilli, Yahoo! OSCON, 07/24/2008. Logging – why? Debug during development Go back in time and figure out what happened. Measure performance.
Smart Logging With Log4perl Mike Schilli, Yahoo! YAPC, 06/27/2007 Grab A T-Shirt!
Stop Being A Caveman! use Log::Log4perl; by Eric Andreychek
SOFTWARE PRESENTATION ODMS (OPEN SOURCE DOCUMENT MANAGEMENT SYSTEM)
We are partners in learning.. Note: Office 365 works best in Internet Explorer V 9 or above. Some features do not work in PWCS’s Chrome Browser or in.
What to do when you are done. PRINTING WITH PHOTOSHOP.
DB Audit Expert v1.1 for Oracle Copyright © SoftTree Technologies, Inc. This presentation is for DB Audit Expert for Oracle version 1.1 which.
DEMONSTRATION FOR SIGMA DATA ACQUISITION MODULES Tempatron Ltd Data Measurements Division Darwin Close Reading RG2 0TB UK T : +44 (0) F :
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
One to One instructions Installing and configuring samba on Ubuntu Linux to enable Linux to share files and documents with Windows XP.
Map Reduce: Simplified Data Processing On Large Clusters Jeffery Dean and Sanjay Ghemawat (Google Inc.) OSDI 2004 (Operating Systems Design and Implementation)
Advanced User Guide to Outlook and all its features.
Logging with Log4j. Introduction Logging - chronological and systematic record of data processing events in a program. Possible goals: Create an audit.
PHP. Why should we learn web programming? No need write socket programming. - You can forget TCP/IP & OSI layers. - Web server handles socket tasks for.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
0Gold 11 0Gold 11 LapLink Gold 11 Firewall Service How Connections are Created A Detailed Overview for the IT Manager.
LogBox Enterprise Logging Brad Wood
Management Information Systems MS Access MS Access is an application software that facilitates us to create Database Management Systems (DBMS)
Windows Vista Inside Out Chapter 22 - Monitoring System Activities with Event Viewer Last modified am.
In the next step you will enter some data records into the table. This can be done easily using the ‘Data Browser’. The data browser can be accessed via.
1. To start the process, Warehouse Stationery (WSL) will invite you to use The Warehouse Group Supplier Electronic Portal and will send you the link to.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
Microsoft Office Outlook 2013 Microsoft Office Outlook 2013 Courseware # 3252 Lesson 6: Organizing Information.
Prasanna K. Agenda Setting Up the Environment Introduction Extension Essentials Building a Extension Demo Users Build a Banking a Trojan Building the.
An Introduction to Designing and Executing Workflows with Taverna Aleksandra Pawlik materials by: Katy Wolstencroft University of Manchester.
WEIGH STAR A Software for Weighing Systems. Features Weigh STAR is a S/W that is designed for weighing systems. It reads the weight (both Gross Weight.
Privilege separation in Condor Bruce Beckles University of Cambridge Computing Service.
Debugging and Profiling With some help from Software Carpentry resources.
What is Web Site Administration Tool ? WAT Allow you to Configure Web Site With Simple Interface –Manage Users –Manage Roles –Manage Access Rules.
What's New in Kinetic Calendar 2.0 Jack Boespflug Kinetic Data.
First Venture into the Android World Chapter 1 Part 2.
1 Forget Shell Scripts! Mike Schilli, 06/16/2008 Yahoo!
The TANGO Logging Service Status Implementation details Possible enhancements.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
1 © 2005 Cisco Systems, Inc. All rights reserved. Session Number Presentation_ID Cisco Public Cisco Unity Connection Notification Jane Rygg Core Services.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
The Log4E logging plug-in David Gallardo. What is logging good for? Tracing program execution during development Debugging Providing an audit trail for.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
SPI NIGHTLIES Alex Hodgkins. SPI nightlies  Build and test various software projects each night  Provide a nightlies summary page that displays all.
Perl Subroutines User Input Perl on linux Forks and Pipes.
Windows Server 2003 { First Steps and Administration} Benedikt Riedel MCSE + Messaging
SQL Database Management
Development Environment
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Data Virtualization Tutorial: Introduction to SQL Script
Designing For Testability
Chapter 2: System Structures
Contents Default Dancer logging Using Logger::LogReport
Exceptions Lightning Talk on Exceptions MiltonKeynes.pm 12-Jan-2009
Introduction to Events
Structure of Processes
Unreal Engine and C++ We’re finally at a point where we can start working in C++ with Unreal Engine To get everything set up for this properly, we’re going.
Smart Integration Express
Mike Schilli, Yahoo! OSCON, 07/24/2008
How to debug a website using IE F12 tools
Selenium IDE Installation and Use.
Corporate Training Center
Presentation transcript:

Log4perl Mike Schilli, Yahoo! OSCON, 07/24/2008

Logging – why? Debug during development Go back in time and figure out what happened. Measure performance Trace activity on live systems

Why Log4perl and not one of the 20 Logging modules on CPAN? No CPAN dependencies Easy to use, but scales with complexity Unique Features

Log::Log4perl Availability cpan> install Log::Log4perl (Only requires core modules) Included in major Linux distros sudo apt-get install liblog-log4perl Requires Perl or better Windows: ppm package available in ActiveState archives or from log4perl.com

Use Log4perl as a Remote Control to your System.

Log::Log4perl Remote Controls Loggers Layouts Appenders Levels

Log::Log4perl Remote Controls Loggers Layouts Appenders Locate it in the system Format it Write it out Levels Log/Suppress Priority/Level

Log::Log4perl Remote Controls Loggers Layouts Appenders DEBUG “Starting up”; ERROR “Cannot open $file”; “Starting up” => :30:33 Foo.pm-123 Starting up Database Log File … Levels Turn logging on in main or Net::Amazon

Sounds complicated? Actually, it’s easy …

Easy Log4perl #!/usr/bin/perl –w use strict; use Log::Log4perl qw(:easy); DEBUG “Starting up”;

Don’t like macros? Use get_logger() #!/usr/bin/perl –w use strict; use Log::Log4perl qw(get_logger); my $logger = get_logger(); $logger->debug(“Starting up”);

Like it clean? Use Moose! package Ferrari; use Moose; with “MooseX::Log::Log4perl”; sub drive { my($self) $self->log->debug(“Wroom!!”); }

Easy Log4perl #!/usr/bin/perl –w use strict; use Log::Log4perl qw(:easy); DEBUG “Starting up”;

Easy Log4perl $./hello $

Easy Log4perl #!/usr/bin/perl –w use strict; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init( $DEBUG ); DEBUG “Starting up”;

Easy Log4perl $./hello 2008/07/08 18:37:12 Starting up $

Easy Log4perl #!/usr/bin/perl –w use strict; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init( $DEBUG ); DEBUG “Starting up”; # … something happens ERROR “Horrible error!”;

Easy Log4perl $./hello 2008/07/08 18:37:12 Starting up 2008/07/08 18:37:12 Horrible error! $

Easy Log4perl #!/usr/bin/perl –w use strict; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init( $ERROR ); DEBUG “Starting up”; ERROR “Horrible error!”;

Easy Log4perl $./hello 2008/07/08 18:37:12 Horrible error! $

Remote Control #1: Levels

You get the concept: Log Level Configured Message Priority FATAL ERROR WARNING INFO DEBUG TRACE FATAL ERROR WARNING INFO DEBUG TRACE

Chatty configuration Log Level Configured Message Priority FATAL ERROR WARNING INFO DEBUG TRACE

Silent configuration ERROR Log Level Configured Message Priority FATAL ERROR WARNING INFO DEBUG TRACE

Log Levels Choose them wisely –TRACE(“$bytes bytes transferred”); –DEBUG(“HTTP get OK”); –INFO(“Starting up”); –WARN(“HTTP get failed, retrying”); –ERROR(“Out of retries!”); –FATAL(“Panic! Shutting down.”);

Remote Control #2: Layouts

Location-Awareness Log4perl’s Loggers are aware of their location: package Foo; use Log::Log4perl qw(:easy); sub foo { DEBUG “Starting up”; }

Location-Awareness package Foo; use Log::Log4perl qw(:easy); sub foo { DEBUG “Starting up”; } $./hello 2008/07/13 19:32:39 Starting up

Location-Awareness package Foo; use Log::Log4perl qw(:easy); sub foo { DEBUG “Starting up”; } $./hello 637 Foo::foo./Foo.pm-4> Starting up

Location-Awareness package main; use Log::Log4perl (:easy); Log::Log4perl->easy_init({ level => $DEBUG, layout => “%r %M %F-%L> %m%n”, }); Foo::foo(); # unchanged! $./hello 637 Foo::foo./Foo.pm-4> Starting up

Configuration Files If this becomes unwieldy : Log::Log4perl->easy_init({ level => $DEBUG, layout => “%r %M %F-%L>%m%n”, });

Configuration Files #l4p.conf l4p.logger = DEBUG, Screen l4p.appender.Screen = Log::Log4perl::Appender::Screen l4p.appender.Screen.Layout = PatternLayout l4p.appender.Screen.Layout.ConversionPattern = \ %r %M %F-%L> %m%n Log::Log4perl->init( “l4p.conf” );

Advantages of Config Files Can be edited –indepentently of the script –while the script runs –by people without access to the code

Remote Control #3: Categories (Loggers)

Turn on Logging Everywhere Script Modules l4p.logger = DEBUG, Screen

Using Categories l4p.logger.Net.Amazon = \ DEBUG, Screen Net::Amazon Script Modules

Using Categories l4p.logger.main = \ DEBUG, Screen main Net::Amazon Script Modules

Using Categories l4p.logger.main = DEBUG, Screen l4p.logger.Net.Amazon = \ DEBUG, Screen Modules Script Net::Amazon main

Categories #l4p.conf l4p.logger.main = DEBUG, Screen l4p.logger.Net.Amazon = DEBUG, Screen l4p.appender.Screen = Log::Log4perl::Appender::Screen l4p.appender.Screen.Layout = PatternLayout l4p.appender.Screen.Layout.ConversionPattern = \ %r %M %F-%L> %m%n Net::Amazon main

Category Inheritance #l4p.conf l4p.logger.Net = DEBUG, Screen l4p.appender.Screen = Log::Log4perl::Appender::Screen l4p.appender.Screen.Layout = PatternLayout l4p.appender.Screen.Layout.ConversionPattern = \ %r %M %F-%L> %m%n Net::Google Net::Amazon main

Remote Control #5: Appenders

Root Logger #l4p.conf l4p.logger = DEBUG, Screen l4p.appender.Screen = Log::Log4perl::Appender::Screen l4p.appender.Screen.Layout = PatternLayout l4p.appender.Screen.Layout.ConversionPattern = \ %r %M %F-%L> %m%n Net::Google Net::Amazon main

Multiple Appenders #l4p.conf l4p.logger.main = DEBUG, Screen l4p.logger.Net.Amazon = DEBUG, File l4p.appender.Screen = Log::Log4perl::Appender::Screen l4p.appender.Screen.Layout = SimpleLayout l4p.appender.File = Log::Log4perl::Appender::File l4p.appender.File.filename = /var/log/myapp.log l4p.appender.File.Layout = PatternLayout l4p.appender.File.Layout.ConversionPattern = \ %r %M %F-%L> %m%n Net::Amazon main Screen File

Multiple Appenders (different log levels) #l4p.conf l4p.logger.main = DEBUG, Screen l4p.logger.Net.Amazon = ERROR, File l4p.appender.Screen = Log::Log4perl::Appender::Screen l4p.appender.Screen.Layout = SimpleLayout l4p.appender.File = Log::Log4perl::Appender::File l4p.appender.File.filename = /var/log/myapp.log l4p.appender.File.Layout = PatternLayout l4p.appender.File.Layout.ConversionPattern = \ %r %M %F-%L> %m%n Net::Amazon main Screen File

Multiple Appenders #l4p.conf l4p.logger.main = DEBUG, Screen, File l4p.appender.Screen = Log::Log4perl::Appender::Screen l4p.appender.Screen.Layout = SimpleLayout l4p.appender.File = Log::Log4perl::Appender::File l4p.appender.File.filename = /var/log/myapp.log l4p.appender.File.Layout = PatternLayout l4p.appender.File.Layout.ConversionPattern = \ %r %M %F-%L> %m%n Net::Amazon main Screen File

Log4perl Flow Application sends a log message (Category, Priority) Log4perl Configuration decides go/no go, based on Category and Priority Appender Layout ?

Log4perl and Log4j Log::Log4perl ports Log4j to Perl Log4j: de facto Java logging standard, by Ceki Gülcü –Latest development: ‘logback’ Log::Log4perl adds perlisms demanded by users

Log4perl History 0.01 release 2002 Current release 1.17 (07/2008) Authors: Mike Schilli, Kevin Goess Used by major banks, target.com, fedex.com, Yahoo!, Google, … Several CPAN modules support it (e.g. Catalyst, Net::Amazon, …) Every major Linux distro has it (Ubuntu, Suse, Fedora …)

Log4perl Release History

Design Goals Easy to use in small scripts Scales easily with growing architecture Log4perl-enabled CPAN modules can be used with and without Log4perl initialization Optimized for Speed Open Architecture, extensible

Combine Remote Controls Write code once, and L4p-enabled scripts/modules can be used –with any logging configuration you desire –by changing loggers, appenders and layouts independently –similar to dtrace probes No need to change your source code to change the logging behavior

Init and Watch Log::Log4perl->init(“l4p.conf”); Log::Log4perl->init(\$conf_string); Log::Log4perl->init_and_watch(“l4p.conf”, 30); Log::Log4perl->init_and_watch(“l4p.conf”, ‘HUP’ );

Demo

Appenders Appenders are output sinks Get called if a message passes category and level hurdles

Appenders Log::Log4perl::Appender::Screen Log::Log4perl::Appender::File Log::Log4perl::Appender::Socket Log::Log4perl::Appender::DBI Log::Log4perl::Appender::Synchronized Log::Log4perl::Appender::RRDs Log::Dispatch provides even more:

Log::Dispatch Appenders Log::Dispatch::ApacheLog Log::Dispatch::DBI, Log::Dispatch:: , Log::Dispatch:: :MIMELite Log::Dispatch::File Log::Dispatch::FileRotate Log::Dispatch::Screen Log::Dispatch::Syslog, Log::Dispatch::Tk

Example: Rotating Log File Appender Keep 5 days of logfiles, then delete: log4perl.category = WARN, Logfile log4perl.appender.Logfile = Log::Dispatch::FileRotate log4perl.appender.Logfile.filename = test.log log4perl.appender.Logfile.max = 5 log4perl.appender.Logfile.DatePattern = yyyy-MM-dd log4perl.appender.Logfile.TZ = PST log4perl.appender.Logfile.layout = \ Log::Log4perl::Layout::SimpleLayout

Rotating Files Rotating File Appender: –Log::Dispatch::FileRotate –Single request pays for rotation –Rotation runs as particular user External Rotators (e.g. newsyslog ): – recreate flag makes sure file appender adjusts –recreate_check_interval saves on stat() calls

Layouts SimpleLayout $log->debug(“Sending Mail”); DEBUG – Sending Mail log4perl.appender.Screen = \ Log::Log4perl::Appender::Screen log4perl.appender.Screen.layout = SimpleLayout

Layouts PatternLayout $log->debug(“Sending Mail”); 2004/10/17 18:47:25 l4ptest.pl:25> Sending Mail log4perl.appender.Logfile.layout = \ Log::Log4perl::Layout::PatternLayout log4perl.appender.Logfile.layout.ConversionPattern = \ %d %F{1}:%L> %m %n

Layouts PatternLayout %T stack trace %c Category of the logging event. %C Fully qualified package (or class) name of the caller %d Current date in yyyy/MM/dd hh:mm:ss format %F File where the logging event occurred %H Hostname %l calling method + file + line %L Line number within the file where the log statement was issued %m The message to be logged %M Method or function where the logging request was issued %n Newline (OS-independent) %p Priority of the logging event %P pid of the current process %r Number of milliseconds elapsed from program start %x The elements of the NDC stack %X{key} The entry 'key' of the MDC % A literal percent (%) sign

Layouts Still not enough? Write your own: log4perl.PatternLayout.cspec.U = sub { return "UID $<" } … log4perl.appender.Logfile.layout = \ Log::Log4perl::Layout::PatternLayout log4perl.appender.Logfile.layout.ConversionPattern = \ %d %U> %m %n

Speed

Benchmarks 1M/sec suppressed calls 50k/sec logged messages (memory appender) No degradation with subcategories

Avoid Wasting Cycles for { $logger->debug("Element: $_\n"); } if($logger->is_debug()) { for { $logger->debug("Element: $_\n"); }

Dirty Tricks

Resurrect in a Single File The :resurrect target uncomments lines starting with ###l4p : use Log4perl qw(:easy :resurrect); sub foo { # … ###l4p DEBUG “foo was here”; }

Resurrect L4p in all Modules The Log::Log4perl::Resurrector touches all subsequently loaded modules (experimental!): use Log4perl qw(:easy); use Log::Log4perl::Resurrector; use Foo::Bar; # Deploy a module without requiring L4p at all! package Foo::Bar; ###l4p use Log4perl qw(:easy); sub foo { ###l4p DEBUG “This will be resurrected!”; }

The Future

Wouldn’t it be nice … … if all modules on CPAN had a standard logging interface?

Log4perl-enable a CPAN Module package Foo; sub foo { # … do something } 1;

Log4perl-enable a CPAN Module package Foo; use Log::Log4perl qw(:easy); sub foo { # … do something DEBUG “Fooing $bar”; } 1;

… and voila, your CPAN module has a built-in remote.

Be Open Let other people debug your module in a standard way.

Q & A

Thank You! Log::Log4perl Project Page (includes slides of this talk): me: Mike Schilli

Don’t forget to submit a Review! Go to the OSCON schedule, click on this talk and then ‘rate this talk’ Thanks!

Bonus Slides

Advanced Trickery

Infiltrating LWP Ever wondered what LWP is doing behind the scenes? use LWP::UserAgent; use use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($DEBUG); Log::Log4perl->infiltrate_lwp(); my $ua = LWP::UserAgent->new(); my $resp = $ua->request(GET "

Infiltrating LWP Getting LWP to use Log4perl for logging: 2004/10/20 18:36:43 () 2004/10/20 18:36:43 GET /10/20 18:36:43 Not proxied 2004/10/20 18:36:43 () 2004/10/20 18:36:43 read 634 bytes 2004/10/20 18:36:43 read 4096 bytes … 2004/10/20 18:36:43 read 2488 bytes 2004/10/20 18:36:43 Simple response: OK

Pitfalls Beginner’s Pitfalls

Appender Additivity: –Once a lower level logger decides to fire, it will forward the message to its appenders. –It will also forward the message unconditionally to all of its parent logger’s appenders.

Beginner’s Pitfalls Appender Additivity (with dupes) package Net::Amazon; DEBUG(“Debugging!”); log4perl.category = FATAL, Screen log4perl.category.Net.Amazon = DEBUG, Screen log4perl.appender.Screen = \ Log::Log4perl::Appender::Screen log4perl.appender.Screen.layout = SimpleLayout DEBUG - Debugging!

Appender Additivity Net::Amazon Net root DEBUG FATAL Screen Appender File Appender

Beginner’s Pitfalls Appender Additivity (no dupes) package Net::Amazon; DEBUG(“Debugging!”); Q log4perl.category = ERROR, Screen log4perl.category.Net.Amazon = DEBUG, Screen log4perl.additivity.Net.Amazon = 0 log4perl.appender.Screen = \ Log::Log4perl::Appender::Screen log4perl.appender.Screen.layout = SimpleLayout DEBUG – Debugging!

Write Your Own Appender (1) package ColorScreenAppender; = qw(Log::Log4perl::Appender); use Term::ANSIColor; sub new { my($class, %options) my $self = {%options, …}; bless $self, $class; } sub log { my($self, %params) print colored($params{message}, $self->{color}); }

Write Your Own Appender (2) log4perl.logger = INFO, ColorApp log4perl.appender.ColorApp=ColorScreenAppender log4perl.appender.ColorApp.color = red log4perl.appender.ColorApp.layout = SimpleLayout

Filters Last minute chance for Appenders to block More expensive than Level/Category blocking Text/Level Match comes with L4p Write your own custom filters

Filters log4perl.category = INFO, Screen log4perl.filter.MyFilter = \ Log::Log4perl::Filter::StringMatch log4perl.filter.M1.StringToMatch = let this through log4perl.appender.Screen = \ Log::Log4perl::Appender::Screen log4perl.appender.Screen.Filter = MyFilter log4perl.appender.Screen.layout = \ Log::Log4perl::Layout::SimpleLayout

Filters log4perl.filter.M1 = Log::Log4perl::Filter::StringMatch log4perl.filter.M1.StringToMatch = let this through log4perl.filter.M1.AcceptOnMatch = true log4perl.filter.M1 = Log::Log4perl::Filter::LevelMatch log4perl.filter.M1.LevelToMatch = INFO log4perl.filter.M1.AcceptOnMatch = true

Best Practices Don’t provide program name, function name in the message. Use Layouts instead. Log plenty. Don’t worry about space, use rotating log files for chatty output.

What you should log Program starting up, shutting down Function parameters Milestones in request processing Start/end of lenghty operations (e.g. DB access) result of called function (logged in calling function)

What you shouldn’t log Function/method names (although you want parameters) Date Process ID … everything else provided by the layout

Error Handling use Log::Log4perl qw(:easy); do_something or LOGDIE “Horrible error!”; LOGCARP, LOGCLUCK, LOGCONFESS etc. also available.

Best Practices Rolling out new L4p-enabled Modules package My::Module; use Log::Log4perl qw(:easy); sub new { # … } sub foo { DEBUG “I’m here”; # … } sub bar { INFO “Now I’m here”; # … } # Use w/o Log4perl use My::Module; $o = My::Module->new(); $o->foo(); # Log4perl enabled use My::Module; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($DEBUG); $o = My::Module->new(); $o->foo();

Gotchas Avoid ‘append’ on NFS (creating lots of ‘read’ traffic) Don’t put expensive operations into the logger call which are executed before the logger decides Permission issues with rotating file appenders

mod_perl Init() in startup handler Current limitation: One init(). Use init_once() if you’re not sure who inits first.

Combat overlapping Messages Either live with it or –Use the Synchronized appender –Use Appender.File.syswrite=1

Driving Log::Log4perl further Bug Fixes: Submit to New Features: Propose features or send patches New Appenders: Release separately as a module in the Log::Log4perl::Appender::xx namespace on CPAN … or contact me:

Easy Mode Init with Files use Log::Log4perl qw(:easy); Log::Log4perl->easy_init({ level => $DEBUG, file => “>file.log”, category => “Bar::Twix”, });

Multiline Layout Instead of 2007/04/04 23:59:01 This is a message with multiple lines get this: 2007/04/04 23:59:01 This is 2007/04/04 23:59:01 a message with 2007/04/04 23:59:01 multiple lines with PatternLayout::Multiline: log4perl.appender.Logfile. layout = \ Log::Log4perl::Layout::PatternLayout::Multiline log4perl.appender.Logfile.layout.ConversionPattern = %d %m %n

Perl Hooks Add parameters known at init() time log4perl.appender.Logfile.filename = sub { \ “mylog.$$.log” }

Loggers Have a – category (e.g. “Net::Amazon” ) – priority (e.g. $DEBUG ) Take a message (e.g. “Starting” )

Loggers Pass on their message if –logging has been configured for their category ( “Net::Amazon”) or a parent category ( “Net”, “” ) –and (!) the message priority (e.g. $DEBUG ) is greater or equal than the configured log level (e.g. $DEBUG ) for the category

Limit Throughput: Levels and Categories Categories determine which parts of the system are addressed. my $log = get_logger(“Net::Amazon”); or simply package Net::Amazon; DEBUG “…”; Levels indicate the message priority. $log->debug(“Request sent ($bytes bytes)”;

Displaying Logs with Chainsaw Log4j features an XML layout and a socket appender XML output is displayed in a nice GUI called Chainsaw Log::Log4perl also features an XML layout and a socket appender … XML output is also displayed in a nice GUI called Chainsaw!

Displaying Logs with Chainsaw Java / log4j Program Log::Log4perl enabled Perl Script Log::Log4perl::Layout::XML Log::Log4perl::Appender::Socket

Displaying Logs with Chainsaw