Fix double logging when testing
This commit is contained in:
parent
4c9d3ee3a6
commit
4ac54845fc
1 changed files with 21 additions and 24 deletions
|
@ -47,30 +47,6 @@ config.argv = ["none"] # Dont pass any argv to config parser
|
||||||
config.parse(silent=True, parse_config=False) # Plugins need to access the configuration
|
config.parse(silent=True, parse_config=False) # Plugins need to access the configuration
|
||||||
config.action = "test"
|
config.action = "test"
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
|
|
||||||
|
|
||||||
|
|
||||||
# Set custom formatter with realative time format (via: https://stackoverflow.com/questions/31521859/python-logging-module-time-since-last-log)
|
|
||||||
class TimeFilter(logging.Filter):
|
|
||||||
|
|
||||||
def filter(self, record):
|
|
||||||
try:
|
|
||||||
last = self.last
|
|
||||||
except AttributeError:
|
|
||||||
last = record.relativeCreated
|
|
||||||
|
|
||||||
delta = datetime.datetime.fromtimestamp(record.relativeCreated / 1000.0) - datetime.datetime.fromtimestamp(last / 1000.0)
|
|
||||||
|
|
||||||
record.relative = '{0:.3f}'.format(delta.seconds + delta.microseconds / 1000000.0)
|
|
||||||
|
|
||||||
self.last = record.relativeCreated
|
|
||||||
return True
|
|
||||||
|
|
||||||
log = logging.getLogger()
|
|
||||||
fmt = logging.Formatter(fmt='+%(relative)ss %(levelname)-8s %(name)s %(message)s')
|
|
||||||
[hndl.addFilter(TimeFilter()) for hndl in log.handlers]
|
|
||||||
[hndl.setFormatter(fmt) for hndl in log.handlers]
|
|
||||||
|
|
||||||
# Load plugins
|
# Load plugins
|
||||||
from Plugin import PluginManager
|
from Plugin import PluginManager
|
||||||
|
|
||||||
|
@ -94,6 +70,27 @@ config.trackers = []
|
||||||
config.data_dir = TEST_DATA_PATH # Use test data for unittests
|
config.data_dir = TEST_DATA_PATH # Use test data for unittests
|
||||||
config.initLogging()
|
config.initLogging()
|
||||||
|
|
||||||
|
# Set custom formatter with realative time format (via: https://stackoverflow.com/questions/31521859/python-logging-module-time-since-last-log)
|
||||||
|
class TimeFilter(logging.Filter):
|
||||||
|
|
||||||
|
def filter(self, record):
|
||||||
|
try:
|
||||||
|
last = self.last
|
||||||
|
except AttributeError:
|
||||||
|
last = record.relativeCreated
|
||||||
|
|
||||||
|
delta = datetime.datetime.fromtimestamp(record.relativeCreated / 1000.0) - datetime.datetime.fromtimestamp(last / 1000.0)
|
||||||
|
|
||||||
|
record.relative = '{0:.3f}'.format(delta.seconds + delta.microseconds / 1000000.0)
|
||||||
|
|
||||||
|
self.last = record.relativeCreated
|
||||||
|
return True
|
||||||
|
|
||||||
|
log = logging.getLogger()
|
||||||
|
fmt = logging.Formatter(fmt='+%(relative)ss %(levelname)-8s %(name)s %(message)s')
|
||||||
|
[hndl.addFilter(TimeFilter()) for hndl in log.handlers]
|
||||||
|
[hndl.setFormatter(fmt) for hndl in log.handlers]
|
||||||
|
|
||||||
from Site.Site import Site
|
from Site.Site import Site
|
||||||
from Site import SiteManager
|
from Site import SiteManager
|
||||||
from User import UserManager
|
from User import UserManager
|
||||||
|
|
Loading…
Reference in a new issue