@@ -32,7 +32,7 @@ def __new__(cls, *args, **kwargs):
32
32
def __init__ (
33
33
self ,
34
34
output_file : str = None ,
35
- level : str = "INFO " ,
35
+ level : str = "DEBUG " ,
36
36
enabled : bool = True ,
37
37
colors : bool = True ,
38
38
erase : bool = True ,
@@ -42,7 +42,7 @@ def __init__(
42
42
43
43
Args:
44
44
output_file (str, optional): Output file path. Defaults to None.
45
- level (str, optional): Minimum log level. Defaults to "INFO ".
45
+ level (str, optional): Minimum log level. Defaults to "DEBUG ".
46
46
enabled (bool, optional): Is log enabled ? Defaults to True.
47
47
colors (bool, optional): Are colors enabled ? Defaults to True.
48
48
erase (bool, optional): Should preexisting file be erased ? Defaults to True.
@@ -116,7 +116,7 @@ def _clear_file(self):
116
116
with open (self ._output_file , "w" ) as f :
117
117
pass
118
118
119
- def _write (self , content : str ):
119
+ def _write (self , level : str , content : str ):
120
120
"""Write provided content to output file.
121
121
122
122
Args:
@@ -126,16 +126,10 @@ def _write(self, content: str):
126
126
if not self ._enabled :
127
127
return
128
128
129
- if self ._colors :
130
- time = Style .DIM + datetime .now ().strftime ("%H:%M:%S.%f" )[:- 3 ]
131
- dash = Style .BRIGHT + " - "
132
- content = f"{ Style .NORMAL } { content } { Style .RESET_ALL } "
133
- else :
134
- time = datetime .now ().strftime ("%H:%M:%S.%f" )[:- 3 ]
135
- dash = " - "
129
+ time = datetime .now ().strftime ("%H:%M:%S.%f" )[:- 3 ]
136
130
137
131
with open (self ._output_file , "a" ) as f :
138
- f .write (f"{ time } { dash } { content } \n " )
132
+ f .write (f"{ level } | { time } - { content } \n " )
139
133
140
134
def _is_valid_level (self , level : str ):
141
135
"""Verify if the given log level should be written.
@@ -156,10 +150,7 @@ def error(self, message: str):
156
150
message (str): Log message
157
151
"""
158
152
159
- if self ._colors :
160
- self ._write (content = Fore .RED + message )
161
- else :
162
- self ._write (content = "error | " + message )
153
+ self ._write (level = "ERR!" , content = message )
163
154
164
155
def warn (self , message : str ):
165
156
"""Write warning message.
@@ -170,10 +161,7 @@ def warn(self, message: str):
170
161
171
162
if not self ._is_valid_level ("WARNING" ):
172
163
return
173
- if self ._colors :
174
- self ._write (content = Fore .YELLOW + message )
175
- else :
176
- self ._write (content = "warning | " + message )
164
+ self ._write (level = "WARN" , content = message )
177
165
178
166
def info (self , message : str ):
179
167
"""Write info message.
@@ -184,10 +172,7 @@ def info(self, message: str):
184
172
185
173
if not self ._is_valid_level ("INFO" ):
186
174
return
187
- if self ._colors :
188
- self ._write (content = Fore .BLUE + message )
189
- else :
190
- self ._write (content = "info | " + message )
175
+ self ._write (level = "INFO" , content = message )
191
176
192
177
def debug (self , message : str ):
193
178
"""Write debug message.
@@ -198,7 +183,4 @@ def debug(self, message: str):
198
183
199
184
if not self ._is_valid_level ("DEBUG" ):
200
185
return
201
- if self ._colors :
202
- self ._write (content = Fore .WHITE + message )
203
- else :
204
- self ._write (content = "debug | " + message )
186
+ self ._write (level = "DBUG" , content = message )
0 commit comments