-
Notifications
You must be signed in to change notification settings - Fork 0
/
testfailoverlogger.py
66 lines (55 loc) · 1.99 KB
/
testfailoverlogger.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""
Python script to test MultiLogger using hard-coded values.
"""
from multilogger import MultiLogger
LOG_FILE = '/var/log/multilogger.log'
FACILITY = 'local1'
class TestMultiLogger(object):
"""
Class to test MultiLogger using hard-coded values.
"""
def __init__(self):
self.logger = MultiLogger(places={'logger': True, 'email': True,
'console': True}, loglevel='DEBUG', facility=FACILITY,
enable_color=True)
self.testData = {
'DEBUG': 'Test DEBUG log',
'INFO' : 'Test INFO log',
'WARNING' : 'Test WARNING log',
'WARN' : 'Test WARN log',
'ERROR' : 'Test ERROR log',
'EXCEPTION' : 'Test EXCEPTION log',
'CRITICAL' : 'Test CRITICAL log'
}
def test_logger(self):
"""
Method to test the MultiLogger with a data set in self.testData and
print the logs in console
"""
# System logger 'local6' location is '/var/log/multilogger.log'
# Ensure you have write permission for this log file
# Clear contents of file:
f = open(LOG_FILE, 'w')
f.close()
# log test data
self.logger.debug(self.testData['DEBUG'])
self.logger.info(self.testData['INFO'])
self.logger.warning(self.testData['WARNING'])
self.logger.warn(self.testData['WARN'])
self.logger.error(self.testData['ERROR'])
self.logger.exception(self.testData['EXCEPTION'])
self.logger.critical(self.testData['CRITICAL'])
# read the contents of log file
f = open(LOG_FILE, 'r')
log_contents = f.read()
f.close()
print "\n####### Log File Contents #######\n"
print log_contents
# get the contents of email log
email_body = self.logger.get_email_log()
print "\n####### Email Body #######\n"
print email_body
if __name__ == '__main__':
testlogger = TestMultiLogger()
testlogger.test_logger()