Skip to content

Commit

Permalink
feature: add support for log messages formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
HorlogeSkynet committed Feb 10, 2024
1 parent 9755fe6 commit aa5232f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ New Features
^^^^^^^^^^^^

- Add Catalan localisation (`#966`_, welpo)
- Add support for log messages formatting (`#976`_, HorlogeSkynet)

[general]
log-format =

.. _#966: https://github.com/posativ/isso/pull/966
.. _#976: https://github.com/posativ/isso/pull/976

Breaking Changes
^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions contrib/isso-dev.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ max-age = 15m
notify = stdout
reply-notifications = false
log-file =
log-format =
latest-enabled = true

[admin]
Expand Down
14 changes: 14 additions & 0 deletions docs/docs/reference/server-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Here are the **default values** for this section:
max-age = 15m
notify = stdout
log-file =
log-format =
gravatar = false
gravatar-url = https://www.gravatar.com/avatar/{}?d=identicon&s=55
latest-enabled = false
Expand Down Expand Up @@ -118,6 +119,19 @@ log-file

Default: (empty)

log-format
Format string for console messages logged to file (see ``log-file`` option).
Also see Python `LogRecord attributes`_ documentation for the full list of
attributes.
Please do note this option is interpolated by Python runtime and may lead
to security issues if not trusted.
Example: ``%(asctime)s:%(levelname)s:%(name)s:%(message)s``, which prepends
log messages with timestamp, log level and internal logger name.

Default: (empty)

.. _LogRecord attributes: https://docs.python.org/3/library/logging.html#logrecord-attributes

gravatar
When set to ``true`` this will add the property "gravatar_image"
containing the link to a gravatar image to every comment. If a comment
Expand Down
3 changes: 3 additions & 0 deletions isso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ def main():
if conf.get("general", "log-file"):
handler = logging.FileHandler(conf.get("general", "log-file"))

if conf.get("general", "log-format"):
handler.setFormatter(logging.Formatter(conf.get("general", "log-format")))

logger.addHandler(handler)
logging.getLogger("werkzeug").addHandler(handler)

Expand Down
5 changes: 5 additions & 0 deletions isso/isso.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ reply-notifications=false
# Log console messages to file instead of standard output.
log-file =

# Format string for console messages logged to file (see Python
# ``logging.Formatter``).
# Example: ``%(asctime)s:%(levelname)s:%(name)s:%(message)s``
log-format =

# adds property "gravatar_image" to json response when true
# will automatically build md5 hash by email and use "gravatar_url" to build
# the url to the gravatar image
Expand Down

0 comments on commit aa5232f

Please sign in to comment.