-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialization.py
More file actions
172 lines (131 loc) · 3.83 KB
/
initialization.py
File metadata and controls
172 lines (131 loc) · 3.83 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# log reader by R.Hoobakht 1402-02-04 v.0.2.5
from os import remove
keyword_list = list()
# directory of log files path
files_path = str()
# result of search log file path
output_filename = str()
# sign of the write mode
write_mode = str()
# sign of the read mode
read_mode = str()
# and delimiter to search with and logic
delimiter = str()
# less than sign
less_than = str()
# pure file name
fn = str()
# indent line
tab = str()
# if true consider case-sensitive to find the keywords and if false not
case_sensitive = bool()
# if true consider only system and database logs. if false not
db2_log_only = bool()
# sign of the new line
new_line = str()
# dash sign
dash = str()
# show number of log file
index = int()
# line for file name separator
separator = str()
# close 'log' xml tag
close_log_tag = str()
# back-slash sign
back_slash = str()
# represent number one
one = int()
# start message for logs reading operation
start_message = str()
# end message for logs reading operation
end_message = str()
# -------------------------------------------------------------
def log_version():
return "log reader by R.Hoobakht 1402-02-04 v.0.2.5"
def set_env_variable():
global files_path
global output_filename
global out_file
global write_mode
global read_mode
global delimiter
global less_than
global fn
global tab
global dash
global case_sensitive
global db2_log_only
global new_line
global close_log_tag
global index
global separator
global back_slash
global one
global end_message
global start_message
files_path = "C:/Users/hoobakht/Downloads/log"
output_filename = "result.xml"
write_mode = "w"
read_mode = "r"
delimiter = "&&"
less_than = "<"
fn = ""
tab = "\t"
dash = " - "
case_sensitive = False
db2_log_only = False
new_line = '\n'
close_log_tag = "</log>"
back_slash = '\\'
index = 0
one = 1
separator = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
end_message = "The End of the log searching ..."
start_message = tab + log_version() + new_line + tab + "Log reader start ..."
def remove_file(file_name):
try:
remove(file_name)
except FileNotFoundError:
print(f"remove {file_name}: {file_name} file not found ...")
def write_header(out_file_object):
out_file_object.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
out_file_object.write(new_line + new_line)
out_file_object.write("<log>")
out_file_object.write(new_line + new_line)
# specified keywords to search
# you can use '&&' delimiter to search with and logic
def set_keywords():
global keyword_list
keyword_list = [
"threadTokenId=\"1679482282160\" && 2023-04-24 && 08:08:13",
# "http://",
# "https://"
# "DEADLOCK",
# "TIMEOUT",
# "KEY NOT FOUND",
# "SSL",
# "DATASOURCE",
# "SQL STATE",
# "PRIVILEGE",
# "GRAMMAR",
# "CALL JAMSHMA",
# "DataIntegrityViolationException",
# "InvalidDataAccessApiUsageException",
# "DataAccessResourceFailureException",
# "MethodArgumentNotValidException"
# "ResourceAccessException"
]
def increase_index():
global index
index = index + 1
# -------------------------------------------------------------
# -------------------------------------------------------------
# initialize all variables and objects
set_env_variable()
# delete result.xml file if exist
remove_file(output_filename)
# set keywords to search
set_keywords()
out_file = open(output_filename, write_mode)
# crate output file object and write the header to it
write_header(out_file)