_format_msg_json doesn't merge arguments
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 52/100
Research direction
Start in fluent/handler.py at FluentRecordFormatter, especially the json.loads(str(msg)) path, and review tests/test_handler.py. Run the existing handler tests, then cover the reported logger call with arguments and confirm the emitted JSON contains the substituted values.
Written by the indexing model from the issue text.
Description
I'm using the FluentHandler class for Python logging module. I was hoping to pass a json string to the logger and have it interpreted as json, which it does, but the FluentRecordFormatter doesn't merge logged arguments in.
Example
logger = logging.getLogger('fluent.test')
logger.info('{"from": "%(a)s", "to": "%(b)s"}', {"a":"userA","b":"userB"})
Expected result
{"type":"INFO","from": "userA", "to": "userB"}
Actual result
{"type":"INFO","from":"%(a)s","to":"%(b)s"}
I expected the arguments to be merged in based on the behaviour of the default Python formatter which calls record.getMessage which merges in arguments
if self.args:
msg = msg % self.args
However, the behaviour of the FluentRecordFormatter is to json.loads(str(msg)) the message, and ignore any arguments.
Would it be suitable to merge in the arguments when loading the json? I'd be happy to contribute a PR for it. Here's a test that would cover it.
def test_json_encoded_message_with_args(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)
with handler:
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('{"key": "%(a)s", "param": "value"}', {"a": "hello world!"})
log.removeHandler(handler)
data = self.get_data()
self.assertTrue('key' in data[0][2])
self.assertEqual('hello world!', data[0][2]['key'])
- Dominant language
- Python
- Stars
- 457
- Forks
- 138
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fluent/fluent-logger-python
-
support of `asctime` Open
Difficulty 3/5 1-2 days Newbie friendliness 48/100
fluent/fluent-logger-python#210 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
fluent/fluent-logger-python#196 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
fluent/fluent-logger-python#195 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
fluent/fluent-logger-python#194 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
fluent/fluent-logger-python#193 · 3 comments ·
All issues in fluent/fluent-logger-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·