Add more control over verbosity

This commit is contained in:
Antoine Bertin
2011-08-22 02:57:19 +08:00
committed by Pablo Alcantara
parent 03e07db9d5
commit 216d3e9e22
3 changed files with 17 additions and 14 deletions
+6 -3
View File
@@ -41,6 +41,7 @@ def main():
# Set up and gather command line arguments # Set up and gather command line arguments
parser = argparse.ArgumentParser(description='Music add-on for SABnzbd+') 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('-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('-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') parser.add_argument('-p', '--port', type=int, help='Force Headphones to run on a specified port')
@@ -51,12 +52,14 @@ def main():
args = parser.parse_args() args = parser.parse_args()
if args.quiet: if args.verbose:
headphones.QUIET=True headphones.VERBOSE = 2
elif args.quiet:
headphones.VERBOSE = 0
if args.daemon: if args.daemon:
headphones.DAEMON=True headphones.DAEMON=True
headphones.QUIET=True headphones.VERBOSE = 0
if args.pidfile : if args.pidfile :
headphones.PIDFILE = args.pidfile headphones.PIDFILE = args.pidfile
+4 -4
View File
@@ -22,7 +22,7 @@ SIGNAL = None
SYS_ENCODING = None SYS_ENCODING = None
QUIET = False VERBOSE = 1
DAEMON = False DAEMON = False
PIDFILE= None PIDFILE= None
@@ -173,7 +173,7 @@ def initialize():
with INIT_LOCK: 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, \ 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, \ 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, \ ADD_ARTISTS, CORRECT_METADATA, MOVE_FILES, RENAME_FILES, FOLDER_FORMAT, FILE_FORMAT, CLEANUP_FILES, INCLUDE_EXTRAS, \
@@ -280,11 +280,11 @@ def initialize():
try: try:
os.makedirs(LOG_DIR) os.makedirs(LOG_DIR)
except OSError: except OSError:
if not QUIET: if VERBOSE:
print 'Unable to create the log directory. Logging to screen only.' print 'Unable to create the log directory. Logging to screen only.'
# Start the logger, silence console logging if we need to # 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: # Update some old config code:
if FOLDER_FORMAT == '%artist/%album/%track': if FOLDER_FORMAT == '%artist/%album/%track':
+6 -6
View File
@@ -20,7 +20,7 @@ class RotatingLogger(object):
self.max_files = max_files self.max_files = max_files
def initLogger(self, quiet=False): def initLogger(self, verbose=1):
l = logging.getLogger('headphones') l = logging.getLogger('headphones')
l.setLevel(logging.DEBUG) l.setLevel(logging.DEBUG)
@@ -35,13 +35,13 @@ class RotatingLogger(object):
filehandler.setFormatter(fileformatter) filehandler.setFormatter(fileformatter)
l.addHandler(filehandler) l.addHandler(filehandler)
if not quiet: if verbose:
consolehandler = logging.StreamHandler() 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') consoleformatter = logging.Formatter('%(asctime)s - %(levelname)s :: %(message)s', '%d-%b-%Y %H:%M:%S')
consolehandler.setFormatter(consoleformatter) consolehandler.setFormatter(consoleformatter)
l.addHandler(consolehandler) l.addHandler(consolehandler)