Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (3)
    As of 2020-11-25 16:49 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found