Permalink
Browse files

further logging improvements, ensuring that logging works in Docker, …

…removing the blatant eval() security hole for configuration, changing the logging format so that it includes timezone
  • Loading branch information...
shawnmjones committed Jul 8, 2018
1 parent 9044b5d commit 9d0ae22d5c90510a932084c9c5e39f1d4f81129f
Showing with 19 additions and 9 deletions.
  1. +1 −3 config/default.py
  2. +1 −1 instance/application.cfg
  3. +16 −4 mementoembed/__init__.py
  4. +1 −1 sample_appconfig.cfg
View
@@ -1,5 +1,3 @@
import logging
CACHEMODEL = 'SQLite'
LOGLEVEL = logging.DEBUG
LOGLEVEL = "DEBUG"
REQUEST_TIMEOUT = 15
View
@@ -35,7 +35,7 @@ APPLICATION_LOGFILE = '/app/logs/mementoembed-application.log'
# the log level to use, specified as Python log levels
# values are: logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR
# for more information, see https://docs.python.org/3/library/logging.html
APPLICATION_LOGLEVEL = "logging.DEBUG"
APPLICATION_LOGLEVEL = "DEBUG"
# --- ACCESS LOG FILE ---
# These settings apply to the log file documenting visitors to this MementoEmbed instance
View
@@ -149,10 +149,9 @@ def get_requests_timeout(config):
def setup_logging_config(config):
logfile = None
formatter = logging.Formatter('[%(asctime)s] - %(name)s - %(levelname)s - [ %(urim)s ]: %(message)s')
if 'APPLICATION_LOGLEVEL' in config:
loglevel = eval(config['APPLICATION_LOGLEVEL'])
loglevel = logging._nameToLevel[config['APPLICATION_LOGLEVEL']]
else:
loglevel = logging.INFO
@@ -166,12 +165,25 @@ def setup_logging_config(config):
try:
test_file_access(logfile) # should throw if file is invalid
if loglevel == logging.DEBUG:
formatter = logging.Formatter(
'[%(asctime)s {} ] - %(levelname)s - [ %(urim)s ]: %(name)s - %(message)s'.format(
strftime('%z')
))
else:
formatter = logging.Formatter(
'[%(asctime)s {} ] - %(levelname)s - [ %(urim)s ]: %(message)s'.format(
strftime('%z')
))
fh = logging.FileHandler(logfile)
fh.addFilter(URIMFilter())
fh.setLevel(loglevel)
fh.setFormatter(formatter)
application_logger.addHandler(fh)
application_logger.info("Writing application log to file {}".format(logfile))
application_logger.info("=== Starting application ===")
application_logger.info("Writing application log to file {} with level {}".format(
logfile, logging.getLevelName(loglevel)))
except Exception as e:
message = "Cannot write to requested application logfile {}, " \
View
@@ -33,7 +33,7 @@ APPLICATION_LOGFILE = '/app/logs/mementoembed-application.log'
# the log level to use, specified as Python log levels
# values are: logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR
# for more information, see https://docs.python.org/3/library/logging.html
APPLICATION_LOGLEVEL = "logging.INFO"
APPLICATION_LOGLEVEL = "INFO"
# --- ACCESS LOG FILE ---
# These settings apply to the log file documenting visitors to this MementoEmbed instance

0 comments on commit 9d0ae22

Please sign in to comment.