Skip to content

Commit

Permalink
only use valid Python logging levels
Browse files Browse the repository at this point in the history
fixes #13
  • Loading branch information
claytron committed Jun 22, 2015
1 parent 10ca2d0 commit b8b1cdf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
1.9.2 (Unreleased)
==================


- Only use valid Python logging levels. Round up to the closest level
if the passed in value does not exist.
[claytron]

1.9.1 (2014-12-01)
==================
Expand Down
17 changes: 17 additions & 0 deletions collective/recipe/plonesite/plonesite.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import logging
import os
from bisect import bisect
from datetime import datetime
try:
# Plone < 4.3
Expand Down Expand Up @@ -160,6 +161,22 @@ def main(app, parser):
except ValueError:
msg = 'The configured log-level is not valid: %s' % log_level
raise zc.buildout.UserError(msg)
current_log_levels = [
logging.NOTSET,
logging.DEBUG,
logging.INFO,
logging.WARNING,
logging.ERROR,
logging.CRITICAL,
]
if log_level not in current_log_levels:
try:
# Find the nearest log level and use that
lvl_index = bisect(current_log_levels, log_level)
log_level = current_log_levels[lvl_index]
except IndexError:
# If the log level is higher, catch that
log_level = 50
root_logger = logging.getLogger()
root_logger.setLevel(log_level)
logger.setLevel(logging.getLevelName(log_level))
Expand Down

0 comments on commit b8b1cdf

Please sign in to comment.