This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ericg97477
Recipients ericg97477
Date 2015-07-25.10:29:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1437820150.2.0.817154151105.issue24717@psf.upfronthosting.co.za>
In-reply-to
Content
If I have interpreted the python3 documentation correctly, regardless of where I add the handler to the root logger, my log messages from within a Process should be sent to a file. However, this is not the case.

Here is a complete program which demonstrates the problem:

import logging
import logging.handlers

from multiprocessing import Process
from time import sleep

fileHandler = logging.FileHandler( 'mylog.log' )
fileHandler.setLevel( 5 )

logger = logging.getLogger( None )

def process_logger():

    print( "process waiting" )
    sleep( 5 )
    print( 'process start' )

    logger = logging.getLogger( None )

    for num in range( 1, 10 ):
        logger.critical( "critical: %d" % num )
        sleep(1)

#
# if this is where the handler is added, the critical messages
# will go to the file
#
logger.addHandler( fileHandler )

processLogger = Process( target=process_logger )
processLogger.start()

#
# if this is where the handler is added, the critical messages
# will not go to the file.
#
#logger.addHandler( fileHandler )

print( "started" )

I am using python 3.4.3 on OS X 10.10.4.

My guess as to why this does not work is that when I start the Process, it makes a copy of the current environment and if the handler has not been added by that time, the environment the Process is running in won't have it.

I have three questions:

Why do my messages not always end up in the file regardless of where I call logger.addHandler?

Should my messages always end up in the file?

If they should not, what is the best solution to the general problem of needed to manipulate handlers after a Process has been started?
History
Date User Action Args
2015-07-25 10:29:10ericg97477setrecipients: + ericg97477
2015-07-25 10:29:10ericg97477setmessageid: <1437820150.2.0.817154151105.issue24717@psf.upfronthosting.co.za>
2015-07-25 10:29:10ericg97477linkissue24717 messages
2015-07-25 10:29:09ericg97477create