Dear all, How can I get the log object? (outside of a specific route) I have this Dancer2 application that is an interface to a backend. If I could handover the Dancer2 log object to the backend, it could write to the same log. What I would like to do is something like: |use Dancer2;|| || ||my $dancer2_log = XXX->get_dancer2_logger;|| || ||my $backend_environment = Backend::Env->new({|| || log => $dancer2_log,|| ||});|||| || ||get '/' => sub {|| || my $env = $env; ... |Is it possible to obtain the log object somehow, or do I have to instantiate Dancer2::Core::Role::Logger myself, and hand it all the config information myself? Kind regards, Arjan.
On Sun, 2015-08-23 at 12:17 -0400, Arjan Widlak wrote:
How can I get the log object? (outside of a specific route)
I have this Dancer2 application that is an interface to a backend. If I could handover the Dancer2 log object to the backend, it could write to the same log.
Sorry, I don't know the answer to your direct question, but you might want to consider using Dancer2::Plugin::LogReport and Dancer2::Logger::LogReport That way everything in your application will write to the same logger, which can also be written to in any other application/backend, just by using Log::Report. Log::Report also has the advantage of having many logging backends, which can be configured/filtered as required for your application deployment. There's still a bit of development work to do on the plugin; once that's complete I'll be posting some more details here. Andy
Hi Andy, Thanx for your reply. I've just read the documentation and I can see the use of the plugin. However I would have the same question: how can I access the log object and pass a reference to another object? (outside of a route) Kind regards, Arjan. On 23-08-15 12:39, Andrew Beverley wrote:
On Sun, 2015-08-23 at 12:17 -0400, Arjan Widlak wrote:
How can I get the log object? (outside of a specific route)
I have this Dancer2 application that is an interface to a backend. If I could handover the Dancer2 log object to the backend, it could write to the same log. Sorry, I don't know the answer to your direct question, but you might want to consider using Dancer2::Plugin::LogReport and Dancer2::Logger::LogReport
That way everything in your application will write to the same logger, which can also be written to in any other application/backend, just by using Log::Report.
Log::Report also has the advantage of having many logging backends, which can be configured/filtered as required for your application deployment.
There's still a bit of development work to do on the plugin; once that's complete I'll be posting some more details here.
Andy
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On Sun, 2015-08-23 at 13:09 -0400, Arjan Widlak wrote:
That way everything in your application will write to the same logger, which can also be written to in any other application/backend, just by using Log::Report.
Thanx for your reply. I've just read the documentation and I can see the use of the plugin. However I would have the same question: how can I access the log object and pass a reference to another object? (outside of a route)
You don't need to access the log object. In your other object you just do (for example): use Log::Report; trace "This will be logged as a debug string"; warning "This will be logged as a warning"; The above lines will be logged in exactly the same way as any other logging in your Dancer2 application, as long as you're using the Dancer2::Logger::LogReport logging backend. Andy
Dear Andy, I can imagine how this works, within a Dancer2 application. But I'm talking about a class that doesn't have a "use Dancer2" statement. Or are you saying: just have both applications use Log::Report and configure them to log to the same file? Kind regards, Arjan On 23-08-15 18:03, Andrew Beverley wrote:
On Sun, 2015-08-23 at 13:09 -0400, Arjan Widlak wrote:
That way everything in your application will write to the same logger, which can also be written to in any other application/backend, just by using Log::Report. Thanx for your reply. I've just read the documentation and I can see the use of the plugin. However I would have the same question: how can I access the log object and pass a reference to another object? (outside of a route) You don't need to access the log object. In your other object you just do (for example):
use Log::Report;
trace "This will be logged as a debug string"; warning "This will be logged as a warning";
The above lines will be logged in exactly the same way as any other logging in your Dancer2 application, as long as you're using the Dancer2::Logger::LogReport logging backend.
Andy
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Perhaps I should rephrase the question. Suppose Dancer2 would not export all these keywords, how would I get a reference to the logger - or any other - object? (outside of a route) On 23-08-15 20:17, Arjan Widlak wrote:
Dear Andy,
I can imagine how this works, within a Dancer2 application. But I'm talking about a class that doesn't have a "use Dancer2" statement. Or are you saying: just have both applications use Log::Report and configure them to log to the same file?
Kind regards, Arjan
On 23-08-15 18:03, Andrew Beverley wrote:
On Sun, 2015-08-23 at 13:09 -0400, Arjan Widlak wrote:
That way everything in your application will write to the same logger, which can also be written to in any other application/backend, just by using Log::Report. Thanx for your reply. I've just read the documentation and I can see the use of the plugin. However I would have the same question: how can I access the log object and pass a reference to another object? (outside of a route) You don't need to access the log object. In your other object you just do (for example):
use Log::Report;
trace "This will be logged as a debug string"; warning "This will be logged as a warning";
The above lines will be logged in exactly the same way as any other logging in your Dancer2 application, as long as you're using the Dancer2::Logger::LogReport logging backend.
Andy
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On Sun, 2015-08-23 at 20:17 -0400, Arjan Widlak wrote:
You don't need to access the log object. In your other object you just do (for example):
use Log::Report;
trace "This will be logged as a debug string"; warning "This will be logged as a warning";
The above lines will be logged in exactly the same way as any other logging in your Dancer2 application, as long as you're using the Dancer2::Logger::LogReport logging backend.
I can imagine how this works, within a Dancer2 application. But I'm talking about a class that doesn't have a "use Dancer2" statement. Or are you saying: just have both applications use Log::Report and configure them to log to the same file?
You don't need to do anything in your other object, other than "use Log::Report". As long as your object was called from within your Dancer2 application (which it was in your original example), then everything else will Just Work. You don't need to configure any separate logging; it will use what is already configured in your parent application. If it is literally a separate application, executed complete separately from within the OS, then yes, you would need to configure it twice.
On 24-08-15 03:27, Andrew Beverley wrote:
On Sun, 2015-08-23 at 20:17 -0400, Arjan Widlak wrote:
You don't need to access the log object. In your other object you just do (for example):
use Log::Report;
trace "This will be logged as a debug string"; warning "This will be logged as a warning";
The above lines will be logged in exactly the same way as any other logging in your Dancer2 application, as long as you're using the Dancer2::Logger::LogReport logging backend. I can imagine how this works, within a Dancer2 application. But I'm talking about a class that doesn't have a "use Dancer2" statement. Or are you saying: just have both applications use Log::Report and configure them to log to the same file? You don't need to do anything in your other object, other than "use Log::Report". As long as your object was called from within your Dancer2 application (which it was in your original example), then everything else will Just Work. You don't need to configure any separate logging; it will use what is already configured in your parent application.
If it is literally a separate application, executed complete separately from within the OS, then yes, you would need to configure it twice. Clear and thanks. I'm going to configure and instantiate it - or Dancers2 log object - twice then, because in the other application I want to be able to either use Dancer's or it's own.
Thank you for your efforts! Kind regards, Arjan.
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
participants (2)
-
Andrew Beverley -
Arjan Widlak