-
Notifications
You must be signed in to change notification settings - Fork 21
/
LogBase.py
50 lines (33 loc) · 973 Bytes
/
LogBase.py
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
import logging
import threading
import abc
class LoggerMixin(metaclass=abc.ABCMeta):
@abc.abstractproperty
def loggerPath(self):
pass
def __init__(self):
self.loggers = {}
self.lastLoggerIndex = 1
@property
def log(self):
threadName = threading.current_thread().name
if "Thread-" in threadName:
if threadName not in self.loggers:
self.loggers[threadName] = logging.getLogger("%s.Thread-%d" % (self.loggerPath, self.lastLoggerIndex))
self.lastLoggerIndex += 1
# If we're not called in the context of a thread, just return the base log-path
else:
self.loggers[threadName] = logging.getLogger("%s" % (self.loggerPath,))
return self.loggers[threadName]
class TestClass(LoggerMixin):
loggerPath = 'Main.Wat'
def test(self):
self.log.info("Wat?")
if __name__ == "__main__":
print("Test mode!")
import logSetup
logSetup.initLogging()
scraper = TestClass()
print(scraper)
extr = scraper.test()
# print(extr['fLinks'])