Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Pr/log serialization sorting #766

Merged
merged 2 commits into from

2 participants

@Ovid

This tiny patch is almost a no-op (I didn't even note it in the CHANGERS). It calls ->Sortkeys(1) when serializing references for the logs. This allows me to have this:

info { b => 1, a => 2, e => 3, d => 4, c => 5};

And have it show up like this in the logs:

{'a' => 2,'b' => 1,'c' => 5,'d' => 4,'e' => 3}

When dealing with complicated data structures (or in my case, when cheating with my tests), it makes it easier to find the data you are looking for.

@bigpresh
Owner

Good call - makes life easier when stuff is dumped in a known order, not somewhat randomly.

Approved!

@bigpresh bigpresh merged commit 991a76b into PerlDancer:devel
@bigpresh
Owner

In fact, it's simple, sensible and harmless enough that I'll merge it without waiting for another approval - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2012
  1. Sort hash keys when serializing references in log messages.

    Ovid authored
    This makes it much easier to find the data you are looking for.
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 1 deletion.
  1. +1 −0  lib/Dancer/Logger.pm
  2. +6 −1 t/11_logger/08_serialize.t
View
1  lib/Dancer/Logger.pm
@@ -25,6 +25,7 @@ sub _serialize {
->Terse(1)
->Purity(1)
->Indent(0)
+ ->Sortkeys(1)
->Dump() :
$_
} @vars;
View
7 t/11_logger/08_serialize.t
@@ -7,7 +7,7 @@ use Test::More import => ['!pass'];
plan skip_all => "Test::Output is needed for this test"
unless Dancer::ModuleLoader->load('Test::Output');
-plan tests => 3;
+plan tests => 4;
use Dancer ':syntax';
set logger => 'Console';
@@ -30,3 +30,8 @@ Test::Output::stderr_like(
'Multiple arguments are okay',
);
+Test::Output::stderr_like(
+ sub { Dancer::Logger::warning( { b => 1, a => 2, e => 3, d => 4, c => 5}) },
+ qr/\[\d+\] warn @.+> {'a' => 2,'b' => 1,'c' => 5,'d' => 4,'e' => 3}/,
+ 'Hash keys are sorted okay',
+);
Something went wrong with that request. Please try again.