changeset 9a7d559cf2cd in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=9a7d559cf2cd
description:
        Setup default logging for WSGI application

        issue8510
        review263911003
diffstat:

 CHANGELOG                   |  1 +
 doc/topics/start_server.rst |  4 ++++
 trytond/application.py      |  8 ++++++++
 3 files changed, 13 insertions(+), 0 deletions(-)

diffs (48 lines):

diff -r f4393bd5664c -r 9a7d559cf2cd CHANGELOG
--- a/CHANGELOG Wed Jul 17 21:15:37 2019 +0200
+++ b/CHANGELOG Tue Jul 23 00:09:25 2019 +0200
@@ -1,3 +1,4 @@
+* Setup default logging for WSGI app
 * Add format argument to report format_date function
 * Change expand attribute into a factor
 * Allow SQL expression as value of fields
diff -r f4393bd5664c -r 9a7d559cf2cd doc/topics/start_server.rst
--- a/doc/topics/start_server.rst       Wed Jul 17 21:15:37 2019 +0200
+++ b/doc/topics/start_server.rst       Tue Jul 23 00:09:25 2019 +0200
@@ -26,12 +26,16 @@
 
  * `TRYTOND_CONFIG`: Point to :ref:`configuration <topics-configuration>` file.
  * `TRYTOND_LOGGING_CONFIG`: Point to :ref:`logging <topics-logs>` file.
+ * `TRYTOND_LOGGING_LEVEL`: An integer to set the default `logging level`_
+   (default: `ERROR`).
  * `TRYTOND_COROUTINE`: Use coroutine for concurrency.
  * `TRYTOND_DATABASE_NAMES`: A list of database names in CSV format, using
    python default dialect.
 
 .. warning:: You must manage to serve the static files from the web root.
 
+.. _`logging level`: 
<https://docs.python.org/library/logging.html#logging-levels>`.
+
 Coroutine server
 ----------------
 
diff -r f4393bd5664c -r 9a7d559cf2cd trytond/application.py
--- a/trytond/application.py    Wed Jul 17 21:15:37 2019 +0200
+++ b/trytond/application.py    Tue Jul 23 00:09:25 2019 +0200
@@ -10,8 +10,16 @@
 
 # Logging must be set before importing
 logging_config = os.environ.get('TRYTOND_LOGGING_CONFIG')
+logging_level = int(os.environ.get(
+        'TRYTOND_LOGGING_LEVEL', default=logging.ERROR))
 if logging_config:
     logging.config.fileConfig(logging_config)
+else:
+    logformat = ('%(process)s %(thread)s [%(asctime)s] '
+        '%(levelname)s %(name)s %(message)s')
+    level = max(logging_level, logging.NOTSET)
+    logging.basicConfig(level=level, format=logformat)
+logging.captureWarnings(True)
 
 if os.environ.get('TRYTOND_COROUTINE'):
     from gevent import monkey

Reply via email to