[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Maposmatic-dev] [PATCH maposmatic 1/2] The logging format can now be sp
From: |
David Decotigny |
Subject: |
[Maposmatic-dev] [PATCH maposmatic 1/2] The logging format can now be specified |
Date: |
Tue, 12 Jan 2010 00:07:39 +0100 |
From: David Decotigny <address@hidden>
This patch adds support for logging message format, and also allows to
log onto stderr when the logging file name is '' or None. Ity also
removed some dead code (impossible exception path).
---
www/settings.py | 16 +++++++++-------
www/settings_local.py-template | 1 +
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/www/settings.py b/www/settings.py
index 3d8dc1a..4efcc84 100644
--- a/www/settings.py
+++ b/www/settings.py
@@ -154,13 +154,15 @@ MAP_LANGUAGES = [("fr_BE.UTF-8", u"Royaume de Belgique
(FR)"),
LOG = logging.getLogger(os.environ.get("MAPOSMATIC_LOG_TARGET",
"maposmatic"))
-LOG.setLevel(os.environ.get("MAPOSMATIC_LOG_LEVEL",
- DEFAULT_MAPOSMATIC_LOG_LEVEL))
-try:
- _fh = logging.FileHandler(os.environ.get('MAPOSMATIC_LOG_FILE',
- DEFAULT_MAPOSMATIC_LOG_FILE))
-except KeyError:
- _fh = logging.FileHandler('maposmatic.log')
+LOG.setLevel(int(os.environ.get("MAPOSMATIC_LOG_LEVEL",
+ DEFAULT_MAPOSMATIC_LOG_LEVEL)))
+_log_dest = os.environ.get('MAPOSMATIC_LOG_FILE', DEFAULT_MAPOSMATIC_LOG_FILE)
+if _log_dest:
+ _fh = logging.FileHandler(_log_dest)
+else:
+ _fh = logging.StreamHandler()
+_fh.setFormatter(logging.Formatter(os.environ.get("MAPOSMATIC_LOG_FORMAT",
+
DEFAULT_MAPOSMATIC_LOG_FORMAT)))
LOG.addHandler(_fh)
LOG.info("log restarted.")
diff --git a/www/settings_local.py-template b/www/settings_local.py-template
index ea58a1c..5a8c646 100644
--- a/www/settings_local.py-template
+++ b/www/settings_local.py-template
@@ -52,6 +52,7 @@ DEFAULT_MAPOSMATIC_LOG_FILE =
'/path/to/maposmatic/logs/maposmatic.log'
# Default log level when the env variable DEFAULT_MAPOSMATIC_LOG_LEVEL
# is not set
DEFAULT_MAPOSMATIC_LOG_LEVEL = logging.INFO
+DEFAULT_MAPOSMATIC_LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s -
%(message)s"
# Base bounding box
BASE_BOUNDING_BOX = (51.956, -7.838, 41.458, 11.937)
--
1.6.4.4
- [Maposmatic-dev] [PATCH maposmatic 1/2] The logging format can now be specified,
David Decotigny <=