Skip to content

Commit 9bfd080

Browse files
committed
Revert "Add extras to end of plain log format"
This reverts commit 943fa79. Reverting this until cleaning up old dependencies.
1 parent 943fa79 commit 9bfd080

File tree

3 files changed

+3
-52
lines changed

3 files changed

+3
-52
lines changed

README.rst

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ debug `True`/`False` Enable debug logging
5353
====== =============== =================================================
5454

5555
The plain format contains the fields timestamp, level name, message, logger name, and thread name.
56-
If the extras feature is used, key-value pairs will be added to the end of the message.
57-
5856
In the json format, there are more fields, with more detail. The fields in the json output are:
5957

6058
============ =======================================================================

fiaas_logging/__init__.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import logging
2222
import sys
2323
import threading
24-
from logging import LogRecord
2524

2625
LOG_EXTRAS = threading.local()
2726

@@ -78,25 +77,6 @@ def _build_location(fields):
7877
}
7978

8079

81-
class PlainExtraFormatter(logging.Formatter):
82-
def __init__(self):
83-
super().__init__("[%(asctime)s|%(levelname)7s] %(message)s [%(name)s|%(threadName)s]%(extra_string)s")
84-
85-
def format(self, record: LogRecord) -> str:
86-
if hasattr(record, "extras") and record.extras:
87-
record.extra_string = self._format_extras(record)
88-
else:
89-
record.extra_string = ""
90-
return super().format(record)
91-
92-
@staticmethod
93-
def _format_extras(record):
94-
pairs = []
95-
for k, v in record.extras.items():
96-
pairs.append(f"{k}={v}")
97-
return " " + ", ".join(pairs)
98-
99-
10080
class ExtraFilter(logging.Filter):
10181
def filter(self, record):
10282
extras = {}
@@ -130,5 +110,5 @@ def _create_default_handler(format):
130110
if format == "json":
131111
handler.setFormatter(FiaasFormatter())
132112
elif format == "plain":
133-
handler.setFormatter(PlainExtraFormatter())
113+
handler.setFormatter(logging.Formatter("[%(asctime)s|%(levelname)7s] %(message)s [%(name)s|%(threadName)s]"))
134114
return handler

tests/test_fiaas_logging.py

+2-29
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
import json
2020
import logging
2121
import sys
22-
from datetime import datetime
2322

2423
import mock
2524
import pytest
2625
from callee import InstanceOf, Attrs, List
2726
from six import StringIO
2827

29-
from fiaas_logging import ExtraFilter, set_extras, init_logging, FiaasFormatter, _create_default_handler, \
30-
PlainExtraFormatter
28+
from fiaas_logging import ExtraFilter, set_extras, init_logging, FiaasFormatter, _create_default_handler
3129

3230
TEST_MESSAGE = "This is a test message"
3331

@@ -48,7 +46,7 @@ def debug(self, request):
4846

4947
@pytest.fixture(params=("plain", "json"))
5048
def format(self, request):
51-
yield request.param, FiaasFormatter if request.param == "json" else PlainExtraFormatter
49+
yield request.param, FiaasFormatter if request.param == "json" else logging.Formatter
5250

5351
@staticmethod
5452
def _describe_stream_handler(formatter):
@@ -86,28 +84,3 @@ def test_json_log_has_extra(self):
8684
assert TEST_MESSAGE in log_entry["message"]
8785
assert log_entry["extras"]["one"] == "1"
8886
assert log_entry["extras"]["two"] == "2"
89-
90-
91-
class TestPlainExtraFormatter(object):
92-
@pytest.fixture
93-
def formatter(self):
94-
return PlainExtraFormatter()
95-
96-
@pytest.fixture
97-
def record(self):
98-
record = logging.LogRecord("name", logging.INFO, "pathname", 42, "msg", None, None)
99-
record.created = datetime(2000, 1, 1, 0, 0, 0).timestamp()
100-
record.msecs = 0
101-
return record
102-
103-
def test_no_extras(self, formatter, record):
104-
actual = formatter.format(record)
105-
assert actual == "[2000-01-01 00:00:00,000| INFO] msg [name|MainThread]"
106-
107-
def test_with_extras(self, formatter, record):
108-
record.extras = {
109-
"key1": "value1",
110-
"key2": "value2",
111-
}
112-
actual = formatter.format(record)
113-
assert actual == "[2000-01-01 00:00:00,000| INFO] msg [name|MainThread] key1=value1, key2=value2"

0 commit comments

Comments
 (0)