MyTetra Share
Делитесь знаниями!
logger
Время создания: 20.05.2017 22:04
Раздел: Python - My_favor_scripts
Запись: xintrea/mytetra_db_mcold/master/base/1495307040ny6eufwp7q/text.html на raw.githubusercontent.com
# coding:utf-8

import logging
import inspect

file_log =
u'mylog.log'
#logging.basicConfig(format=u'%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s] %(message)s', level = logging.DEBUG, filename=u'mylog.log')
logging.basicConfig(format=u'[%(asctime)s] # %(message)s ', level = logging.DEBUG, filename=file_log)


def caller_args():
frame = inspect.currentframe()

outer_frames = inspect.getouterframes(frame)
#print(outer_frames)
caller_frame = outer_frames[2][0]
return inspect.getargvalues(caller_frame)

def log(string=None):
with open(file_log, "a") as f:
f.write(
'\n')
if not string == None:
logging.info(
u'{0}'.format(string))
print(inspect.stack())
logging.info(
u'{0}'.format(inspect.stack()[1][3].strip()))

with open(file_log, "a") as f:
for k, v in caller_args().locals.items():
if not str(v).find('open file') > 0: # убираем сам файл из лога
f.write(str(k) + ' - ' + str(v) + '\n')


def hunny(s = 'Mummy'):
log()
print("Happy birthday " + s + "!!!")

def test_func(a = 5, b = 78):
log()
hunny()

if __name__ == '__main__':
test_func()
 
MyTetra Share v.0.65
Яндекс индекс цитирования