Skip to content

Commit

Permalink
feat: Add ability to log in json, with doc example
Browse files Browse the repository at this point in the history
  • Loading branch information
favilo committed Nov 5, 2024
1 parent 59f9b3a commit 54c9afa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,51 @@ Here is an example of a logging configuration that uses ``${LOG_PATH}``::
}
}
}


Example
~~~~~~~

With the following configuration Rally will log to ``~/.rally/logs/rally.log`` and ``~/.rally/logs/rally.json``, the
latter being a JSON file::

{
"version": 1,
"formatters": {
"normal": {
"format": "%(asctime)s,%(msecs)d %(actorAddress)s/PID:%(process)d %(name)s %(levelname)s %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
"()": "esrally.log.configure_utc_formatter"
},
"json": {
"datefmt": "%Y-%m-%d %H:%M:%S",
"class": "pythonjsonlogger.jsonlogger.JsonFormatter"
}
},
"handlers": {
"rally_log_handler": {
"()": "esrally.log.configure_file_handler",
"filename": "${LOG_PATH}/rally.log",
"encoding": "UTF-8",
"formatter": "normal"
},
"rally_json_handler": {
"()": "esrally.log.configure_file_handler",
"filename": "${LOG_PATH}/rally.json",
"encoding": "UTF-8",
"formatter": "json"
}
},
"root": {
"handlers": ["rally_log_handler", "rally_json_handler"],
"level": "INFO"
},
"loggers": {
"elasticsearch": {
"handlers": ["rally_log_handler", "rally_json_handler"],
"level": "WARNING",
"propagate": false
}
}
}

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ dependencies = [
"zstandard==0.21.0",
# License: Python Software Foundation License
"typing-extensions==4.12.2",
# License: BSD-2-Clause license
"python-json-logger==2.0.7",
]

[project.optional-dependencies]
Expand Down

0 comments on commit 54c9afa

Please sign in to comment.