-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoggingTest.py
24 lines (22 loc) · 887 Bytes
/
LoggingTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import logging
logger = logging.getLogger("Testing")
def initLogging(outputFileName):
logger.setLevel(logging.DEBUG)
fileHandle = logging.FileHandler(outputFileName)
fileHandle.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fileHandle.setFormatter(formatter)
#set up the stream handle (console)
consoleHandle = logging.StreamHandler()
consoleHandle.setLevel(logging.INFO)
consoleFormatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
consoleHandle.setFormatter(consoleFormatter)
logger.addHandler(fileHandle)
logger.addHandler(consoleHandle)
#======================================
if __name__ == '__main__':
initLogging("C:/Temp/TestLogging.log")
logger.warn("Test")
logger.info("Test")
logger.debug("Test")
logger.error("Test")