def pwd_log from os import name getcwd mkdir from os path import join

 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
def pwd_log():
from os import name, getcwd, mkdir
from os.path import join, exists
pwd = r'/var/log/nms/'
if name == 'nt':
pwd = join(getcwd(), 'log')
if not exists(pwd):
mkdir(pwd)
return pwd
format_loggin = '%(asctime)-15s %(clientip)s %(user)-8s %(message)s'
logging.basicConfig(format = format_loggin, filename=pwd_log() + '/nms.log', level=logging.INFO)
log = logging.getLogger(__name__)
log.info('Message')
'''KeyError: 'clientip'
Call stack:
File "E:/Pyre_python/NMS/clsNMS/nms.py", line 31, in <module>
log.info('Message')
Message: 'Message'
Arguments: ()'''