LionHeart123 / pyscripter

Automatically exported from code.google.com/p/pyscripter
0 stars 0 forks source link

logging module cannot work when using remote engine #685

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
--- What steps will reproduce the problem?

1. Switch the Python engine to "Remote" in: Run | Python Engine
2. Do "Reinitialize Python engine"
3. in the editor, open a script file with following codes, then execute:

import logging

LOG_FILENAME = 'test_example5.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)

logging.debug('This message 1')
logging.debug('This message 2')

--- What is the expected output? What do you see instead?

Expected: A "test_example5.log" file should be created.

Actual result: no file is created. (I used tool "everything" to search the 
whole system, and confirmed the expected file really did not be created.)

--- What version of the product are you using? On what operating system?

Windows 7 (64bit) Professional
PyScripter 2.5.3.0 x86 (32bit)
Python 3.2.2 (32bit)

--- Please provide any additional information below.

Work around: switch to "Internal" Python engine

Original issue reported on code.google.com by cynosure...@gmail.com on 29 Aug 2012 at 1:28

GoogleCodeExporter commented 9 years ago
Indeed, the problem is that the remote python engine initializes logging and 
the call to basicConfig in your script is ignored.

As a workaround use the following:

import logging

LOG_FILENAME = 'test_example5.log'
fh = logging.FileHandler(LOG_FILENAME)
fh.setLevel(logging.DEBUG)

logger = logging.getLogger()
logger.addHandler(fh)

logger.debug('This message 1')
logger.debug('This message 2')

fh.close()

Original comment by pyscripter on 6 Sep 2012 at 12:15

GoogleCodeExporter commented 9 years ago
I can't seem to find a way to fix logging to the console (sys.stdout). Any 
advice on that? I've tried the following, among other things:

import sys
consoleLogHandler = logging.StreamHandler(sys.stdout)
consoleLogHandler.setLevel(logging.DEBUG)
consoleLogHandler.setFormatter(logging.Formatter('%(message)s'))
logging.root.addHandler(consoleLogHandler)

Original comment by pckuj...@gmail.com on 10 Sep 2012 at 7:40

GoogleCodeExporter commented 9 years ago
Oh, and I should mention that, when using the Internal Python engine, 
basicConfig works fine ( logging.basicConfig(level=logging.DEBUG, 
format='%(message)s') ). It's only with the External engine that logging 
disappears.

Original comment by pckuj...@gmail.com on 10 Sep 2012 at 7:41

GoogleCodeExporter commented 9 years ago
Exactly, I had mentioned that in the "workaround" part when I reported the bug:

--- Please provide any additional information below.

Work around: switch to "Internal" Python engine

Original comment by cynosure...@gmail.com on 11 Sep 2012 at 11:34

GoogleCodeExporter commented 9 years ago
I can't remember how to reproduce it but it is also possible for the Internal 
Python engine to fail logging (and to file) too if you use both basicConfig and 
addHandler incorrectly. 

Original comment by yho2...@gmail.com on 2 Aug 2013 at 1:48