Re: Question about logging.config.dictConfig

2023-02-08 Thread Ivan "Rambius" Ivanov
On Tue, Feb 7, 2023 at 7:35 PM Peter J. Holzer  wrote:
>
> On 2023-02-07 17:58:26 -0500, Ivan "Rambius" Ivanov wrote:
> > I am trying to configure my loggers using dictConfig, but they do not
> > print anything. Here are more details.
> [...]
> > from myloggingconf import configure_logging
> >
> > logger = logging.getLogger(os.path.basename(__file__))
> [...]
> >
> > def main():
> > configure_logging()
> > dosmth()
> [...]
> > def configure_logging():
> > config = {
> > 'version': 1,
> > 'disable_existing_loggers': True,
>
>   'disable_existing_loggers': False,

Thank you! That helped a lot!

Regards
rambius

>
> I think I just found out why I've been cargo-culting this line since my
> early Django days ;-)-
>
> If you call getLogger very early (as you do), you don't want it disabled
> by a later call to dictConfig().
>
>
> > 'formatters': {
> > 'default': {
> > 'fmt': '%(asctime)s %(levelname)-7s %(name)s %(funcName)s 
> > %(message)s'
>   'format'
> > }
> > },
> [...]
> > }
> > logging.config.dictConfig(config)
> >
> > When I run uselog.py it prints nothing. I am wondering what is wrong
> > with the second configuration.
>
> See above.
>
> hp
>
> --
>_  | Peter J. Holzer| Story must make more sense than reality.
> |_|_) ||
> | |   | h...@hjp.at |-- Charles Stross, "Creative writing
> __/   | http://www.hjp.at/ |   challenge!"
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Tangra Mega Rock: http://www.radiotangra.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about logging.config.dictConfig

2023-02-07 Thread Peter J. Holzer
On 2023-02-07 17:58:26 -0500, Ivan "Rambius" Ivanov wrote:
> I am trying to configure my loggers using dictConfig, but they do not
> print anything. Here are more details.
[...]
> from myloggingconf import configure_logging
> 
> logger = logging.getLogger(os.path.basename(__file__))
[...]
> 
> def main():
> configure_logging()
> dosmth()
[...]
> def configure_logging():
> config = {
> 'version': 1,
> 'disable_existing_loggers': True,

  'disable_existing_loggers': False,

I think I just found out why I've been cargo-culting this line since my
early Django days ;-)-

If you call getLogger very early (as you do), you don't want it disabled
by a later call to dictConfig().


> 'formatters': {
> 'default': {
> 'fmt': '%(asctime)s %(levelname)-7s %(name)s %(funcName)s 
> %(message)s'
  'format'
> }
> },
[...]
> }
> logging.config.dictConfig(config)
> 
> When I run uselog.py it prints nothing. I am wondering what is wrong
> with the second configuration.

See above.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list