WIP tweak logging of git and mercurial operations (bug 1288282) draft
authorbyron jones <glob@mozilla.com>
Wed, 27 Sep 2017 15:06:25 +0800
changeset 11719 c9c8686da29e38b558c4f916344b66cf02989f16
parent 11718 d16e27b6766c648d9e66764fd6ed01622a552df1
child 11720 e9a10bb0d99a9606670cc935a3cbd9df095d946d
push id1805
push userbjones@mozilla.com
push dateWed, 27 Sep 2017 07:33:57 +0000
bugs1288282
WIP tweak logging of git and mercurial operations (bug 1288282) Minor quality of life changes to make the logs easier to scan. MozReview-Commit-ID: Dh9493p3Loi
vcssync/mozvcssync/github_pr.py
vcssync/mozvcssync/gitutil.py
vcssync/mozvcssync/servo.py
vcssync/mozvcssync/util.py
--- a/vcssync/mozvcssync/github_pr.py
+++ b/vcssync/mozvcssync/github_pr.py
@@ -10,17 +10,17 @@ import logging
 import re
 import tempfile
 import urllib
 import urlparse
 
 import github3
 from gitutil import GitCommand, setup_local_clone
 
-logger = logging.getLogger(__name__)
+logger = logging.getLogger('git')
 
 
 class GitHubPR(object):
     """Helper class for creating GitHub pull requests."""
 
     def __init__(self, auth_token, repo_name, path, github=None):
         assert auth_token
 
--- a/vcssync/mozvcssync/gitutil.py
+++ b/vcssync/mozvcssync/gitutil.py
@@ -6,17 +6,17 @@
 
 from __future__ import absolute_import, unicode_literals
 
 import logging
 import os
 import pipes
 import subprocess
 
-logger = logging.getLogger(__name__)
+logger = logging.getLogger('git')
 
 
 class GitCommand(object):
     """Helper class for running git commands"""
 
     def __init__(self, repo_path, secret=None):
         """
         :param repo_path: the full path to the git repo.
--- a/vcssync/mozvcssync/servo.py
+++ b/vcssync/mozvcssync/servo.py
@@ -146,17 +146,17 @@ def load_config(path):
 
 def configure_stdout():
     # Unbuffer stdout.
     sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1)
 
     # Log to stdout.
     root = logging.getLogger()
     handler = logging.StreamHandler(sys.stdout)
-    formatter = logging.Formatter('%(name)s %(message)s')
+    formatter = logging.Formatter('[%(name)s] %(message)s')
     handler.setFormatter(formatter)
     root.addHandler(handler)
 
 
 def pulse_daemon():
     import argparse
 
     configure_stdout()
--- a/vcssync/mozvcssync/util.py
+++ b/vcssync/mozvcssync/util.py
@@ -12,23 +12,25 @@ import os
 import pipes
 import shutil
 import sys
 
 import github3
 import hglib
 
 
-def run_hg(logger, client, args):
+def run_hg(logger, client, args, log_output=True):
     """Run a Mercurial command through hgclient and log output."""
-    logger.warn('executing: hg %s' % ' '.join(map(pipes.quote, args)))
+    logger.warn('executing: hg %s' % ' '.join(
+        pipes.quote(a).replace('\n', '\\n') for a in args))
     out = hglib.util.BytesIO()
 
     def write(data):
-        logger.warn(b'hg> %s' % data.rstrip())
+        if log_output:
+            logger.warn(b'hg> %s' % data.rstrip())
         out.write(data)
 
     out_channels = {b'o': write, b'e': write}
     ret = client.runcommand(args, {}, out_channels)
 
     if ret:
         raise hglib.error.CommandError(args, ret, out.getvalue(), b'')