Skip to content

Commit

Permalink
Logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Armen Zambrano G committed Jul 31, 2015
1 parent 2c15bdf commit 9e8a809
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions mozci/scripts/alltalos.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def main():
options = parse_args()

if options.debug:
LOG = setup_logging(logging.DEBUG)
setup_logging(logging.DEBUG)
else:
LOG = setup_logging(logging.INFO)
setup_logging()

pgo = False
if options.repo_name in PGO_ONLY_BRANCHES or options.pgo:
Expand Down
6 changes: 4 additions & 2 deletions mozci/scripts/generate_triggercli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
3) Remove the --dry-run parameter and actually trigger intermittents via trigger.py script.
"""
import logging
import os

from argparse import ArgumentParser
Expand All @@ -40,18 +41,19 @@
from mozci.utils.misc import setup_logging

bugzilla = bugsy.Bugsy()
LOG = setup_logging()


def main():
global LOG

options = parse_args()
bugs = []
assert options.bug_no or options.test_name, \
"Either call this with --bug-no or with --test-name"

if options.debug:
LOG = setup_logging(logging.DEBUG)
else:
LOG = setup_logging(logging.INFO)

if options.bug_no:
bugs.append(options.bug_no)
Expand Down
10 changes: 4 additions & 6 deletions mozci/scripts/misc/taskcluster_retrigger.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'''
taskcluster_retrigger.py allows you to retrigger a task from TaskCluster
past its deadline.
The API used is:
* createTask [1]
'''
import logging

from argparse import ArgumentParser

from mozci.scheduling import TaskclusterSchedulingClient
Expand Down Expand Up @@ -33,9 +31,9 @@ def main():
options = parser.parse_args()

if options.debug:
LOG = setup_logging(logging.DEBUG)
setup_logging(logging.DEBUG)
else:
LOG = setup_logging(logging.INFO)
setup_logging()

if options.retrigger:
sch = TaskclusterSchedulingClient()
Expand Down
2 changes: 1 addition & 1 deletion mozci/sources/taskcluster_.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def retrigger_task(task_id, dry_run=False):
LOG.debug("Contents of new task:")
LOG.debug(task)
if not dry_run:
LOG.info("Submitting new task with task_id: {}".format(new_task_id))
LOG.info("Attempting to schedule new task with task_id: {}".format(new_task_id))
result = queue.createTask(new_task_id, task)
LOG.debug(result)
LOG.info("/{}/task-inspector/#{}/".format(
Expand Down
7 changes: 5 additions & 2 deletions mozci/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _all_urls_reachable(urls):
return True


def setup_logging(level):
def setup_logging(level=logging.INFO):
"""
Save every message (including debug ones) to ~/.mozilla/mozci/mozci-debug.log.
Expand All @@ -54,17 +54,20 @@ def setup_logging(level):
https://docs.python.org/2/howto/logging-cookbook.html#logging-to-multiple-destinations
"""
LOG = logging.getLogger('mozci')

# 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',
filename=path_to_file('mozci-debug.log'),
filemode='w')

# Handler 2 - Console output
console = logging.StreamHandler()
console.setLevel(level)
# console does not use the same formatter specified in basicConfig
# we have to set it again
formatter = logging.Formatter('%(asctime)s %(levelname)s:\t %(message)s',
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s:\t %(message)s',
datefmt='%m/%d/%Y %I:%M:%S')
console.setFormatter(formatter)
LOG.addHandler(console)
Expand Down

0 comments on commit 9e8a809

Please sign in to comment.