https://tutorial.djangogirls.org/ko/django_start_project/
를 따라 했다.
하다 보면 이런 오류가 보인다,
이건 파이선3.7과 장고가 뭔가 일으킨다고 한다.
그래서..
'개발 > Python' 카테고리의 다른 글
python 로그파일 읽어서 원하는 내용 따로 파일로 만들기 (0) | 2018.07.26 |
---|
출처: http://november11tech.tistory.com/88 [Mr.november11]
https://tutorial.djangogirls.org/ko/django_start_project/
를 따라 했다.
하다 보면 이런 오류가 보인다,
이건 파이선3.7과 장고가 뭔가 일으킨다고 한다.
그래서..
python 로그파일 읽어서 원하는 내용 따로 파일로 만들기 (0) | 2018.07.26 |
---|
import os.path
import gzip
import re
prompt = '> '
############ DEFINE ##################
#start_str = '========================== Controller START =========================='
#finish_str = '========================== Controller FINISH =========================='
#"\d{1,3}?\.\d{1,3}?\.\d{1,3}?\.\d{1,3}",
ip_reg = re.compile('^\[ip-[0-9]+-[0-9]+-[0-9]+-[0-9]+]')
thread_reg = re.compile('\[Thread-[0-9]{5}]')
#timestamp_reg = re.compile('[0-9]{4}:[0-9]{2}:[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}')
timestamp_reg = re.compile('[0-9]{4}:[0-9]{2}:[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{3}')
######################################
current_directory = os.getcwd()
output_directory = "ResultParseLogs"
print "Input the Log script name \n"
print "With check current directory : %s" %current_directory
org_log_file = raw_input(prompt)
print "Input the KeyWord for search"
searchFor = raw_input(prompt)
if not os.path.exists(output_directory):
os.makedirs(output_directory)
# existence of the key
def check_the_key(dict, key):
return dict.has_key(key)
# find str in value -> return key
def search(dict, key):
value_from_key = ''.join(dict[key])
return value_from_key.find(searchFor)
# append dictionary
def refresh_dict(dict, key, value):
if check_the_key(dict, key) is True:
temp_value = dict[key]
result = ''.join(temp_value +value)
dict[key] = result
else:
dict[key] = value
def make_file_from_dict(dict, key):
if search(dict, key) > 0:
result = ''.join(dict[key])
filename = "output_"+key
filename = os.path.join(output_directory, filename)
with open(filename,"a+") as w:
w.write(result)
def make_dict_from_file(d):
if org_log_file[-2:] == "gz":
with gzip.open(org_log_file, 'r') as f:
for line in f:
if not line:
break
if ip_reg.search(line) is not None and thread_reg.search(line) is not None:
server = ip_reg.search(line).group()
thread = thread_reg.search(line).group()
key = server + thread
d[key] = line
# refresh_dict(d, key, line)
make_file_from_dict(d, key)
else:
pass
print "GZ End"
f.close()
else:
print "else"
with open(org_log_file) as f:
for line in f:
if not line:
break
if ip_reg.search(line) is not None and thread_reg.search(line) is not None:
server = ip_reg.search(line).group()
thread = thread_reg.search(line).group()
key = server + thread
d[key] = line
# refresh_dict(d, key, line)
make_file_from_dict(d, key)
else:
pass
print "Log End"
f.close()
# dictionary
dict = {}
make_dict_from_file(dict)
장고 프로젝트 시작 (0) | 2018.08.27 |
---|