Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding plaintext and JSON logging formatters #1426

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5c94a69
Adding plaintext and JSON logging formatters
Alsheh Apr 20, 2021
88b3804
putting formatter creation logic in a class
Alsheh Apr 20, 2021
489ffa3
Merge pull request #1 from Alsheh/logformat-formatter-factory
Alsheh Apr 20, 2021
62ace15
Adding the ability to add default values for required fields in the l…
Alsheh Apr 21, 2021
67c6c7f
Avoid overwriting record fields with default values.
Alsheh Apr 21, 2021
6bedd36
Merge pull request #2 from Alsheh/logformat-default-value-parser
Alsheh Apr 21, 2021
5f1b906
Adding the only supervisor dependency: python-json-logger
Alsheh Apr 21, 2021
407b37f
Merge pull request #3 from Alsheh/logging-formatters-dependency
Alsheh Apr 21, 2021
45803b7
Adding log attributes to DummyPConfig object
Alsheh Apr 21, 2021
cee1eb0
Merge pull request #4 from Alsheh/logging-formatters-ci-test
Alsheh Apr 21, 2021
30ab58f
Adding logging formatters options tests
Alsheh Apr 21, 2021
f8e4f93
Adding the ability to set level by description
Alsheh Apr 21, 2021
5853312
Merge pull request #6 from Alsheh/logging-formatters-local
Alsheh Apr 21, 2021
f52b2e2
Adding the ability to set level by number
Alsheh Apr 21, 2021
01dfa8d
Merge pull request #7 from Alsheh/logging-formatters-local
Alsheh Apr 21, 2021
646f19d
Reverting commit f52b2e2fa518f1e0df9272dc7d21bba55d06a207
Alsheh Apr 21, 2021
a3bb1d1
Removing unintended unit testing
Alsheh Apr 21, 2021
c2654e8
Merge pull request #8 from Alsheh/logging-formatters-local
Alsheh Apr 22, 2021
771e101
Fxing a typo
Alsheh Apr 22, 2021
9fbe7e6
Using for/else for simplicity
Alsheh Apr 22, 2021
29fcd9a
Refactoring formatters factory conditionals
Alsheh Apr 22, 2021
1f59e79
Removing duplicate code
Alsheh Apr 22, 2021
618b16b
Code restructuring and CI tests updates
Alsheh Apr 28, 2021
e2c1d80
Merge pull request #9 from Alsheh/logging-formatters-local
Alsheh Apr 28, 2021
959c928
Making the logger backward compatible
Alsheh Apr 28, 2021
ae76fb3
Merge pull request #10 from Alsheh/logging-formatters-local
Alsheh Apr 28, 2021
b573bd3
Removing jsonformatter dependency
Alsheh Apr 29, 2021
871b55a
Merge pull request #11 from Alsheh/logging-formatters-local
Alsheh Apr 29, 2021
b9cde7d
loggers updates
Alsheh Apr 29, 2021
2a50bb3
Merge pull request #14 from Alsheh/logging-formatters-local
Alsheh Apr 29, 2021
5736268
Fixing an issue where numbers are considered valid JSON by the praser
Alsheh May 4, 2021
b623852
Merge pull request #17 from Alsheh/logging-formatters-local
Alsheh May 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Making the logger backward compatible
Alsheh committed Apr 28, 2021
commit 959c928318867a0340eb91026205f253ab68765c
14 changes: 8 additions & 6 deletions supervisor/loggers.py
Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@ def format(self, record):
message_dict = json.loads(message)
record.message = None
except json.decoder.JSONDecodeError:
record.message = message.rstrip('\n')
record.message = as_string(message).rstrip('\n')

# only format time if needed
if "asctime" in self._required_fields:
@@ -398,9 +398,6 @@ def emit(self, record):
try:
msg = self.formatter.format(record)
if 'b' in self.mode:
#msg = bytes(msg, 'utf-8')
#bytes_terminator = bytes(self.terminator, 'utf-8')
#self.stream.write(msg + bytes_terminator)
msg = as_bytes(msg + self.terminator)
self.stream.write(msg)
else:
@@ -503,7 +500,7 @@ class LogRecord:
def __init__(self, level, msg, **kw):
self.level = level
self.levelname = LOG_LEVELS_BY_NUM[level]
self.msg = as_string(msg)
self.msg = msg
self.kw = kw
self.dictrepr = None
self.created = time.time()
@@ -524,7 +521,12 @@ def asdict(self):
return self.dictrepr

def getMessage(self):
return self.msg
try:
return as_string(self.msg) % self.kw
except ValueError as e:
# Skip string interpolation when string
# formatting charcaters are not escaped.
return as_string(self.msg)

class Logger:
def __init__(self, level=None, handlers=None):