_format_msg_json doesn't merge arguments
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 52/100
Direzione di ricerca
Inizia in fluent/handler.py da FluentRecordFormatter, prestando particolare attenzione al percorso json.loads(str(msg)), e rivedi tests/test_handler.py. Esegui i test esistenti di handler, quindi copri la chiamata di logger segnalata con argomenti e conferma che il JSON emesso contenga i valori sostituiti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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'])
- Lingua principale
- Python
- Stelle
- 457
- Fork
- 138
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fluent/fluent-logger-python
-
support of `asctime` Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
fluent/fluent-logger-python#210 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
fluent/fluent-logger-python#196 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
fluent/fluent-logger-python#195 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
fluent/fluent-logger-python#194 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
fluent/fluent-logger-python#193 · 3 commenti ·
Tutte le issue di fluent/fluent-logger-python
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
use-agent-os/agent-os#3314 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
BasedHardware/omi#15662 · 1 commento ·
-
documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
AiursoftWeb/AnduinOS-2#19 ·