Skip to Content
Mastering Perl, 2nd Edition
book

Mastering Perl, 2nd Edition

by brian d foy
January 2014
Intermediate to advanced
400 pages
9h 23m
English
O'Reilly Media, Inc.
Content preview from Mastering Perl, 2nd Edition

Chapter 12. Logging

Logging records messages from my program so I can watch its progress or later look at what happened. This is much more than warnings or errors from my program, since I can also emit messages when things are going well. Along with configuration, logging is one of the features most often missing from Perl applications, or bolted on as an afterthought. I can easily add logging from the start of development or retrofit a legacy application.

Recording Errors and Other Information

Web applications already have it made. They can send things to STDERR (through whichever mechanism or interface the program might use) and they show up in the web server error log. Other programs have to work harder. In general, logging is not as simple as opening a file, appending some information, and closing the file. That might work if the program won’t run more than once at the same time and definitely finishes before it will run again. For any other case, it’s possible that two runs of the program running at the same time will try to write to the same file. Output buffering and the race for control of the output file means that somebody is going to win and not all of the output may make it into the file.

Logging, however, doesn’t necessarily mean merely adding text to a file. Maybe I want to put the messages into a database, display them on the screen, send them to a system logger (such as syslogd), or more than one of those. I might want to send them directly to my email or pager. Indeed, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Perl Programming, 2nd Edition

Advanced Perl Programming, 2nd Edition

Simon Cozens
Intermediate Perl, 2nd Edition

Intermediate Perl, 2nd Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Mastering Perl

Mastering Perl

brian d foy
Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour

Publisher Resources

ISBN: 9781449364946Errata Page