diff --git a/Headphones.py b/Headphones.py index 480caf08..ce67b2b1 100755 --- a/Headphones.py +++ b/Headphones.py @@ -77,9 +77,9 @@ def main(): args = parser.parse_args() if args.verbose: - headphones.VERBOSE = 2 - elif args.quiet: - headphones.VERBOSE = 0 + headphones.VERBOSE = True + if args.quiet: + headphones.QUIET = True if args.daemon: if sys.platform == 'win32': diff --git a/headphones/__init__.py b/headphones/__init__.py index 821fb202..3b785efc 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -38,7 +38,8 @@ SIGNAL = None SYS_PLATFORM = None SYS_ENCODING = None -VERBOSE = 1 +QUIET = True +VERBOSE = False DAEMON = False CREATEPID = False PIDFILE= None @@ -340,7 +341,7 @@ def initialize(): with INIT_LOCK: - global __INITIALIZED__, FULL_PATH, PROG_DIR, VERBOSE, DAEMON, SYS_PLATFORM, DATA_DIR, CONFIG_FILE, CFG, CONFIG_VERSION, LOG_DIR, CACHE_DIR, \ + global __INITIALIZED__, FULL_PATH, PROG_DIR, VERBOSE, QUIET, DAEMON, SYS_PLATFORM, DATA_DIR, CONFIG_FILE, CFG, CONFIG_VERSION, LOG_DIR, CACHE_DIR, \ HTTP_PORT, HTTP_HOST, HTTP_USERNAME, HTTP_PASSWORD, HTTP_ROOT, HTTP_PROXY, LAUNCH_BROWSER, API_ENABLED, API_KEY, GIT_PATH, GIT_USER, GIT_BRANCH, DO_NOT_OVERRIDE_GIT_BRANCH, \ CURRENT_VERSION, LATEST_VERSION, CHECK_GITHUB, CHECK_GITHUB_ON_STARTUP, CHECK_GITHUB_INTERVAL, MUSIC_DIR, DESTINATION_DIR, \ LOSSLESS_DESTINATION_DIR, PREFERRED_QUALITY, PREFERRED_BITRATE, DETECT_BITRATE, ADD_ARTISTS, CORRECT_METADATA, MOVE_FILES, \ @@ -717,8 +718,8 @@ def initialize(): if VERBOSE: sys.stderr.write('Unable to create the log directory. Logging to screen only.\n') - # Start the logger, silence console logging if we need to - logger.initLogger(verbose=VERBOSE) + # Start the logger, disable console if needed + logger.initLogger(console=not QUIET, verbose=VERBOSE) if not CACHE_DIR: # Put the cache dir in the data dir for now diff --git a/headphones/logger.py b/headphones/logger.py index b2ea73db..0f2baf98 100644 --- a/headphones/logger.py +++ b/headphones/logger.py @@ -43,19 +43,21 @@ class LogListHandler(logging.Handler): headphones.LOG_LIST.insert(0, (helpers.now(), message, record.levelname, record.threadName)) -def initLogger(verbose=1): +def initLogger(console=False, verbose=False): """ Setup logging for Headphones. It uses the logger instance with the name 'headphones'. Three log handlers are added: * RotatingFileHandler: for the file headphones.log * LogListHandler: for Web UI - * StreamHandler: for console (if verbose > 0) + * StreamHandler: for console (if console) + + Console logging is only enabled if console is set to True. """ # Configure the logger to accept all messages logger.propagate = False - logger.setLevel(logging.DEBUG if verbose == 2 else logging.INFO) + logger.setLevel(logging.DEBUG if verbose else logging.INFO) # Setup file logger filename = os.path.join(headphones.LOG_DIR, FILENAME) @@ -74,7 +76,7 @@ def initLogger(verbose=1): logger.addHandler(loglist_handler) # Setup console logger - if verbose: + if console: console_formatter = logging.Formatter('%(asctime)s - %(levelname)s :: %(threadName)s : %(message)s', '%d-%b-%Y %H:%M:%S') console_handler = logging.StreamHandler() console_handler.setFormatter(console_formatter)