librelist archives

« back to archive

How to use the default logger of werkzeug ?

How to use the default logger of werkzeug ?

From:
Stephane Wirtel
Date:
2010-05-17 @ 10:22
Hi all,

I want to use the default logger of werkzeug, but I think I forget something

I made two tests:

1. With the default logger from the python library
I think I should use this code, but the output on the console is not very useful
[code]
import logging
log = logging.getLogger('werkzeug')
log.warning('Test')
[/code]

[output]
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader...
127.0.0.1 - - [17/May/2010 12:18:37] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [17/May/2010 12:18:37] "GET /favicon.ico HTTP/1.1" 200 -
Test               <---- My log :/
127.0.0.1 - - [17/May/2010 12:18:42] "GET /modify/2 HTTP/1.1" 200 -
127.0.0.1 - - [17/May/2010 12:18:42] "GET /favicon.ico HTTP/1.1" 200 -
[/output]

2. With the _log function from werkzeug
from werkzeug._internal import _log

_log('info', 'Test')

And the result is the same.

Is there a way to log to the console ?

Thank you

Stephane

Re: [flask] How to use the default logger of werkzeug ?

From:
Armin Ronacher
Date:
2010-05-17 @ 14:08
Hi,

Related followup: There is now an app.logger you can use for logging. 
Documentation to follow.  Until then, you can do this:

     app = Flask(__name__)

     @app.route('/')
     def index():
         app.error('Implement me')
         return ''

The handler is by default set up to only print these messages during 
development.  For production you have to hook in your own handler (for 
example one that logs to the syslog, a different file, sends you emails 
etc.)


Regards,
Armin

Re: [flask] How to use the default logger of werkzeug ?

From:
Stephane Wirtel
Date:
2010-05-18 @ 08:15
On 05/17/2010 04:08 PM, Armin Ronacher wrote:
> Hi,
> 
> Related followup: There is now an app.logger you can use for logging. 
> Documentation to follow.  Until then, you can do this:
> 
>      app = Flask(__name__)
> 
>      @app.route('/')
>      def index():
>          app.error('Implement me')
>          return ''
> 
> The handler is by default set up to only print these messages during 
> development.  For production you have to hook in your own handler (for 
> example one that logs to the syslog, a different file, sends you emails 
> etc.)
> 
> 
> Regards,
> Armin
Cool, I have seen the commit for the logging support in the git repository.

Thanks

Re: [flask] How to use the default logger of werkzeug ?

From:
Armin Ronacher
Date:
2010-05-17 @ 10:37
Hi,

On 2010-05-17 12:22 PM, Stephane Wirtel wrote:
> I want to use the default logger of werkzeug, but I think I forget something
Do not.  There is a reason why the logging function is called 
_internal._log.  The only thing you should do with that thing is 
reconfiguring the logger handler to hide the messages or redirect them.

Get your own logger instead and put more information on it.  The log 
message see is generated by the lower level server implementation btw.


Regards,
Armin

Re: [flask] How to use the default logger of werkzeug ?

From:
Stephane Wirtel
Date:
2010-05-17 @ 11:32
Thank you

Regards,

Stéphane
On 05/17/2010 12:37 PM, Armin Ronacher wrote:
> Hi,
> 
> On 2010-05-17 12:22 PM, Stephane Wirtel wrote:
>> I want to use the default logger of werkzeug, but I think I forget something
> Do not.  There is a reason why the logging function is called 
> _internal._log.  The only thing you should do with that thing is 
> reconfiguring the logger handler to hide the messages or redirect them.
> 
> Get your own logger instead and put more information on it.  The log 
> message see is generated by the lower level server implementation btw.
> 
> 
> Regards,
> Armin