RESOLUTION: Dancer2::Plugin::LogReport - basic setup
Hi all, For the archive/record, see below - all working now. I'd mis-indented the yml config. cheers, Nathan ---------- Forwarded message ---------- Date: 4 January 2017 at 21:18 Subject: Re: [dancer-users] Dancer2::Plugin::LogReport - basic setup Nevermind, I see I indented the yml incorrectly: logger: "LogReport" engines: logger: LogReport: log_format: %a%i%m app_name: AppName dispatchers: logfile: # "default" dispatcher stays open as well type: FILE to: /path/filename.log charset: utf-8 mode: DEBUG now works! And I see that adding the dispatcher line in a test harness lets me write errors to a file rather than stderr too. Brilliant! thanks, Nathan On 4 January 2017 at 19:51, Nathan Bailey <web@ <web@polynate.net>...> wrote:
On 4 January 2017 at 19:12, Andrew Beverley <andy@ <andy@andybev.com>...> wrote:
On Wed, 4 Jan 2017 Nathan Bailey wrote:
1. Add logging information to my yml
Yes, although if you just want to test it initially, then you don't need any config and any messages will go to STDERR (I think).
They happily print to STDERR, they just don't print to the log file :-)
I have: # The log level for this environment. Log warning and error messages* [ presumably this doesn't conflict with the LogReport log levels? ]* log: 'info'
logger: "LogReport"
engines: logger: LogReport: log_format: %a%i%m app_name: AppName dispatchers: logfile: # "default" dispatcher stays open as well type: FILE to: /path/filename.log charset: utf-8 mode: DEBUG
2. Add use Log::Report ();
This is no longer needed (sorry, I thought the docs had been updated).
Okay, so I just have: use Dancer2; ... use Dancer2::Plugin::LogReport mode => 'DEBUG'; # '3' or 'DEBUG'
in my main route handler module.
With this config, nothing is being written to my log file (ie. normal 'info' messages that were getting written with: logger: "File"
engines: logger: File: log_dir: "/path" file_name: "filename.log" (now removed and replaced with above) are no longer getting written. I have a 'trace' and 'info' in a non-Dancer module that is writing to stderr.
Log::Report maintains some global space that all messages go to. When a
message is logged (regardless of where it is logged from) that will trigger the logging code in the Dancer plugin. The Dancer plugin knows your config, so it all Just Works.
Nifty! Presumably module-based unit tests need to include Log::Report with some suitable config/dispatcher?
thanks, Nathan
Hi all (especially Andy :-) What are you supposed to put in your non-main route handlers? use Dancer2::Plugin::LogReport mode => 'DEBUG'; (like main route handler); OR use Log::Report; (like other modules) I assume the later, however in all cases (with none or either of the above), I had an error that Log::Report wouldn't report, ie. I had to change my environment.yml back to logger: "File" to see it. It was a missing dependency - I'd started using a function that I hadn't use'd the module for. 'File' wrote: [AppName::Module:PID] error @2017-01-05 14:47:42> Route exception: Undefined subroutine &Mod::Mod::sub called at path/file.pm line 254. in /Library/Perl/5.18/Dancer2/Core/App.pm l. 1441 in the log files, but 'LogReport' wrote nothing. -N On 5 January 2017 at 09:30, Nathan Bailey <web@polynate.net> wrote:
Hi all, For the archive/record, see below - all working now. I'd mis-indented the yml config.
cheers, Nathan
---------- Forwarded message ---------- Date: 4 January 2017 at 21:18 Subject: Re: [dancer-users] Dancer2::Plugin::LogReport - basic setup
Nevermind, I see I indented the yml incorrectly: logger: "LogReport"
engines: logger: LogReport: log_format: %a%i%m app_name: AppName dispatchers: logfile: # "default" dispatcher stays open as well type: FILE to: /path/filename.log charset: utf-8 mode: DEBUG
now works!
And I see that adding the dispatcher line in a test harness lets me write errors to a file rather than stderr too.
Brilliant!
thanks, Nathan
On 4 January 2017 at 19:51, Nathan Bailey <web@ <web@polynate.net>...> wrote:
On 4 January 2017 at 19:12, Andrew Beverley <andy@ <andy@andybev.com>...> wrote:
On Wed, 4 Jan 2017 Nathan Bailey wrote:
1. Add logging information to my yml
Yes, although if you just want to test it initially, then you don't need any config and any messages will go to STDERR (I think).
They happily print to STDERR, they just don't print to the log file :-)
I have: # The log level for this environment. Log warning and error messages* [ presumably this doesn't conflict with the LogReport log levels? ]* log: 'info'
logger: "LogReport"
engines: logger: LogReport: log_format: %a%i%m app_name: AppName dispatchers: logfile: # "default" dispatcher stays open as well type: FILE to: /path/filename.log charset: utf-8 mode: DEBUG
2. Add use Log::Report ();
This is no longer needed (sorry, I thought the docs had been updated).
Okay, so I just have: use Dancer2; ... use Dancer2::Plugin::LogReport mode => 'DEBUG'; # '3' or 'DEBUG'
in my main route handler module.
With this config, nothing is being written to my log file (ie. normal 'info' messages that were getting written with: logger: "File"
engines: logger: File: log_dir: "/path" file_name: "filename.log" (now removed and replaced with above) are no longer getting written. I have a 'trace' and 'info' in a non-Dancer module that is writing to stderr.
Log::Report maintains some global space that all messages go to. When a
message is logged (regardless of where it is logged from) that will trigger the logging code in the Dancer plugin. The Dancer plugin knows your config, so it all Just Works.
Nifty! Presumably module-based unit tests need to include Log::Report with some suitable config/dispatcher?
thanks, Nathan
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On Thu, 5 Jan 2017 Nathan Bailey wrote:
Hi all (especially Andy :-)
Hi Nathan :)
What are you supposed to put in your non-main route handlers? use Dancer2::Plugin::LogReport mode => 'DEBUG'; (like main route handler); OR use Log::Report; (like other modules)
It depends if you want to use the "special" Dancer-specific keywords (such as process and success). If you don't, I would just use Log::Report;
I assume the later, however in all cases (with none or either of the above), I had an error that Log::Report wouldn't report, ie. I had to change my environment.yml back to logger: "File" to see it. It was a missing dependency - I'd started using a function that I hadn't use'd the module for.
'File' wrote: [AppName::Module:PID] error @2017-01-05 14:47:42> Route exception: Undefined subroutine &Mod::Mod::sub called at path/file.pm line 254. in /Library/Perl/5.18/Dancer2/Core/App.pm l. 1441
in the log files, but 'LogReport' wrote nothing.
I have to admit that I'd never tried using the module in such a way. I've just tried now, and I see what you mean. A very quick debug shows Dancer calling the Log::Report plugin (as it should) but with different parameters than it does for the main route handler. Strangely it seems to be passing details of a 404 error for the page that generates the exception. I don't have time to look at it right now; I'll make some time later, but if you want to have a look yourself in the meantime, then the key part of the plugin is in Plugin/LogReport.pm in $dsl->hook (init_error ... just after on_plugin_import; Andy
On Thu, 5 Jan 2017 Nathan Bailey <web@polynate.net> wrote:
Hi all (especially Andy :-)
Sorry for the delay on this Nathan.
What are you supposed to put in your non-main route handlers? use Dancer2::Plugin::LogReport mode => 'DEBUG'; (like main route handler); OR use Log::Report; (like other modules)
I can now say that it /should/ be the same as any other route handlers. So wherever you have: use Dancer2; You should also have: use Dancer2::Plugin::LogReport ... Although if you're using the same appname (appname => ...) then you only need to use Log::Report. The reason being that otherwise the required logging hook isn't inserted into that particular app. However, there is a problem with the way the current version of the plugin works, which means that the correct DSL isn't always available to it. This will cause some unexpected behaviour. I'm working on a fix at the moment. Andy
On Tue, 7 Feb 2017 Andrew Beverley <andy@andybev.com> wrote:
On Thu, 5 Jan 2017 Nathan Bailey <web@polynate.net> wrote:
Hi all (especially Andy :-)
Sorry for the delay on this Nathan.
What are you supposed to put in your non-main route handlers? use Dancer2::Plugin::LogReport mode => 'DEBUG'; (like main route handler); OR use Log::Report; (like other modules)
I can now say that it /should/ be the same as any other route handlers. So wherever you have:
use Dancer2;
You should also have:
use Dancer2::Plugin::LogReport ...
Although if you're using the same appname (appname => ...) then you only need to use Log::Report.
The reason being that otherwise the required logging hook isn't inserted into that particular app.
However, there is a problem with the way the current version of the plugin works, which means that the correct DSL isn't always available to it. This will cause some unexpected behaviour. I'm working on a fix at the moment.
Fix included in aforementioned v1.19 Log::Report release. Let me know if you run into any other problems. Regards, Andy
participants (2)
-
Andrew Beverley -
Nathan Bailey