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


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

Help me understand this logging config

Started byRoy Smith <roy@panix.com>
First post2011-08-29 10:53 -0700
Last post2011-08-30 17:01 +0530
Articles 7 — 4 participants

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


Contents

  Help me understand this logging config Roy Smith <roy@panix.com> - 2011-08-29 10:53 -0700
    Re: Help me understand this logging config Peter Otten <__peter__@web.de> - 2011-08-30 11:24 +0200
      Re: Help me understand this logging config Roy Smith <roy@panix.com> - 2011-08-30 08:39 -0400
        Re: Help me understand this logging config Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-09-02 02:56 -0700
        Re: Help me understand this logging config Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-09-02 09:58 +0000
        Re: Help me understand this logging config Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-09-02 03:00 -0700
    Re: Help me understand this logging config anand jeyahar <anand.ibmgsi@gmail.com> - 2011-08-30 17:01 +0530

#12411 — Help me understand this logging config

FromRoy Smith <roy@panix.com>
Date2011-08-29 10:53 -0700
SubjectHelp me understand this logging config
Message-ID<bdf729a3-5f68-46fb-b6ae-27dceed5af77@18g2000yqu.googlegroups.com>
I'm using django 1.3 and python 2.6.

My logging config is:


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(asctime)s: %(name)s %(levelname)s %
(funcName)s %(message)s'
            }
        },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
	},
    },
    'loggers': {
        'django.request': {'handlers': ['mail_admins'],
                           'level': 'ERROR',
                           'propagate': True,
                           },
        'djfront': {'handlers': ['console'],
                    'propagate': True,
                    },
	'djfront.view': {'level': 'INFO'},
        'djfront.auth': {'level': 'INFO'},
        'djfront.auth.user': {'level': 'INFO'},
	'djfront.api': {'level': 'WARN'},
        }
    }

In my code, I do:

logger = logging.getLogger('djfront.auth.facebook')

Since I haven't configured a 'djfront.auth.facebook' logger, it should
inherit the 'djfront.auth' config, which means the logging level
should be set to INFO.  But, when I do:

    logger.debug('redirecting to "%s"' % url)

it emits a message:

2011-08-29 13:31:03,321: djfront.auth.facebook DEBUG oauth_init
redirecting to [...]

I'm confused.  Why is the debug level message not getting filtered
out?

[toc] | [next] | [standalone]


#12432

FromPeter Otten <__peter__@web.de>
Date2011-08-30 11:24 +0200
Message-ID<mailman.566.1314696279.27778.python-list@python.org>
In reply to#12411
Roy Smith wrote:

> I'm using django 1.3 and python 2.6.

Isn't dictConfig() new in 2.7? It looks like that is what you are using...

> My logging config is:
> 
> 
> LOGGING = {
>     'version': 1,
>     'disable_existing_loggers': False,
>     'formatters': {
>         'verbose': {
>             'format': '%(asctime)s: %(name)s %(levelname)s %
> (funcName)s %(message)s'
>             }
>         },
>     'handlers': {
>         'mail_admins': {
>             'level': 'ERROR',
>             'class': 'django.utils.log.AdminEmailHandler'
>         },
>         'console': {
>             'level': 'DEBUG',
>             'class': 'logging.StreamHandler',
>             'formatter': 'verbose',
> },
>     },
>     'loggers': {
>         'django.request': {'handlers': ['mail_admins'],
>                            'level': 'ERROR',
>                            'propagate': True,
>                            },
>         'djfront': {'handlers': ['console'],
>                     'propagate': True,
>                     },
> 'djfront.view': {'level': 'INFO'},
>         'djfront.auth': {'level': 'INFO'},
>         'djfront.auth.user': {'level': 'INFO'},
> 'djfront.api': {'level': 'WARN'},
>         }
>     }
> 
> In my code, I do:
> 
> logger = logging.getLogger('djfront.auth.facebook')
> 
> Since I haven't configured a 'djfront.auth.facebook' logger, it should
> inherit the 'djfront.auth' config, which means the logging level
> should be set to INFO.  But, when I do:
> 
>     logger.debug('redirecting to "%s"' % url)
> 
> it emits a message:
> 
> 2011-08-29 13:31:03,321: djfront.auth.facebook DEBUG oauth_init
> redirecting to [...]
> 
> I'm confused.  Why is the debug level message not getting filtered
> out?

I tried your setup with the django-specific handler replaced by another 
StreamHandler

$ cat tmp_logging.py
import logging
import logging.config

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(asctime)s: %(name)s %(levelname)s %(funcName)s 
%(message)s'
            }
        },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'logging.StreamHandler' 
#'django.utils.log.AdminEmailHandler'
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'django.request': {'handlers': ['mail_admins'],
                           'level': 'ERROR',
                           'propagate': True,
                           },
        'djfront': {'handlers': ['console'],
                    'propagate': True,
                    },
        'djfront.view': {'level': 'INFO'},
        'djfront.auth': {'level': 'INFO'},
        'djfront.auth.user': {'level': 'INFO'},
        'djfront.api': {'level': 'WARN'},
        }
    }

logging.config.dictConfig(LOGGING)

logger = logging.getLogger('djfront.auth.facebook')
logger.info("info-test")
logger.debug("debug-test")

and got what

$ python2.7 tmp_logging.py
2011-08-30 11:18:33,160: djfront.auth.facebook INFO <module> info-test
$

which seems to be what you expected. So I'm confused, too...

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


#12438

FromRoy Smith <roy@panix.com>
Date2011-08-30 08:39 -0400
Message-ID<roy-7F52BC.08392630082011@news.panix.com>
In reply to#12432
In article <mailman.566.1314696279.27778.python-list@python.org>,
 Peter Otten <__peter__@web.de> wrote:

> Roy Smith wrote:
> 
> > I'm using django 1.3 and python 2.6.
> 
> Isn't dictConfig() new in 2.7? It looks like that is what you are using...

Oh, my, it turns out that django includes:

# This is a copy of the Python logging.config.dictconfig module,                                    
# reproduced with permission. It is provided here for backwards                                     
# compatibility for Python versions prior to 2.7. 

Comparing the django copy to lib/logging/config.py from Python 2.7.2, 
they're not identical.  It's likely they grabbed something earlier in 
the 2.7 series.  I'll check 2.7.0 and 2.7.1 to see.

> I tried your setup with the django-specific handler replaced by another 
> StreamHandler
> [...]
> and got what
> 
> $ python2.7 tmp_logging.py
> 2011-08-30 11:18:33,160: djfront.auth.facebook INFO <module> info-test
> $
> 
> which seems to be what you expected. So I'm confused, too...

I'll need to dig deeper.  Not that I realize this may not be a Python 
issue per-se, I'll do some more experimentation and ask on the django 
mailing list.  Thanks for your help.

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


#12627

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-09-02 02:56 -0700
Message-ID<fa2db494-bd1b-40f1-bfcf-5be31c8f97a6@a31g2000vbt.googlegroups.com>
In reply to#12438
On Aug 30, 1:39 pm, Roy Smith <r...@panix.com> wrote:
> Oh, my, it turns out that django includes:
>
> # This is a copy of the Pythonlogging.config.dictconfig module,
> # reproduced with permission. It is provided here for backwards
> # compatibility for Python versions prior to 2.7.
>
> Comparing the django copy to lib/logging/config.py from Python 2.7.2,
> they're not identical.  It's likely they grabbed something earlier in
> the 2.7 series.  I'll check 2.7.0 and 2.7.1 to see.

They're not identical, but should be functionally equivalent. I'm not
able to reproduce your results: I copied the "loggers" part of your
config into a Django 1.3 project, and from a manage.py shell session:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import logging
>>> logger = logging.getLogger('djfront.auth.facebook')
>>> logger.debug('Debug')
>>> logger.info('Info')
2011-09-02 10:51:13,445 INFO     djfront.auth.facebook Info
>>>

... as expected.

Since it's Python 2.6, it should be using the dictconfig which ships
with Django 1.3.

Regards,

Vinay Sajip

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


#12628

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-09-02 09:58 +0000
Message-ID<mailman.698.1314957525.27778.python-list@python.org>
In reply to#12438
On Aug 30, 1:39 pm, Roy Smith <r...@panix.com> wrote:
> Oh, my, it turns out that django includes:
> 
> # This is a copy of the Pythonlogging.config.dictconfig module,              
                     
> # reproduced with permission. It is provided here for backwards              
                     
> # compatibility for Python versions prior to 2.7.
> 
> Comparing the django copy to lib/logging/config.py from Python 2.7.2,
> they're not identical.  It's likely they grabbed something earlier in
> the 2.7 series.  I'll check 2.7.0 and 2.7.1 to see.

They're not identical, but should be functionally equivalent. I'm not able to
reproduce your results: I copied the "loggers" part of your config into a Django
1.3 project, and from a manage.py shell session:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import logging
>>> logger = logging.getLogger('djfront.auth.facebook')
>>> logger.debug('Debug')
>>> logger.info('Info')
2011-09-02 10:51:13,445 INFO     djfront.auth.facebook Info
>>> 

... as expected.

Since it's Python 2.6, it should be using the dictconfig which ships with Django
1.3.

Regards,

Vinay Sajip

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


#12629

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-09-02 03:00 -0700
Message-ID<d4a6dc37-0165-4209-ac79-2fbdc507dcdc@er4g2000vbb.googlegroups.com>
In reply to#12438
On Aug 30, 1:39 pm, Roy Smith <r...@panix.com> wrote:
> Oh, my, it turns out that django includes:
>
> # This is a copy of the Pythonlogging.config.dictconfig module,
> # reproduced with permission. It is provided here for backwards
> # compatibility for Python versions prior to 2.7.
>
> Comparing the django copy to lib/logging/config.py from Python 2.7.2,
> they're not identical.  It's likely they grabbed something earlier in
> the 2.7 series.  I'll check 2.7.0 and 2.7.1 to see.

They're not identical, but should be functionally equivalent. I'm not
able to reproduce your results: I copied the "loggers" part of your
config into a Django 1.3 project, and from a manage.py shell session:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import logging
>>> logger = logging.getLogger('djfront.auth.facebook')
>>> logger.debug('Debug')
>>> logger.info('Info')
2011-09-02 10:51:13,445 INFO     djfront.auth.facebook Info
>>>

... as expected.

Since it's Python 2.6, it should be using the dictconfig which ships
with Django 1.3.

Regards,

Vinay Sajip

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


#12435

Fromanand jeyahar <anand.ibmgsi@gmail.com>
Date2011-08-30 17:01 +0530
Message-ID<mailman.567.1314703930.27778.python-list@python.org>
In reply to#12411

[Multipart message — attachments visible in raw view] — view raw

Hi,
   I took a look at the logging source code. getLogger checks for existing
loggers with the given name and if it doesn't creates one.



def getLogger(self, name):
        """
        Get a logger with the specified name (channel name), creating it
        if it doesn't yet exist. This name is a dot-separated hierarchical
        name, such as "a", "a.b", "a.b.c" or similar.

        If a PlaceHolder existed for the specified name [i.e. the logger
        didn't exist but a child of it did], replace it with the created
        logger and fix up the parent/child references which pointed to the
        placeholder to now point to the logger.
        """
        rv = None
        _acquireLock()
        try:
            if name in self.loggerDict:
                rv = self.loggerDict[name]
                if isinstance(rv, PlaceHolder):
                    ph = rv
                    rv = (self.loggerClass or _loggerClass)(name)
                    rv.manager = self
                    self.loggerDict[name] = rv
                    self._fixupChildren(ph, rv)
                    self._fixupParents(rv)
            else:
                rv = (self.loggerClass or _loggerClass)(name)
                rv.manager = self
                self.loggerDict[name] = rv
                self._fixupParents(rv)
        finally:
            _releaseLock()
        return rv

==============================================
Anand Jeyahar
https://sites.google.com/site/<https://sites.google.com/site/aangjie/home/quotes>
anandjeyahar
==============================================
The man who is really serious,
with the urge to find out what truth is,
has no style at all. He lives only in what is.
                  ~Bruce Lee

Love is a trade with lousy accounting policies.
                 ~Aang Jie<https://sites.google.com/site/aangjie/home/quotes>

[toc] | [prev] | [standalone]


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


csiph-web