Skip to content
This repository has been archived by the owner on Nov 22, 2017. It is now read-only.

Commit

Permalink
Make logging more customizable and have shorter lines by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Armen Zambrano G committed Apr 15, 2016
1 parent a38c6da commit a2dbaf1
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions mozci/utils/log_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
LOG = None


def setup_logging(level=logging.INFO):
def setup_logging(level=logging.INFO, datefmt='%I:%M:%S', show_timestamps=True,
show_name_level=False):
"""
Save every message (including debug ones) to ~/.mozilla/mozci/mozci-debug.log.
Expand All @@ -26,10 +27,21 @@ def setup_logging(level=logging.INFO):
# modules
LOG = logging.getLogger()

format = ''
if show_timestamps:
format += '%(asctime)s '

format += '%(name)s'

if show_name_level:
format += ' %(levelname)s" '

format += '\t%(message)s'

# Handler 1 - Store all debug messages in a specific file
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s:\t%(message)s',
datefmt='%m/%d/%Y %I:%M:%S',
format=format,
datefmt=datefmt,
filename=path_to_file('mozci-debug.log'),
filemode='w')

Expand All @@ -38,8 +50,7 @@ def setup_logging(level=logging.INFO):
console.setLevel(level)
# console does not use the same formatter specified in basicConfig
# we have to set it again
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s:\t%(message)s',
datefmt='%m/%d/%Y %I:%M:%S')
formatter = logging.Formatter(format, datefmt=datefmt)
console.setFormatter(formatter)
LOG.addHandler(console)
LOG.info("Setting %s level" % logging.getLevelName(level))
Expand Down

0 comments on commit a2dbaf1

Please sign in to comment.