Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5615 > unrolled thread

python logging

Started byFei <mail2fei@gmail.com>
First post2011-05-17 13:55 -0700
Last post2011-05-19 02:27 -0700
Articles 13 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  python logging Fei <mail2fei@gmail.com> - 2011-05-17 13:55 -0700
    Re: python logging Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2011-05-18 00:00 +0200
    Re: python logging Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-17 16:55 -0600
      Re: python logging Fei <mail2fei@gmail.com> - 2011-05-17 18:09 -0700
        Re: python logging Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2011-05-18 21:42 +0200
        Re: python logging Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-18 15:29 -0600
        Re: python logging Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2011-05-19 00:01 +0200
        Re: python logging Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-18 16:10 -0600
          Re: python logging Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-05-18 15:27 -0700
        Re: python logging Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2011-05-19 00:21 +0200
        Re: python logging Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-18 16:37 -0600
        Re: python logging Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-18 16:42 -0600
          Re: python logging Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-05-19 02:27 -0700

#5615 — python logging

FromFei <mail2fei@gmail.com>
Date2011-05-17 13:55 -0700
Subjectpython logging
Message-ID<049755c7-4238-438a-9b9b-9b3b7a3ebc87@s2g2000yql.googlegroups.com>
where is default logging file on Mac? I saw lots of app just import
logging, and begins to logging.info(...) etc.  I'm not sure where to
look at the logging configuration to figure out the log location.

I just get in touch of python about 1month ago, and I appreciate your
help.

[toc] | [next] | [standalone]


#5624

FromRafael Durán Castañeda <rafadurancastaneda@gmail.com>
Date2011-05-18 00:00 +0200
Message-ID<mailman.1723.1305669666.9059.python-list@python.org>
In reply to#5615
On 17/05/11 22:55, Fei wrote:
> where is default logging file on Mac? I saw lots of app just import
> logging, and begins to logging.info(...) etc.  I'm not sure where to
> look at the logging configuration to figure out the log location.
>
> I just get in touch of python about 1month ago, and I appreciate your
> help.
Looking at python docs you will find:

http://docs.python.org/howto/logging.html#logging-basic-tutorial

First example explains what you are asking.

P.S.: Next time you may try to look for the info you need before asking

[toc] | [prev] | [next] | [standalone]


#5628

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-05-17 16:55 -0600
Message-ID<mailman.1725.1305672986.9059.python-list@python.org>
In reply to#5615
On Tue, May 17, 2011 at 2:55 PM, Fei <mail2fei@gmail.com> wrote:
> where is default logging file on Mac? I saw lots of app just import
> logging, and begins to logging.info(...) etc.  I'm not sure where to
> look at the logging configuration to figure out the log location.

There is no default log file.  You're seeing that because logging only
needs to be configured by the program once, not on a per-module basis.
 Thus most modules will just do import logging on the assumption that
the configuration has already been performed somewhere else.

If no logging configuration is done at all, then the logging
statements will have no effect.

[toc] | [prev] | [next] | [standalone]


#5638

FromFei <mail2fei@gmail.com>
Date2011-05-17 18:09 -0700
Message-ID<4e923309-d4a5-4fc2-9fdf-b4350e11eab8@z37g2000vbl.googlegroups.com>
In reply to#5628
On May 17, 6:55 pm, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Tue, May 17, 2011 at 2:55 PM, Fei <mail2...@gmail.com> wrote:
> > where is default logging file on Mac? I saw lots of app just import
> > logging, and begins to logging.info(...) etc.  I'm not sure where to
> > look at the logging configuration to figure out the log location.
>
> There is no default log file.  You're seeing that because logging only
> needs to be configured by the program once, not on a per-module basis.
>  Thus most modules will just do import logging on the assumption that
> the configuration has already been performed somewhere else.
>
> If no logging configuration is done at all, then the logging
> statements will have no effect.

Thanks Ian.

[toc] | [prev] | [next] | [standalone]


#5731

FromRafael Durán Castañeda <rafadurancastaneda@gmail.com>
Date2011-05-18 21:42 +0200
Message-ID<mailman.1770.1305747758.9059.python-list@python.org>
In reply to#5638
On 18/05/11 03:09, Fei wrote:
> On May 17, 6:55 pm, Ian Kelly<ian.g.ke...@gmail.com>  wrote:
>> On Tue, May 17, 2011 at 2:55 PM, Fei<mail2...@gmail.com>  wrote:
>>> where is default logging file on Mac? I saw lots of app just import
>>> logging, and begins to logging.info(...) etc.  I'm not sure where to
>>> look at the logging configuration to figure out the log location.
>> There is no default log file.  You're seeing that because logging only
>> needs to be configured by the program once, not on a per-module basis.
>>   Thus most modules will just do import logging on the assumption that
>> the configuration has already been performed somewhere else.
>>
>> If no logging configuration is done at all, then the logging
>> statements will have no effect.
> Thanks Ian.
That's not exactly how it works. You can use logging without any 
configuration and the default output will be console. In addition 
default logging level is warning, so:

logging.info("Some text")

won't  show anything and

logging.warning("Other text")

will show:

WARNING:root:Other text

Please check the link I gave before.

Bye

[toc] | [prev] | [next] | [standalone]


#5743

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-05-18 15:29 -0600
Message-ID<mailman.1772.1305754218.9059.python-list@python.org>
In reply to#5638
2011/5/18 Rafael Durán Castañeda <rafadurancastaneda@gmail.com>:
> That's not exactly how it works. You can use logging without any
> configuration and the default output will be console. In addition default
> logging level is warning, so:
>
> logging.info("Some text")
>
> won't  show anything and
>
> logging.warning("Other text")
>
> will show:
>
> WARNING:root:Other text
>
> Please check the link I gave before.
>
> Bye

Odd.  That seems to work, but it contradicts the documentation at:

http://docs.python.org/howto/logging.html#what-happens-if-no-configuration-is-provided

[toc] | [prev] | [next] | [standalone]


#5746

FromRafael Durán Castañeda <rafadurancastaneda@gmail.com>
Date2011-05-19 00:01 +0200
Message-ID<mailman.1775.1305756070.9059.python-list@python.org>
In reply to#5638
On 18/05/11 23:29, Ian Kelly wrote:
> 2011/5/18 Rafael Durán Castañeda<rafadurancastaneda@gmail.com>:
>> That's not exactly how it works. You can use logging without any
>> configuration and the default output will be console. In addition default
>> logging level is warning, so:
>>
>> logging.info("Some text")
>>
>> won't  show anything and
>>
>> logging.warning("Other text")
>>
>> will show:
>>
>> WARNING:root:Other text
>>
>> Please check the link I gave before.
>>
>> Bye
> Odd.  That seems to work, but it contradicts the documentation at:
>
> http://docs.python.org/howto/logging.html#what-happens-if-no-configuration-is-provided
I think you are confuse because of you are looking at advanced logging, 
where getLogger is being used. Simple logging works without any 
configuration, getLogger doesn't.

[toc] | [prev] | [next] | [standalone]


#5748

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-05-18 16:10 -0600
Message-ID<mailman.1777.1305756668.9059.python-list@python.org>
In reply to#5638
2011/5/18 Rafael Durán Castañeda <rafadurancastaneda@gmail.com>:
> I think you are confuse because of you are looking at advanced logging,
> where getLogger is being used. Simple logging works without any
> configuration, getLogger doesn't.

It seems to work without any configuration just as well as the root logger:

>>> import logging
>>> logging.getLogger('foo').warning('test')
WARNING:foo:test

Or am I misunderstanding you?

[toc] | [prev] | [next] | [standalone]


#5750

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-05-18 15:27 -0700
Message-ID<b8a9d80b-2b61-404f-979a-38064fa94969@l26g2000yqm.googlegroups.com>
In reply to#5748
On May 18, 11:10 pm, Ian Kelly <ian.g.ke...@gmail.com> wrote:

> It seems to work without any configuration just as well as the root logger:
>
> >>> importlogging
> >>>logging.getLogger('foo').warning('test')
>
> WARNING:foo:test
>
> Or am I misunderstanding you?

In general for Python 2.x, the code

import logging
logging.getLogger('foo').warning('test')

will produce

No handlers could be found for logger "foo"

unless loggers have been configured, e.g. by calling logging.warning()
- that call implicitly adds a console handler to the root logger, if
no other handlers have been configured for the root logger.

In Python 3.2 and later, if no handlers have been configured, messages
at level WARNING and greater will be printed to sys.stderr using a
"handler of last resort" - see

http://docs.python.org/py3k/howto/logging.html#what-happens-if-no-configuration-is-provided

Regards,

Vinay Sajip

[toc] | [prev] | [next] | [standalone]


#5749

FromRafael Durán Castañeda <rafadurancastaneda@gmail.com>
Date2011-05-19 00:21 +0200
Message-ID<mailman.1778.1305757321.9059.python-list@python.org>
In reply to#5638
On 19/05/11 00:10, Ian Kelly wrote:
> 2011/5/18 Rafael Durán Castañeda<rafadurancastaneda@gmail.com>:
>> I think you are confuse because of you are looking at advanced logging,
>> where getLogger is being used. Simple logging works without any
>> configuration, getLogger doesn't.
> It seems to work without any configuration just as well as the root logger:
>
>>>> import logging
>>>> logging.getLogger('foo').warning('test')
> WARNING:foo:test
>
> Or am I misunderstanding you?
Are you using python 2.x or 3.x? At python 2.7 using:

import logging
logging.getLogger('log').warning('test')

I got:

No handlers could be found for logger "log"

[toc] | [prev] | [next] | [standalone]


#5752

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-05-18 16:37 -0600
Message-ID<mailman.1780.1305758303.9059.python-list@python.org>
In reply to#5638
2011/5/18 Rafael Durán Castañeda <rafadurancastaneda@gmail.com>:
> Are you using python 2.x or 3.x? At python 2.7 using:
>
> import logging
> logging.getLogger('log').warning('test')
>
> I got:
>
> No handlers could be found for logger "log"

Ah, that's it.  I was using Python 2.5.  Using 2.7 I get the same
result that you do.

Still, it's a surprising change that doesn't seem to be documented as
such.  I'm not sure whether it's a regression or an intentional
change.

[toc] | [prev] | [next] | [standalone]


#5753

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-05-18 16:42 -0600
Message-ID<mailman.1781.1305758558.9059.python-list@python.org>
In reply to#5638
2011/5/18 Ian Kelly <ian.g.kelly@gmail.com>:
> Ah, that's it.  I was using Python 2.5.  Using 2.7 I get the same
> result that you do.
>
> Still, it's a surprising change that doesn't seem to be documented as
> such.  I'm not sure whether it's a regression or an intentional
> change.

I was wrong, it's more complicated than that.

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.getLogger('log').warning('test')
No handlers could be found for logger "log"
>>> logging.warning('test')
WARNING:root:test
>>> logging.getLogger('log').warning('test')
WARNING:log:test

Apparently, getLogger() is unconfigured by default, but if you just
use the root logger once, then they magically get configured.

[toc] | [prev] | [next] | [standalone]


#5768

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-05-19 02:27 -0700
Message-ID<073b63fa-51bc-4c21-bdb2-676adc405093@r20g2000yqd.googlegroups.com>
In reply to#5753
On May 18, 11:42 pm, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> I was wrong, it's more complicated than that.
>
> >>>logging.getLogger('log').warning('test')
>
> No handlers could be found for logger "log">>>logging.warning('test')
> WARNING:root:test
> >>>logging.getLogger('log').warning('test')
>
> WARNING:log:test
>
> Apparently, getLogger() is unconfigured by default, but if you just
> use the root logger once, then they magically get configured.

The difference is that you called the module-level convenience
function -

logging.warning('test')

The module-level convenience functions call basicConfig(), which
configures a console handler on the root logger if no handlers are
present there. This is documented at

http://docs.python.org/library/logging.html#logging.log

(see para starting "PLEASE NOTE:")

and

http://docs.python.org/howto/logging.html#advanced-logging-tutorial

(search for "If you call the functions")

This is not a behaviour change - it's been like this since logging
appeared in Python, see

http://hg.python.org/cpython/annotate/f72b1f8684a2/Lib/logging/__init__.py#l1145

Regards,

Vinay Sajip

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web