On 2021-09-02 09:06:53 +0200, Loris Bennett wrote:
> Thanks Peter and Dieter for all the help.  I have finally figured out
> what my problem was.  If in a module 'mylibs.mylib' I have
> 
>   import logging
> 
>   logger = logging.getLogger(__name__)
> 
> and in my main script have
> 
>   import logger
>   import logger.config
> 
>   import mylibs.mylib
> 
>   logging.config.fileConfig("/home/loris/config")
>   logger = logging.getLogger(__name__)
>  
> then 'logger' in 'mylibs.mylib' is defined before
> 'logging.config.fileConfig' is called and the logger in the module is
> not configured.
> 
> If change the order and write
> 
>   import logger
>   import logger.config
> 
>   logging.config.fileConfig("/home/loris/config")
>   logger = logging.getLogger(__name__)
> 
>   import mylibs.mylib
> 
> then the 'logger' in 'mylibs.mylibs' does get configured properly.

That normally shouldn't make any difference, since any functions in
mylibs.mylib would be called only after the logger is initialized.

Does your mylibs.mylib contain code which is run on import (other than
class, function and variable definitions)?

        hp

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

Attachment: signature.asc
Description: PGP signature

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to