http://qs321.pair.com?node_id=951201

andreas1234567 has asked for the wisdom of the Perl Monks concerning the following question:

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]