klassa has asked for the wisdom of the Perl Monks concerning the following question:
Now, I already have a repository for the data, and a way to get it there (we have a departmental tool with an XML interface for receiving the data; it also has a web UI, for reporting against collected data). I also have the collection details worked out, in the form of a script template into which I could wrap the contents of each script. It's the obvious approach, and looks like this:
#!/usr/bin/perl -w use strict; use Monitor; eval { Monitor::register($0, @ARGV); ### EXISTING CODE GOES HERE }; if ($@) { my $exc = $@; Monitor::exception($exc); die $exc }
Inside the Monitor module, a BEGIN block would track the start time, and an END block would track the elapsed time and handle the task of posting all of the data to the monitor application. Pretty straightforward stuff. What I don't like, though, is that this template code has to go into every source file... This amount of copy/paste just seems wrong (and lacking in elegance).
A colleague suggested that we should shoot for a way to get it down to a single-line addition to every file: the inclusion of a use Monitor line. He reasoned that we should be able to come up with a way to trap unhandled exceptions, without actually putting the eval everywhere. Basically, the Monitor module would do something to set things up, and then reach back into main:: (e.g.), from its END block, to figure out whether any unhandled exceptions occurred.
Alas, despite playing with this for a quite some time, we couldn't get it worked out. For one thing, $@ only applies after an eval. For another, there doesn't seem to be a foolproof way to even get to $@, given that other modules could have END blocks that fire first, each of which could corrupt it.
So, I come to the monks for guidance...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: logging, to include unhandled exceptions
by ikegami (Patriarch) on Aug 31, 2008 at 01:42 UTC | |
by klassa (Acolyte) on Sep 02, 2008 at 19:20 UTC | |
by ikegami (Patriarch) on Sep 02, 2008 at 19:31 UTC | |
by klassa (Acolyte) on Sep 02, 2008 at 20:10 UTC |