Add log-auto-indent option to control multiline formatting
This commit is contained in:
@@ -53,13 +53,77 @@ def test_multiline_message():
|
||||
# this is called by logging.Formatter.format
|
||||
record.message = record.getMessage()
|
||||
|
||||
style = PercentStyleMultiline(logfmt)
|
||||
output = style.format(record)
|
||||
ai_on_style = PercentStyleMultiline(logfmt, True)
|
||||
output = ai_on_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\n"
|
||||
" line2"
|
||||
)
|
||||
|
||||
ai_off_style = PercentStyleMultiline(logfmt, False)
|
||||
output = ai_off_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\nline2"
|
||||
)
|
||||
|
||||
ai_none_style = PercentStyleMultiline(logfmt, None)
|
||||
output = ai_none_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\nline2"
|
||||
)
|
||||
|
||||
record.auto_indent = False
|
||||
output = ai_on_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\nline2"
|
||||
)
|
||||
|
||||
record.auto_indent = True
|
||||
output = ai_off_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\n"
|
||||
" line2"
|
||||
)
|
||||
|
||||
record.auto_indent = "False"
|
||||
output = ai_on_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\nline2"
|
||||
)
|
||||
|
||||
record.auto_indent = "True"
|
||||
output = ai_off_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\n"
|
||||
" line2"
|
||||
)
|
||||
|
||||
# bad string values default to False
|
||||
record.auto_indent = "junk"
|
||||
output = ai_off_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\nline2"
|
||||
)
|
||||
|
||||
# anything other than string or int will default to False
|
||||
record.auto_indent = dict()
|
||||
output = ai_off_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\nline2"
|
||||
)
|
||||
|
||||
record.auto_indent = "5"
|
||||
output = ai_off_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\n line2"
|
||||
)
|
||||
|
||||
record.auto_indent = 5
|
||||
output = ai_off_style.format(record)
|
||||
assert output == (
|
||||
"dummypath 10 INFO Test Message line1\n line2"
|
||||
)
|
||||
|
||||
|
||||
def test_colored_short_level():
|
||||
logfmt = "%(levelname).1s %(message)s"
|
||||
|
||||
Reference in New Issue
Block a user