mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-23 05:09:28 +00:00
Add more control over verbosity
This commit is contained in:
committed by
Pablo Alcantara
parent
03e07db9d5
commit
216d3e9e22
@@ -41,6 +41,7 @@ def main():
|
||||
# Set up and gather command line arguments
|
||||
parser = argparse.ArgumentParser(description='Music add-on for SABnzbd+')
|
||||
|
||||
parser.add_argument('-v', '--verbose', action='store_true', help='Increase console logging verbosity')
|
||||
parser.add_argument('-q', '--quiet', action='store_true', help='Turn off console logging')
|
||||
parser.add_argument('-d', '--daemon', action='store_true', help='Run as a daemon')
|
||||
parser.add_argument('-p', '--port', type=int, help='Force Headphones to run on a specified port')
|
||||
@@ -50,13 +51,15 @@ def main():
|
||||
parser.add_argument('--pidfile', help='Create a pid file (only relevant when running as a daemon)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.quiet:
|
||||
headphones.QUIET=True
|
||||
|
||||
if args.verbose:
|
||||
headphones.VERBOSE = 2
|
||||
elif args.quiet:
|
||||
headphones.VERBOSE = 0
|
||||
|
||||
if args.daemon:
|
||||
headphones.DAEMON=True
|
||||
headphones.QUIET=True
|
||||
headphones.VERBOSE = 0
|
||||
if args.pidfile :
|
||||
headphones.PIDFILE = args.pidfile
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ SIGNAL = None
|
||||
|
||||
SYS_ENCODING = None
|
||||
|
||||
QUIET = False
|
||||
VERBOSE = 1
|
||||
DAEMON = False
|
||||
PIDFILE= None
|
||||
|
||||
@@ -173,7 +173,7 @@ def initialize():
|
||||
|
||||
with INIT_LOCK:
|
||||
|
||||
global __INITIALIZED__, FULL_PATH, PROG_DIR, QUIET, DAEMON, DATA_DIR, CONFIG_FILE, CFG, LOG_DIR, CACHE_DIR, \
|
||||
global __INITIALIZED__, FULL_PATH, PROG_DIR, VERBOSE, DAEMON, DATA_DIR, CONFIG_FILE, CFG, LOG_DIR, CACHE_DIR, \
|
||||
HTTP_PORT, HTTP_HOST, HTTP_USERNAME, HTTP_PASSWORD, HTTP_ROOT, LAUNCH_BROWSER, GIT_PATH, \
|
||||
CURRENT_VERSION, LATEST_VERSION, MUSIC_DIR, DESTINATION_DIR, PREFERRED_QUALITY, PREFERRED_BITRATE, DETECT_BITRATE, \
|
||||
ADD_ARTISTS, CORRECT_METADATA, MOVE_FILES, RENAME_FILES, FOLDER_FORMAT, FILE_FORMAT, CLEANUP_FILES, INCLUDE_EXTRAS, \
|
||||
@@ -280,11 +280,11 @@ def initialize():
|
||||
try:
|
||||
os.makedirs(LOG_DIR)
|
||||
except OSError:
|
||||
if not QUIET:
|
||||
if VERBOSE:
|
||||
print 'Unable to create the log directory. Logging to screen only.'
|
||||
|
||||
# Start the logger, silence console logging if we need to
|
||||
logger.headphones_log.initLogger(quiet=QUIET)
|
||||
logger.headphones_log.initLogger(verbose=VERBOSE)
|
||||
|
||||
# Update some old config code:
|
||||
if FOLDER_FORMAT == '%artist/%album/%track':
|
||||
|
||||
@@ -20,7 +20,7 @@ class RotatingLogger(object):
|
||||
self.max_files = max_files
|
||||
|
||||
|
||||
def initLogger(self, quiet=False):
|
||||
def initLogger(self, verbose=1):
|
||||
|
||||
l = logging.getLogger('headphones')
|
||||
l.setLevel(logging.DEBUG)
|
||||
@@ -35,13 +35,13 @@ class RotatingLogger(object):
|
||||
filehandler.setFormatter(fileformatter)
|
||||
l.addHandler(filehandler)
|
||||
|
||||
if not quiet:
|
||||
|
||||
if verbose:
|
||||
consolehandler = logging.StreamHandler()
|
||||
consolehandler.setLevel(logging.INFO)
|
||||
|
||||
if verbose == 1:
|
||||
consolehandler.setLevel(logging.INFO)
|
||||
if verbose == 2:
|
||||
consolehandler.setLevel(logging.DEBUG)
|
||||
consoleformatter = logging.Formatter('%(asctime)s - %(levelname)s :: %(message)s', '%d-%b-%Y %H:%M:%S')
|
||||
|
||||
consolehandler.setFormatter(consoleformatter)
|
||||
l.addHandler(consolehandler)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user