[dancer-users] Some questions about Logger and format_message in Dancer2

Lennart Hengstmengel lennart at tevreden.nl
Thu Nov 6 13:44:43 GMT 2014


I'm using Dancer2 in a RESTful JSON API. Works like a charm. Made 
everything so much easier! :)

Now I needed to implement some logging, and I noticed that the 
documentation describes some placeholders that haven't been implemented 
yet, like %h (host emitting the request) and %{header}h (value of a 
request header).

I really needed those two so I cloned the repo and implemented these 
myself, which was quite easy. I'll push the changes and create a pull 
request. But I have some questions:

- According to the docs, the (not yet implemented) placeholder %i should 
give the "request id". I'm not sure what that should be? Some kind of 
session id or something?

- lib/Dancer2/Core/Role/Logger.pm:74 :
$level = sprintf( '%5s', $level );
Here $level is padded with spaces if it's shorter than 5 chars. So 
"info" gets an extra space. I'm not sure about the rationale, as 
"warning" has 7 chars so this line seems a bit pointless. (And the extra 
space before "info" makes my OCD play up ;))

- lib/Dancer2/Core/Role/Logger.pm:83 :
return "[" . strftime( $block, localtime(time) ) . "]";
Why is the custom formatted time/date enclosed in brackets? Wouldn't it 
be better to do that in the log_format config directive if you wanted to?

Obviously I'm hesitant to change the behaviour of these last two things 
as that may break stuff (like log parsers)...


More information about the dancer-users mailing list