@@ -350,10 +350,19 @@ The config below works with the `Waitress wsgi server
350350roundup.wsgi channel. It also controls the `TransLogger
351351middleware <https://github.com/pasteorg/paste>`_ configured to
352352use roundup.wsgi.translogger, to produce httpd style combined
353- logs. The log file is specified relative to the current working
353+ logs.
354+
355+ The log file is specified relative to the current working
354356directory not the tracker home. The tracker home is the
355- subdirectory demo under the current working directory. The
356- commented config is::
357+ subdirectory demo under the current working directory.
358+
359+ The config also expects the ``python-json-logger`` package to be
360+ installed so that it can produce a jsonl (json line) formatted
361+ output log file. This format is useful for sending to log
362+ management/observability platforms like elasticsearch, splunk,
363+ logly, or honeycomb.
364+
365+ The commented config is::
357366
358367 {
359368 "version": 1, // only supported version
@@ -364,6 +373,28 @@ commented config is::
364373 "standard": {
365374 "format": "%(asctime)s %(trace_id)s %(levelname)s %(name)s:%(module)s %(msg)s"
366375 },
376+ // Used to dump all log requests in jsonl format.
377+ // Each json object is on one line. Can be pretty printed
378+ // using:
379+ // python -m json.tool --json-lines --sort-keys < roundup.json.log
380+ // jq --slurp --sort-keys . < roundup.json.log
381+ // requires that you pip install python-json-logger
382+ // * does not report the fields in reserved_attrs
383+ // * example to remap a field in the log to traceID in
384+ // the output json. (note trace_id_eg is not defined by
385+ // logging
386+ // * also adds the env atribute to json with the value of demo
387+ "json": {
388+ "()": "pythonjsonlogger.json.JsonFormatter",
389+ "reserved_attrs": ["ROUNDUP_CONTEXT_FILTER_CALLED",
390+ "msg", "pct_char", "relativeCreated"],
391+ "rename_fields": {
392+ "trace_id_eg": "traceID"
393+ },
394+ "static_fields": {
395+ "env": "demo"
396+ }
397+ },
367398 // used for waitress wsgi server to produce httpd style logs
368399 "http": {
369400 "format": "%(message)s %(trace_id)"
@@ -385,6 +416,13 @@ commented config is::
385416 "class": "logging.FileHandler",
386417 "filename": "demo/roundup.log"
387418 },
419+ // handler for json output log file
420+ "roundup_json": {
421+ "level": "DEBUG", // "DEBUG",
422+ "formatter": "json",
423+ "class": "logging.FileHandler",
424+ "filename": "demo/roundup.json.log"
425+ },
388426 // print to stdout - fall through for other logging
389427 "default": {
390428 "level": "DEBUG",
@@ -396,15 +434,17 @@ commented config is::
396434 "loggers": {
397435 "": {
398436 "handlers": [
399- "default"
437+ "default",
438+ "roundup_json" // add json formatted logging
400439 ],
401440 "level": "DEBUG",
402441 "propagate": false
403442 },
404443 // used by roundup.* loggers
405444 "roundup": {
406445 "handlers": [
407- "roundup"
446+ "roundup",
447+ "roundup_json"
408448 ],
409449 "level": "DEBUG",
410450 "propagate": false // note pytest testing with caplog requires
0 commit comments