forked from OmkarPathak/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP18_Logging.py
More file actions
22 lines (20 loc) · 688 Bytes
/
Copy pathP18_Logging.py
File metadata and controls
22 lines (20 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Author: OMKAR PATHAK
#This program illustrates a logging example
import logging
def log(number):
''' This function creates a log file if any error is reported '''
logging.basicConfig(filename = 'P18-logfile.txt', level = logging.INFO)
try:
if int(number) % 2 == 0:
print('Successful')
else:
print('Unsuccessful, this instance will be reported, check the log file')
logging.info('Invalid Entry')
except:
print('Please enter a valid integer')
if __name__ == '__main__':
try:
userInput = int(input('Enter a number: '))
log(userInput)
except:
print('Please enter a valid integer')