Add log JSON formatter
This commit is contained in:
parent
4750d1c5ef
commit
3c99928a27
27 changed files with 402 additions and 41 deletions
41
util/test/test_log_util.py
Normal file
41
util/test/test_log_util.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
import pytest
|
||||
from util.log import logfile_path, filter_logs
|
||||
from app import FILTERED_VALUES
|
||||
|
||||
|
||||
def test_filter_logs():
|
||||
values = {
|
||||
'user': {
|
||||
'password': "toto"
|
||||
},
|
||||
'blob': '1234567890asdfewkqresfdsfewfdsfd',
|
||||
'unfiltered': 'foo'
|
||||
}
|
||||
filter_logs(values, FILTERED_VALUES)
|
||||
assert values == {'user': {'password': '[FILTERED]'}, 'blob': '12345678', 'unfiltered': "foo"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('debug,jsonfmt,expected', [
|
||||
(False, False, "conf/logging.conf"),
|
||||
(False, True, "conf/logging_json.conf"),
|
||||
(True, False, "conf/logging_debug.conf"),
|
||||
(True, True, "conf/logging_debug_json.conf"),
|
||||
])
|
||||
def test_logfile_path(debug, jsonfmt, expected, monkeypatch):
|
||||
assert logfile_path(jsonfmt=jsonfmt, debug=debug) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('debug,jsonfmt,expected', [
|
||||
("false", "false", "conf/logging.conf"),
|
||||
("false", "true", "conf/logging_json.conf"),
|
||||
("true", "false", "conf/logging_debug.conf"),
|
||||
("true", "true", "conf/logging_debug_json.conf"),
|
||||
])
|
||||
def test_logfile_path_env(debug, jsonfmt, expected, monkeypatch):
|
||||
monkeypatch.setenv("DEBUGLOG", debug)
|
||||
monkeypatch.setenv("JSONLOG", jsonfmt)
|
||||
assert logfile_path() == expected
|
||||
|
||||
|
||||
def test_logfile_path_default():
|
||||
assert logfile_path() == "conf/logging.conf"
|
Reference in a new issue