1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

A tiny bit more configuration on logging

This commit is contained in:
spl0k 2014-06-14 14:49:03 +02:00
parent 4facfbe275
commit b83538f80b
4 changed files with 32 additions and 10 deletions

View File

@ -40,10 +40,12 @@ Available settings are:
* Section **base**: * Section **base**:
* **database_uri**: required, a SQLAlchemy [database URI](http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html#database-urls). * **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. 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 `<system temp dir>/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 * **scanner_extensions**: space-separated list of file extensions the scanner is restricted to. If omitted, files will be scanned
regardless of their extension regardless of their extension
* Section **webapp**
* **cache_dir**: path to a cache folder. Mostly used for resized cover art images. Defaults to `<system temp dir>/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**: * Section **lastfm**:
* **api_key**: Last.FM [API key](http://www.last.fm/api/accounts) to enable scrobbling * **api_key**: Last.FM [API key](http://www.last.fm/api/accounts) to enable scrobbling
* **secret**: Last.FM API secret matching the key. * **secret**: Last.FM API secret matching the key.

View File

@ -21,6 +21,7 @@
import time, sys import time, sys
import logging import logging
from logging.handlers import TimedRotatingFileHandler
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler from watchdog.events import PatternMatchingEventHandler
@ -63,10 +64,21 @@ if __name__ == "__main__":
sys.exit(1) sys.exit(1)
logger = logging.getLogger(__name__) 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")) log_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s"))
logger.addHandler(log_handler) 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 from supysonic import db
db.init_db() db.init_db()

View File

@ -151,7 +151,7 @@ def cover_art():
if size > im.size[0] and size > im.size[1]: if size > im.size[0] and size > im.size[1]:
return send_file(os.path.join(res.path, 'cover.jpg')) 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)) path = os.path.join(size_path, str(res.id))
if os.path.exists(path): if os.path.exists(path):
return send_file(path) return send_file(path)

View File

@ -32,8 +32,8 @@ def create_application():
if not config.check(): if not config.check():
return None return None
if not os.path.exists(config.get('base', 'cache_dir')): if not os.path.exists(config.get('webapp', 'cache_dir')):
os.makedirs(config.get('base', 'cache_dir')) os.makedirs(config.get('webapp', 'cache_dir'))
from supysonic import db from supysonic import db
db.init_db() db.init_db()
@ -41,11 +41,19 @@ def create_application():
app = Flask(__name__) app = Flask(__name__)
app.secret_key = '?9huDM\\H' app.secret_key = '?9huDM\\H'
if config.get('base', 'log_file'): if config.get('webapp', 'log_file'):
import logging import logging
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler
handler = TimedRotatingFileHandler(config.get('base', 'log_file'), when = 'midnight') handler = TimedRotatingFileHandler(config.get('webapp', 'log_file'), when = 'midnight')
handler.setLevel(logging.WARNING) 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.logger.addHandler(handler)
app.teardown_request(teardown) app.teardown_request(teardown)