Hey all,
I'm new at programming with Python and thru reading different documentation, I built a small program (handler), that I want to accept calls from other scripts to log to file and console, depending on the level passed in. I'm able to get the error message to show up in both locations (console and log file), however, in the log file, one of the messages shows up twice (the 'info' message)...even though it's only being called once....any idea why this might be? Did I set up something wrong? I have included the relevant data here....
************** testLogger.py ******************
import sys, os, getopt, subprocess, logging
from logging import getLogger, Formatter, shutdown
from logging.handlers import RotatingFileHandler
def testLogger ():
myLog = logging.getLogger('myLogger')
myLog.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler('/tmp/testLogger.log', 'a', 800, 4)
format = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
handler.setFormatter(format)
myLog.addHandler(handler)
# print to screen
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
return myLog
def myWarning (msg):
logger = testLogger()
logger.warning(msg)
def myInfo (msg):
logger = testLogger()
logger.info(msg)
************ app.py *****************
import testLogger
testLogger.myWarning("warning")
testLogger.myInfo("info")
*********************************
Thanks in advance.
v.