May 2017
Beginner to intermediate
444 pages
11h 31m
English
First, we create a new Python module into which we place two new classes. The first class is very simple and defines the logging levels. This is basically an enumeration:
class LogLevel: '''Define logging levels.''' OFF = 0 MINIMUM = 1 NORMAL = 2 DEBUG = 3
The second class creates a log file by using the passed-in full path of the file name and places this into a logs folder. On the first run, the logs folder might not exist, so the code automatically creates the folder:
import os, timefrom datetime import datetimeclass Logger: ''' Create a test log and write to it. ''' #------------------------------------------------------- def __init__(self, fullTestName, loglevel=LogLevel.DEBUG): testName = os.path.splitext(os.path.basename(fullTestName))[0] ...
Read now
Unlock full access