mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-13 03:25:45 +00:00
Support Loguru as a logger (#2036)
This commit is contained in:
@@ -4,6 +4,8 @@ import pytest
|
||||
from changedetectionio import changedetection_app
|
||||
from changedetectionio import store
|
||||
import os
|
||||
import sys
|
||||
from loguru import logger
|
||||
|
||||
# https://github.com/pallets/flask/blob/1.1.2/examples/tutorial/tests/test_auth.py
|
||||
# Much better boilerplate than the docs
|
||||
@@ -11,6 +13,15 @@ import os
|
||||
|
||||
global app
|
||||
|
||||
# https://loguru.readthedocs.io/en/latest/resources/migration.html#replacing-caplog-fixture-from-pytest-library
|
||||
# Show loguru logs only if CICD pytest fails.
|
||||
from loguru import logger
|
||||
@pytest.fixture
|
||||
def reportlog(pytestconfig):
|
||||
logging_plugin = pytestconfig.pluginmanager.getplugin("logging-plugin")
|
||||
handler_id = logger.add(logging_plugin.report_handler, format="{message}")
|
||||
yield
|
||||
logger.remove(handler_id)
|
||||
|
||||
def cleanup(datastore_path):
|
||||
import glob
|
||||
@@ -41,6 +52,18 @@ def app(request):
|
||||
|
||||
app_config = {'datastore_path': datastore_path, 'disable_checkver' : True}
|
||||
cleanup(app_config['datastore_path'])
|
||||
|
||||
logger_level = 'TRACE'
|
||||
|
||||
logger.remove()
|
||||
log_level_for_stdout = { 'DEBUG', 'SUCCESS' }
|
||||
logger.configure(handlers=[
|
||||
{"sink": sys.stdout, "level": logger_level,
|
||||
"filter" : lambda record: record['level'].name in log_level_for_stdout},
|
||||
{"sink": sys.stderr, "level": logger_level,
|
||||
"filter": lambda record: record['level'].name not in log_level_for_stdout},
|
||||
])
|
||||
|
||||
datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], include_default_watches=False)
|
||||
app = changedetection_app(app_config, datastore)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user