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
--- 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'')