Use a terse logging line if --verbose is not specified
This commit is contained in:
@@ -106,32 +106,47 @@ from overviewer_core import googlemap, rendernode
|
|||||||
helptext = """
|
helptext = """
|
||||||
%prog [OPTIONS] <World # / Name / Path to World> <tiles dest dir>"""
|
%prog [OPTIONS] <World # / Name / Path to World> <tiles dest dir>"""
|
||||||
|
|
||||||
def configure_logger():
|
def configure_logger(options=None):
|
||||||
"Configures the root logger to our liking"
|
"Configures the root logger to our liking"
|
||||||
|
|
||||||
|
if not options:
|
||||||
|
verbose = False
|
||||||
|
else:
|
||||||
|
verbose = options.verbose
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
outstream = sys.stderr
|
outstream = sys.stderr
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
# Our custom output stream processor knows how to deal with select ANSI
|
# Our custom output stream processor knows how to deal with select ANSI
|
||||||
# color escape sequences
|
# color escape sequences
|
||||||
outstream = util.WindowsOutputStream()
|
outstream = util.WindowsOutputStream()
|
||||||
formatter = util.ANSIColorFormatter()
|
formatter = util.ANSIColorFormatter(verbose)
|
||||||
|
|
||||||
elif sys.stderr.isatty():
|
elif sys.stderr.isatty():
|
||||||
# terminal logging with ANSI color
|
# terminal logging with ANSI color
|
||||||
formatter = util.ANSIColorFormatter()
|
formatter = util.ANSIColorFormatter(verbose)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Let's not assume anything. Just text.
|
# Let's not assume anything. Just text.
|
||||||
formatter = util.DumbFormatter()
|
formatter = util.DumbFormatter(verbose)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
if hasattr(logger, 'overviewerHandler'):
|
||||||
handler = logging.StreamHandler(outstream)
|
# we have already set up logging so just replace the formatter
|
||||||
handler.setFormatter(formatter)
|
# this time with the new values from options
|
||||||
logger.addHandler(handler)
|
logger.overviewerHandler.setFormatter(formatter)
|
||||||
|
logger.setLevel(logger.level + 10*options.quiet)
|
||||||
|
logger.setLevel(logger.level - 10*options.verbose)
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.overviewerHandler = logging.StreamHandler(outstream)
|
||||||
|
logger.overviewerHandler.setFormatter(formatter)
|
||||||
|
logger.addHandler(logger.overviewerHandler)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
# bootstrap the logger with defaults
|
||||||
configure_logger()
|
configure_logger()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -173,6 +188,8 @@ def main():
|
|||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
|
# the details of the logger options can depend on the command line options
|
||||||
|
configure_logger(options)
|
||||||
|
|
||||||
if options.version:
|
if options.version:
|
||||||
try:
|
try:
|
||||||
@@ -316,11 +333,6 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
|
|||||||
else:
|
else:
|
||||||
north_direction = 'auto'
|
north_direction = 'auto'
|
||||||
|
|
||||||
logging.getLogger().setLevel(
|
|
||||||
logging.getLogger().level + 10*options.quiet)
|
|
||||||
logging.getLogger().setLevel(
|
|
||||||
logging.getLogger().level - 10*options.verbose)
|
|
||||||
|
|
||||||
if options.changelist:
|
if options.changelist:
|
||||||
try:
|
try:
|
||||||
changefile = open(options.changelist,'w+')
|
changefile = open(options.changelist,'w+')
|
||||||
|
|||||||
@@ -224,13 +224,17 @@ class HighlightingFormatter(logging.Formatter):
|
|||||||
"""Base class of our custom formatter
|
"""Base class of our custom formatter
|
||||||
|
|
||||||
"""
|
"""
|
||||||
fmtstr = '%(fileandlineno)-18s:PID(%(pid)s):%(asctime)s ' \
|
datefmt = "%Y-%m-%d %H:%M:%S"
|
||||||
'%(levelname)-8s %(message)s'
|
|
||||||
datefmt = "%H:%M:%S"
|
|
||||||
funcName_len = 15
|
funcName_len = 15
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, verbose=False):
|
||||||
logging.Formatter.__init__(self, self.fmtstr, self.datefmt)
|
if verbose:
|
||||||
|
fmtstr = '%(fileandlineno)-18s %(pid)s %(asctime)s ' \
|
||||||
|
'%(levelname)-8s %(message)s'
|
||||||
|
else:
|
||||||
|
fmtstr = '%(asctime)s ' '%(shortlevelname)-1s%(message)s'
|
||||||
|
|
||||||
|
logging.Formatter.__init__(self, fmtstr, self.datefmt)
|
||||||
|
|
||||||
def format(self, record):
|
def format(self, record):
|
||||||
"""Add a few extra options to the record
|
"""Add a few extra options to the record
|
||||||
@@ -245,7 +249,14 @@ class HighlightingFormatter(logging.Formatter):
|
|||||||
funcName
|
funcName
|
||||||
The function name truncated/padded to a fixed width characters
|
The function name truncated/padded to a fixed width characters
|
||||||
|
|
||||||
|
shortlevelname
|
||||||
|
The level name truncated to 1 character
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
record.shortlevelname = record.levelname[0] + ' '
|
||||||
|
if record.levelname == 'INFO': record.shortlevelname = ''
|
||||||
|
|
||||||
record.pid = os.getpid()
|
record.pid = os.getpid()
|
||||||
record.fileandlineno = "%s:%s" % (record.filename, record.lineno)
|
record.fileandlineno = "%s:%s" % (record.filename, record.lineno)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user