Honorable Monks,
I'm looking for a way to increase the readability of log files.
If a reference to a DateTime object gets dumped, then the output can span multiple lines of relatively uninteresting and confusing output.
Is there a way to override the 'dump' call so that what gets logged is a single line (e.g. $dt->dmy . q{ } .$dt->hms or equivalent)? This would be analogous to the TO_JSON support in JSON::XS.
$ perl -wle 'use Data::Dumper; use DateTime; my $dt = DateTime::->now(
+); print Dumper($dt); print $dt->dmy . q{ } .$dt->hms'
$VAR1 = bless( {
'local_rd_secs' => 44783,
'local_rd_days' => 734534,
'rd_nanosecs' => 0,
'locale' => bless( {
'default_time_format_length' =>
+'medium',
'native_territory' => 'United St
+ates',
'native_language' => 'English',
'native_complete_name' => 'Engli
+sh United States',
'en_language' => 'English',
'id' => 'en_US',
'default_date_format_length' =>
+'medium',
'en_complete_name' => 'English U
+nited States',
'en_territory' => 'United States
+'
}, 'DateTime::Locale::en_US' ),
'local_c' => {
'hour' => 12,
'second' => 23,
'month' => 2,
'quarter' => 1,
'day_of_year' => 32,
'day_of_quarter' => 32,
'minute' => 26,
'day' => 1,
'day_of_week' => 3,
'year' => 2012
},
'utc_rd_secs' => 44783,
'formatter' => undef,
'tz' => bless( {
'name' => 'UTC'
}, 'DateTime::TimeZone::UTC' ),
'utc_year' => 2013,
'utc_rd_days' => 734534,
'offset_modifier' => 0
}, 'DateTime' );
01-02-2012 12:26:23
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
-
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.