-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path2.WriteLogToFile.py
41 lines (33 loc) · 1.44 KB
/
2.WriteLogToFile.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
##------------------------------------------------------------------------------------------------------
#Created By:Ravishankar Chavare
#version:python 3.7
#Date:13/03/2019
#File_des:Introduction of Logging
#Offical Documentation:https://docs.python.org/2/library/logging.html
##------------------------------------------------------------------------------------------------------
import logging as log
#To configure logging use log.basicconfig(parametere) for initilization
'''
some of the commonly used paramter for basicconfig
1.level: The root logger will be set to the specified severity level.
2.filename: This specifies the file.
3.filemode: If filename is given, the file is opened in this mode. The default is a, which means append.
4.format: This is the format of the log message.
'''
#Configure loggging
loger=log.getLogger(__name__)
log.basicConfig(filename='simplelog.log',level=log.INFO,format='[%(asctime)s-%(levelname)s]-%(message)s')
loger.info("Simple logMessage")
loger.debug("This is debug Message")
loger.error("this is Error Log")
#Foloowing are the some log records attributes format
'''
%(asctime)s :-Asctime
%(created)f :-created
%(filename)s :-filename where log generated
%(funcName)s :Function name
%(levelname)s :-level name
%(message)s :-logger passing messgae
%(pathname)s :-Full pathname of the source file where the logging call was issued (if available).
%(process)d :-if process id is Avialable
'''