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

Sawyer X xsawyerx at gmail.com
Sat Nov 8 11:15:51 GMT 2014


On Thu, Nov 6, 2014 at 2:44 PM, Lennart Hengstmengel <lennart at tevreden.nl>
wrote:

> Hi,
>

Hey.


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

Happy to hear! :)


> 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.


First let me thank you for putting the time on this. Well done!



> 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?
>

The Request ID (will be available as "id" method in the next release) is
documented as:

The ID of the request. This allows you to trace a specific request in
loggers, per the string created using "to_string".

The ID of the request is essentially the number of requests run in the
current class.


>
> - 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 ;))
>

OCD++

Go for it!


>
> - 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?
>

Makes sense, yup.


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

I'm not aware of any log parsers for the Dancer2 logs. It's also not an
official format (unlike the common log format in Apache), so I wouldn't
worry.

Submit the PR and let's check it out.

All the best,
Sawyer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20141108/9d8ce34d/attachment.html>


More information about the dancer-users mailing list