Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Over the past few years, I've been progressively interested in some of the more sophisticated and useful strategies to integrate logging into my Perl scripts. My interest is both for debugging and maintenance purposes and also for capturing the results of my scripts.

But what I have found is that as I integrate logging into my scripts, it is becoming harder and harder to see and follow the logic of the "heavy-lifting" that my scripts are accomplishing...in essence, I am having trouble "seeing the forest for the trees."

My scripts are not continuous-running or long-running scripts; though they often taken many minutes to complete. Many of them are a multitude of scripts that are integrated together using some master control script that doles out the work to the other scripts.

I used to "roll my own" logging so that I could print results to the screen and to log files...but it was tedious and time-consuming to reinvent the wheel every time I wrote a script. So I have, in the last few months, migrated to Log4Perl. It is wonderful and gives me everything I need and a tremendous amount of flexibility...just like it promised to do. I am still a novice and am learing more and more every day about how to use it more effectively.

But with its power comes in vivid colorful obviousness the old problem that I found even with my own home-grown logging: the plethora of logging invocations throughout my code makes it increasingly difficult to follow the real logic of my scripts. The logging invocations are distracting and become "noise" in my logic.

This seems like something is wrong and seems to almost defeat the whole idea of flexible, integrated and pervasive logging in scripts.

So my interest is: How does one balance the effective use of logging while maintaining the sense and view of the intrinsic logic of the scripts being logged? How does one ensure that the logging doesn't become so much "noise" that the original intent of the code is lost?

UPDATE: Thanks to everyone for all the great advice and comments. One thing I didn't note (slipped my mind) is that most of the logging that I use is really not for debugging. Rather I use it to allow me a lot of flexibility in how to capture the script's results. Using, for example, Log4perl I can easily have the output go just to the screen...which I use for most initial debugging and output formatting adjustments, etc...or with simple changes I can have the output got to a log file(s) and to the screen. I can also get only certain types of output to the screen (for example, I can just send notifications when certains stages are processing completed to the screen and a log file and then have all of the details go just to the log file). Even with Log4perl I still tend to do, as one responder apparently does, too...loggings or prints that I ultimately remove when the application script gets into production. That sort of helps me "clean up" the script to regain a sense of the logic and script flow. Anyway, thanks to all of the great feedback. It is comforting to know that I'm not the only that's faced the dilema of balancing code and logging readability.

ack Albuquerque, NM

In reply to Balancing Logging and Code Readability by ack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found