Skip to content

Commit 3c76c7b

Browse files
committed
add levels output
1 parent a5b5061 commit 3c76c7b

File tree

4 files changed

+16
-113
lines changed

4 files changed

+16
-113
lines changed

logs.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
plfm = 'windows'
1818

1919

20+
2021
class Log:
2122
file_path = os.getcwd()
2223
file_name = 'file_log'
@@ -56,15 +57,23 @@ def getFullPath(self):
5657
def getLogger(self):
5758
return self.logger
5859

59-
def addToLog(self, s):
60+
def addToLog(self, s, type_output='info'):
6061
if plfm == 'windows':
6162
file_ = self.file_path + "\\logs\\" + self.file_name + "_" + strftime('%d_%m_%Y', gmtime()) + ".txt"
6263
else:
6364
file_ = self.file_path + "/logs/" + self.file_name + "_" + strftime('%d_%m_%Y', gmtime()) + ".txt"
6465

6566
if not os.path.isfile(file_):
6667
self.init_logging()
67-
self.getLogger().info(s)
68+
69+
output_level = {'info': 0, 'warning': 1, 'debug': 2}
70+
71+
if output_level[type_output] == 0:
72+
self.getLogger().info(s)
73+
elif output_level[type_output] == 1:
74+
self.getLogger().warning(s)
75+
else:
76+
self.getLogger().debug(s)
6877

6978
def initLogFolder(self):
7079
try:

test_loger/logs.py

-110
This file was deleted.

test_loger/logs.pyc

-3.48 KB
Binary file not shown.

test_loger/test.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33

44
Log = Log(os.getcwd(), '_hello_world_logs')
55

6-
Log.addToLog('Hello world')
6+
Log.addToLog('Hello world', 'info')
7+
8+
Log.addToLog('Hello world', 'warning')
9+
10+
Log.addToLog('Hello world', 'debug')

0 commit comments

Comments
 (0)