diff --git a/README.md b/README.md index f3945b9..9afea72 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,12 @@ Available settings are: * Section **base**: * **database_uri**: required, a SQLAlchemy [database URI](http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html#database-urls). I personally use SQLite (`sqlite:////var/supysonic/supysonic.db`), but it might not be the brightest idea for large libraries. - * **cache_dir**: path to a cache folder. Mostly used for resized cover art images. Defaults to `/supysonic`. - * **log_file**: path and base name of a rolling log file. * **scanner_extensions**: space-separated list of file extensions the scanner is restricted to. If omitted, files will be scanned regardless of their extension +* Section **webapp** + * **cache_dir**: path to a cache folder. Mostly used for resized cover art images. Defaults to `/supysonic`. + * **log_file**: path and base name of a rolling log file. + * **log_level**: logging level. Possible values are *DEBUG*, *INFO*, *WARNING*, *ERROR* or *CRITICAL*. * Section **lastfm**: * **api_key**: Last.FM [API key](http://www.last.fm/api/accounts) to enable scrobbling * **secret**: Last.FM API secret matching the key. diff --git a/bin/supysonic-watcher b/bin/supysonic-watcher index eea9269..ef223cc 100755 --- a/bin/supysonic-watcher +++ b/bin/supysonic-watcher @@ -21,6 +21,7 @@ import time, sys import logging +from logging.handlers import TimedRotatingFileHandler from watchdog.observers import Observer from watchdog.events import PatternMatchingEventHandler @@ -63,10 +64,21 @@ if __name__ == "__main__": sys.exit(1) logger = logging.getLogger(__name__) - log_handler = logging.StreamHandler(sys.stdout) + if config.get('daemon', 'log_file'): + log_handler = TimedRotatingFileHandler(config.get('daemon', 'log_file'), when = 'midnight') + else: + log_handler = logging.NullHandler() log_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")) logger.addHandler(log_handler) - logger.setLevel(logging.DEBUG) + if config.get('daemon', 'log_level'): + mapping = { + 'DEBUG': logging.DEBUG, + 'INFO': logging.INFO, + 'WARNING': logging.WARNING, + 'ERROR': logging.ERROR, + 'CRTICAL': logging.CRITICAL + } + logger.setLevel(mapping.get(config.get('daemon', 'log_level').upper(), logging.NOTSET)) from supysonic import db db.init_db() diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 70a1fde..da38c06 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -151,7 +151,7 @@ def cover_art(): if size > im.size[0] and size > im.size[1]: return send_file(os.path.join(res.path, 'cover.jpg')) - size_path = os.path.join(config.get('base', 'cache_dir'), str(size)) + size_path = os.path.join(config.get('webapp', 'cache_dir'), str(size)) path = os.path.join(size_path, str(res.id)) if os.path.exists(path): return send_file(path) diff --git a/supysonic/web.py b/supysonic/web.py index 15ae154..6f6f3ee 100644 --- a/supysonic/web.py +++ b/supysonic/web.py @@ -32,8 +32,8 @@ def create_application(): if not config.check(): return None - if not os.path.exists(config.get('base', 'cache_dir')): - os.makedirs(config.get('base', 'cache_dir')) + if not os.path.exists(config.get('webapp', 'cache_dir')): + os.makedirs(config.get('webapp', 'cache_dir')) from supysonic import db db.init_db() @@ -41,11 +41,19 @@ def create_application(): app = Flask(__name__) app.secret_key = '?9huDM\\H' - if config.get('base', 'log_file'): + if config.get('webapp', 'log_file'): import logging from logging.handlers import TimedRotatingFileHandler - handler = TimedRotatingFileHandler(config.get('base', 'log_file'), when = 'midnight') - handler.setLevel(logging.WARNING) + handler = TimedRotatingFileHandler(config.get('webapp', 'log_file'), when = 'midnight') + if config.get('webapp', 'log_level'): + mapping = { + 'DEBUG': logging.DEBUG, + 'INFO': logging.INFO, + 'WARNING': logging.WARNING, + 'ERROR': logging.ERROR, + 'CRTICAL': logging.CRITICAL + } + handler.setLevel(mapping.get(config.get('webapp', 'log_level').upper(), logging.NOTSET)) app.logger.addHandler(handler) app.teardown_request(teardown)