python logging module is not writing anything to file -


i'm trying write server logs exceptions both console , file. pulled code off cookbook. here is:

logger = logging.getlogger('server_logger') logger.setlevel(logging.debug) # create file handler logs debug messages fh = logging.filehandler('server.log') fh.setlevel(logging.debug) # create console handler higher log level ch = logging.streamhandler() ch.setlevel(logging.error) # create formatter , add handlers formatter = logging.formatter('%(asctime)s - %(levelname)s - %(message)s', datefmt='%y-%m-%d %h:%m:%s') ch.setformatter(formatter) fh.setformatter(formatter) # add handlers logger logger.addhandler(ch) logger.addhandler(fh) 

this code logs fine console, nothing logged file. file created, nothing ever written it. i've tried closing handler, doesn't anything. neither flushing it. searched internet, apparently i'm 1 problem. have idea problem is? answers.

try calling

logger.error('this should go both console , file') 

instead of

logging.error('this go default logger have not changed config of') 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -