diff --git a/cps/config_sql.py b/cps/config_sql.py index 2c48d3e5..c5287d36 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -293,7 +293,12 @@ class _ConfigSQL(object): have_metadata_db = os.path.isfile(db_file) self.db_configured = have_metadata_db constants.EXTENSIONS_UPLOAD = [x.lstrip().rstrip() for x in self.config_upload_formats.split(',')] - logger.setup(self.config_logfile, self.config_log_level) + logfile = logger.setup(self.config_logfile, self.config_log_level) + if logfile != self.config_logfile: + log.warning("Log path %s not valid, falling back to default", self.config_logfile) + self.config_logfile = logfile + self._session.merge(s) + self._session.commit() def save(self): '''Apply all configuration values to the underlying storage.''' diff --git a/cps/logger.py b/cps/logger.py index 3f850442..d9531655 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -82,7 +82,6 @@ def _absolute_log_file(log_file, default_log_file): if not os.path.dirname(log_file): log_file = os.path.join(_CONFIG_DIR, log_file) return os.path.abspath(log_file) - return default_log_file @@ -115,7 +114,7 @@ def setup(log_file, log_level=None): if previous_handler: # if the log_file has not changed, don't create a new handler if getattr(previous_handler, 'baseFilename', None) == log_file: - return + return "" if log_file == DEFAULT_LOG_FILE else log_file logging.debug("logging to %s level %s", log_file, r.level) if log_file == LOG_TO_STDERR or log_file == LOG_TO_STDOUT: @@ -132,12 +131,14 @@ def setup(log_file, log_level=None): if log_file == DEFAULT_LOG_FILE: raise file_handler = RotatingFileHandler(DEFAULT_LOG_FILE, maxBytes=50000, backupCount=2) + log_file = "" file_handler.setFormatter(FORMATTER) for h in r.handlers: r.removeHandler(h) h.close() r.addHandler(file_handler) + return "" if log_file == DEFAULT_LOG_FILE else log_file def create_access_log(log_file, log_name, formatter): @@ -150,11 +151,18 @@ def create_access_log(log_file, log_name, formatter): access_log = logging.getLogger(log_name) access_log.propagate = False access_log.setLevel(logging.INFO) + try: + file_handler = RotatingFileHandler(log_file, maxBytes=50000, backupCount=2) + except IOError: + if log_file == DEFAULT_ACCESS_LOG: + raise + file_handler = RotatingFileHandler(DEFAULT_ACCESS_LOG, maxBytes=50000, backupCount=2) + log_file = "access.log" - file_handler = RotatingFileHandler(log_file, maxBytes=50000, backupCount=2) file_handler.setFormatter(formatter) access_log.addHandler(file_handler) - return access_log + return access_log, \ + "access.log" if _absolute_log_file(log_file, DEFAULT_ACCESS_LOG) == DEFAULT_ACCESS_LOG else log_file # Enable logging of smtp lib debug output diff --git a/cps/server.py b/cps/server.py index 9180c821..7c2d321d 100644 --- a/cps/server.py +++ b/cps/server.py @@ -72,7 +72,11 @@ class WebServer(object): if config.config_access_log: log_name = "gevent.access" if _GEVENT else "tornado.access" formatter = logger.ACCESS_FORMATTER_GEVENT if _GEVENT else logger.ACCESS_FORMATTER_TORNADO - self.access_logger = logger.create_access_log(config.config_access_logfile, log_name, formatter) + self.access_logger, logfile = logger.create_access_log(config.config_access_logfile, log_name, formatter) + if logfile != config.config_access_logfile: + log.warning("Accesslog path %s not valid, falling back to default", config.config_access_logfile) + config.config_access_logfile = logfile + config.save() else: if not _GEVENT: logger.get('tornado.access').disabled = True diff --git a/cps/web.py b/cps/web.py index b21146ca..de2a654b 100644 --- a/cps/web.py +++ b/cps/web.py @@ -48,7 +48,7 @@ except ImportError: from werkzeug.datastructures import Headers from werkzeug.security import generate_password_hash, check_password_hash -from . import constants, logger, isoLanguages, services, worker +from . import constants, logger, isoLanguages, services, worker, cli from . import searched_ids, lm, babel, db, ub, config, get_locale, app from . import calibre_db from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download @@ -1157,13 +1157,24 @@ def advanced_search(): return render_title_template('search.html', adv_searchterm=searchterm, entries=q, title=_(u"search"), page="search") # prepare data for search-form - tags = calibre_db.session.query(db.Tags).join(db.books_tags_link).join(db.Books).filter(calibre_db.common_filters()) \ - .group_by(text('books_tags_link.tag')).order_by(db.Tags.name).all() - series = calibre_db.session.query(db.Series).join(db.books_series_link).join(db.Books).filter(calibre_db.common_filters()) \ - .group_by(text('books_series_link.series')).order_by(db.Series.name).filter(calibre_db.common_filters()).all() - extensions = calibre_db.session.query(db.Data).join(db.Books).filter(calibre_db.common_filters()) \ - .group_by(db.Data.format).order_by(db.Data.format).all() - + tags = calibre_db.session.query(db.Tags)\ + .join(db.books_tags_link)\ + .join(db.Books)\ + .filter(calibre_db.common_filters()) \ + .group_by(text('books_tags_link.tag'))\ + .order_by(db.Tags.name).all() + series = calibre_db.session.query(db.Series)\ + .join(db.books_series_link)\ + .join(db.Books)\ + .filter(calibre_db.common_filters()) \ + .group_by(text('books_series_link.series'))\ + .order_by(db.Series.name)\ + .filter(calibre_db.common_filters()).all() + extensions = calibre_db.session.query(db.Data)\ + .join(db.Books)\ + .filter(calibre_db.common_filters()) \ + .group_by(db.Data.format)\ + .order_by(db.Data.format).all() if current_user.filter_language() == u"all": languages = calibre_db.speaking_language() else: