Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

You really haven't given all your requirements here, so I apologize if this is a useless suggestion.

I've had success using Data::Dumper or YAML (or its XS replacement YAML::Syck) to dump structures to a file, which is then referenced in the log file. I use a sub that looks something like:

# assumes-> use File::Temp ':POSIX'; for tempnam() # assumes-> use YAML 'Dump'; (or) use YAML::Syck 'Dump'; for Dump() sub dump { my $message = shift; my $structures = scalar @_; # yes, 'scalar' is redudant, but reada +ble # create file in curdir with prefix 'dump.' my ($dump_h, $dump_n) = tempnam('.','dump.'); print $dump_h, Dump($_) for @_; close $dump_h; $message.=sprintf '(%d dumped to "%s")', $structures, $dump_n; }

And would be called something like:

$logger->fatal( dump('Unable to foo, dumping object $foo_doer.', $foo_ +doer) );

The log line would look something like:

20070314 15:09 FATAL: Unable to foo, dumping object $foo_doer.(1 dumpe +d to "dump.foobar1")

And the file "dump.foobar1" would contain the $foo_doer serialization.

You can equally use Data::Dumper or any other serialization module you prefer using this model.

Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re: What is the best way to dump data structures to logfiles? by radiantmatrix
in thread What is the best way to dump data structures to logfiles? by monsieur_champs

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2022-10-06 16:36 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (26 votes). Check out past polls.