Custom logging for tests to spot possible performance bottlenecks easier
This commit is contained in:
parent
8e2be5cfe2
commit
be755fe25e
1 changed files with 25 additions and 0 deletions
|
@ -6,6 +6,7 @@ import logging
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import gc
|
import gc
|
||||||
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import mock
|
import mock
|
||||||
|
@ -27,8 +28,32 @@ sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + "/..")) # Import
|
||||||
from Config import config
|
from Config import config
|
||||||
config.argv = ["none"] # Dont pass any argv to config parser
|
config.argv = ["none"] # Dont pass any argv to config parser
|
||||||
config.parse(silent=True) # Plugins need to access the configuration
|
config.parse(silent=True) # Plugins need to access the configuration
|
||||||
|
config.action = "test"
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
|
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
|
||||||
from Plugin import PluginManager
|
from Plugin import PluginManager
|
||||||
PluginManager.plugin_manager.loadPlugins()
|
PluginManager.plugin_manager.loadPlugins()
|
||||||
config.loadPlugins()
|
config.loadPlugins()
|
||||||
|
|
Loading…
Reference in a new issue