Whilst the above suggestions all solve the problem at hand, if the amount of stuff you're logging out gets significant it's normally a good idea to switch to using one of the many Perl modules that handle logging in a more complete manner.
Amongst the useful capabilities that a decent logging package (I personally use Log4Perl, but many others exist) are:
- Actual details of configuration can be stored either in the program, or a seperate log configuration file. This allows them to be easily changed.
- Pluggable log dispatch system. This allows you to easily set up a situation where, for example, all messages are logged to a file, a database, and printed to screen, but those which are exceptionally important are actually emailled to someone to deal with.
- Capable of having multiple log-files, so you could have your database errors put into one log and any system failures into another if the two types of error were to be handled by different people.
- Ability to change logging levels on-the-fly. By using a configuration file to control the level of detail of logging it's trivial to switch from 'Standard' levels of logging to 'Debug' when things start going wrong, all without needing to edit code and (in the case of Log4perl at least) potentially without needing to restart the service. The logging-levels can even be changed on a per-logfile basis so you could have the extra detail only when needed.
- Keeps code simple and tidy. With the handling of the errorfile etc. kept in it's own set of external modules your own code is kept nice and simple, free of the kind of errorhandling cruft.
- A robust solution, the more used logging modules are used by a considerable number of people so are generally quite well tested and very unlikely to cause problems unless you're doing some very bizarre things with them.
- Simple interface. Most logging systems try and keep things simple, and provide nice drop-in replacements for die, warn etc.
Sorry if it seems like I am randomly soap-boxing, it's just that I noticed that the usability and power of the logging in the more complex systems that I write has been notably improved since I started to use this module.
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>
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
Want more info? How to link
or How to display code and escape characters
are good places to start.