Re: How to export a logging level?

2012-09-25 Thread Vincent Vande Vyvre
Le 25/09/12 19:47, Jean-Michel Pichavant a écrit :
> - Original Message -
>> In my application I import a module and I want to set the same
>> logging
>> level
>> as the main app to this module.
>>
>> I've tried this code
>>
>> main.py
>>
>> import logging
>> logger = logging.getLogger(__name__)
>> lvl = logging.DEBUG
>> LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s"
>> logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl)
>>
>> from mymodule.myfile import MyClass
>>
>> ...
>> def load_myclass(self):
>> lvl = logger.getEffectiveLevel()
>> mc = MyClass(self, lvl)
>>
>>
>> myfile.py
>>
>> import logging
>> logger = logging.getLogger(__name__)
>>
>> class MyClass(object):
>> def __init__(self, main, lvl):
>> logger.setLevel(lvl)
>>
>> If I set the level to logging.DEBUG I can see all infos from the main
>> but anything
>> from my module.
>>
>> Thanks for your advice.
>> --
>> Vincent V.V.
>> Oqapy  . Qarte
>>  . PaQager
>> 
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> Life is actually simpler, one rule to remember: you don't configure your 
> loggers, ever. You let this worthless task to the user (in your case the 
> main.py file or however import your module).
>
> In myfile.py, the only logging related lines are:
>
> import logging
> logger = logging.getLogger(__name_)
>
> Then you just log. How the logs  are processed, at which level, for which 
> formatter, you don't care. The root logger will take care of that. Keep your 
> main.py as it is and it should work.
>
> JM
>
>
Oops, my fault, I've forgotten a line "logger.setLevel(logging.WARNING)"
into my module.

Thanks
-- 
Vincent V.V.
Oqapy  . Qarte
 . PaQager 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to export a logging level?

2012-09-25 Thread Jean-Michel Pichavant
- Original Message -
> In my application I import a module and I want to set the same
> logging
> level
> as the main app to this module.
> 
> I've tried this code
> 
> main.py
> 
> import logging
> logger = logging.getLogger(__name__)
> lvl = logging.DEBUG
> LOG_FORMAT = "%(asctime)-6s %(levelname)s: %(name)s - %(message)s"
> logging.basicConfig(format=LOG_FORMAT, datefmt='%H:%M:%S', level=lvl)
> 
> from mymodule.myfile import MyClass
> 
> ...
> def load_myclass(self):
> lvl = logger.getEffectiveLevel()
> mc = MyClass(self, lvl)
> 
> 
> myfile.py
> 
> import logging
> logger = logging.getLogger(__name__)
> 
> class MyClass(object):
> def __init__(self, main, lvl):
> logger.setLevel(lvl)
> 
> If I set the level to logging.DEBUG I can see all infos from the main
> but anything
> from my module.
> 
> Thanks for your advice.
> --
> Vincent V.V.
> Oqapy  . Qarte
>  . PaQager
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Life is actually simpler, one rule to remember: you don't configure your 
loggers, ever. You let this worthless task to the user (in your case the 
main.py file or however import your module).

In myfile.py, the only logging related lines are:

import logging
logger = logging.getLogger(__name_)

Then you just log. How the logs  are processed, at which level, for which 
formatter, you don't care. The root logger will take care of that. Keep your 
main.py as it is and it should work.

JM

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


Re: How to export a logging level?

2012-09-25 Thread Vincent Vande Vyvre
Le 25/09/12 19:01, Peter Otten a écrit :
> Vincent Vande Vyvre wrote:
>
>> In my application I import a module and I want to set the same logging
>> level as the main app to this module.
> Isn't that the default? If you set the logging level with basicConfig() that 
> level should be applied to all messages. 
>
>
Not, only the messages from the main class and the others class that are
in the same module (folder) appears into the console.

Any message from the module imported.

-- 
Vincent V.V.
Oqapy  . Qarte
 . PaQager 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to export a logging level?

2012-09-25 Thread Peter Otten
Vincent Vande Vyvre wrote:

> In my application I import a module and I want to set the same logging
> level as the main app to this module.

Isn't that the default? If you set the logging level with basicConfig() that 
level should be applied to all messages. 


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