Skip to content

Instantly share code, notes, and snippets.

@HorlogeSkynet
Last active April 14, 2024 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HorlogeSkynet/7052787db2d3e2027a848ed399d824c4 to your computer and use it in GitHub Desktop.
Save HorlogeSkynet/7052787db2d3e2027a848ed399d824c4 to your computer and use it in GitHub Desktop.
[isso] feature: add support for log messages formatting

Isso feature: add support for log messages formatting

Patch v1.0.0 (for Isso v0.13.0+)

Why ?

See isso-comments/isso#976 for context.

How to apply this patch in production ?

apt-get update && apt-get install patchutils

cd /path/to/isso/
wget -qO- https://gist.githubusercontent.com/HorlogeSkynet/7052787db2d3e2027a848ed399d824c4/raw/isso-976.patch \
    | filterdiff -p 1 -i 'isso/*' \
    | patch -p 2
From a76b1392e8ee5eb4305999a0a1288806054476f4 Mon Sep 17 00:00:00 2001
From: Samuel FORESTIER <samuel+dev@forestier.app>
Date: Wed, 8 Nov 2023 20:14:43 +0100
Subject: [PATCH] feature: add support for log messages formatting
---
CHANGES.rst | 7 ++++++-
contrib/isso-dev.cfg | 1 +
docs/docs/reference/server-config.rst | 12 ++++++++++++
isso/__init__.py | 3 +++
isso/isso.cfg | 4 ++++
5 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/CHANGES.rst b/CHANGES.rst
index 21d711078..34b763136 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -14,7 +14,12 @@ New Features
Breaking Changes
^^^^^^^^^^^^^^^^
-- TBD
+- Change default log messages formatting and make it configurable (`#976`_, HorlogeSkynet)
+
+ [general]
+ log-format = %(asctime)s:%(levelname)s:%(name)s:%(message)s
+
+.. _#976: https://github.com/posativ/isso/pull/976
Bugfixes & Improvements
^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/contrib/isso-dev.cfg b/contrib/isso-dev.cfg
index d3820ee51..b1f817e4d 100644
--- a/contrib/isso-dev.cfg
+++ b/contrib/isso-dev.cfg
@@ -16,6 +16,7 @@ max-age = 15m
notify = stdout
reply-notifications = false
log-file =
+log-format = %(asctime)s:%(levelname)s:%(name)s:%(message)s
latest-enabled = true
[admin]
diff --git a/docs/docs/reference/server-config.rst b/docs/docs/reference/server-config.rst
index 833bd6bbd..84154a625 100644
--- a/docs/docs/reference/server-config.rst
+++ b/docs/docs/reference/server-config.rst
@@ -49,6 +49,7 @@ Here are the **default values** for this section:
max-age = 15m
notify = stdout
log-file =
+ log-format = %(asctime)s:%(levelname)s:%(name)s:%(message)s
gravatar = false
gravatar-url = https://www.gravatar.com/avatar/{}?d=identicon&s=55
latest-enabled = false
@@ -118,6 +119,17 @@ 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.
+
+ Default: %(asctime)s:%(levelname)s:%(name)s:%(message)s
+
+.. _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
diff --git a/isso/__init__.py b/isso/__init__.py
index 68468de73..e90d9976e 100644
--- a/isso/__init__.py
+++ b/isso/__init__.py
@@ -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)
diff --git a/isso/isso.cfg b/isso/isso.cfg
index 3827a61bb..b54f52ede 100644
--- a/isso/isso.cfg
+++ b/isso/isso.cfg
@@ -51,6 +51,10 @@ 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``).
+log-format = %(asctime)s:%(levelname)s:%(name)s:%(message)s
+
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment