Python Forum
logging: child module unable to get parent config
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
logging: child module unable to get parent config
#1
I had some problems with logging
According to The Doc
in the same Python interpreter, you get the same logger object with the same config

But if that's true, why can't my code work
https://gist.github.com/isjerryxiao/b6ff...c011ae7a7a

Actually I was trying to make traceback look prettier in log files.

my test environment:
Python 3.7.3 (default, Mar 26 2019, 21:43:19)
[GCC 8.2.1 20181127] on linux
Reply
#2
The calls to logging.getLogger(__name__) create two different logger instances in your code, namely logging.getLogger('__main__') and logging.getLogger('mymodule').
Reply
#3
(Apr-08-2019, 04:17 PM)Gribouillis Wrote: The calls to logging.getLogger(__name__) create two different logger instances in your code, namely logging.getLogger('__main__') and logging.getLogger('mymodule').

I don't think so, according to the Python Doc I posted above, calls to the other instances should be passed to the main logger instance, otherwise the example code there shouldn't even work.
Reply
#4
Quote:logging.getLogger(name=None)
Return a logger with the specified name or, if name is None, return a logger which is the root logger of the hierarchy. If specified, the name is typically a dot-separated hierarchical name like ‘a’, ‘a.b’ or ‘a.b.c.d’. Choice of these names is entirely up to the developer who is using logging.

All calls to this function with a given name return the same logger instance. This means that logger instances never need to be passed between different parts of an application.


That's clearly documented, but i did not look carefully.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Chain object that have parent child relation.. SpongeB0B 10 1,112 Dec-12-2023, 01:01 PM
Last Post: Gribouillis
  Using one child class method in another child class garynewport 5 1,610 Jan-11-2023, 06:07 PM
Last Post: garynewport
  Updating a config file [solved] ebolisa 8 2,609 Nov-04-2021, 10:20 AM
Last Post: Gribouillis
  Is there a library for recursive object creation using config objects johsmi96 0 1,857 May-03-2021, 08:09 PM
Last Post: johsmi96
  help with pytesseract.image_to_string(savedImage, config='--psm 11')iamge to string korenron 0 2,711 Apr-29-2021, 10:08 AM
Last Post: korenron
  unable to find module in su mode? korenron 2 1,929 Jan-10-2021, 07:41 PM
Last Post: Gribouillis
  Can we access instance variable of parent class in child class using inheritance akdube 3 14,006 Nov-13-2020, 03:43 AM
Last Post: SalsaBeanDip
  Unable to install module rrowhe4d 1 2,294 Oct-13-2020, 10:20 AM
Last Post: Larz60+
  Python3 binary tree not replacing parent nodes with child nodes Aspect11 0 1,781 Sep-23-2020, 02:22 PM
Last Post: Aspect11
  Config file update Olivier74 0 1,487 Aug-18-2020, 03:36 PM
Last Post: Olivier74

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020