Thanks Justin
well my true issue is accumulation of log info every time I reload the
script.
I realize that I might have a totally wrong way of doing this but,
let say I have this script called myScript.py
#===========================
import logging
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -
%(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
# prevent logging from bubbling up to maya's logger
logger.propagate=0
def testLog():
# 'application' code
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')
#=================================
now if I
import myScript
myScript.testLog()
I get a nice print out.
However if I make a change to the script and reload
reload(myScript)
myScript.testLog()
my print out is old info and new info, so its adding to the log,
how can I clear the log every time I reload?
>Could you explain your actual goal? Are you trying to modify maya's
existing logger or just create your >own for custom logging?
I was not trying to modify Maya's existing logger, I was just trying to use
python logging module to see if its something I could use for my work.
However how can I access Maya's existing Logger, that sounds interesting?
If I have something simple
import logging
logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
def testLog():
log.debug("this is debugging")
then I get the info printed out once but when I try to add the the
formatting, log accumulates the info.
Thanks
Yury
On Tue, Dec 6, 2011 at 7:05 PM, Justin Israel <[email protected]>wrote:
> Hi there,
>
> I believe the problem you are experiencing is that you are conflicting
> with maya's own logger. The python docs for logging explain that
> logging.basicConfig() should only be called in the main thread and before
> any other threads are started.
>
> What you might want to try is this example from the Basic Tutorial section:
> http://docs.python.org/howto/logging.html#logging-basic-tutorial
>
> But with a small modification:
>
> #=======================
>
> import logging
>
>
> logger = logging.getLogger('simple_example')
>
> logger.setLevel(logging.DEBUG)
>
>
> ch = logging.StreamHandler()
>
> ch.setLevel(logging.DEBUG)
>
>
> # create formatter
>
> formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -
> %(message)s')
>
> ch.setFormatter(formatter)
>
> logger.addHandler(ch)
>
>
> # prevent logging from bubbling up to maya's logger
>
> logger.propagate=0
>
>
> # 'application' code
>
> logger.debug('debug message')
>
> logger.info('info message')
>
> logger.warn('warn message')
>
> logger.error('error message')
>
> logger.critical('critical message')
>
>
> #=======================
>
> Could you explain your actual goal? Are you trying to modify maya's
> existing logger or just create your own for custom logging?
>
>
>
> On Tue, Dec 6, 2011 at 5:48 PM, ynedelin <[email protected]> wrote:
>
>> I got this from the python docs page
>>
>> if I run this in the script editor:
>>
>> import logging
>> logging.basicConfig(format='%(asctime)s %(message)s')
>> logging.warning('is when this event was logged.')
>>
>> I get this:
>>
>> # Warning: root : is when this event was logged. #
>>
>> How can I get the date to show in the script editor?
>>
>> 2010-12-12 11:41:42,612 is when this event was logged.
>>
>> Yury
>>
>> --
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings:
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe