Skip to content

Commit

Permalink
Merge pull request #1730 from dcos/mh/logging-handler
Browse files Browse the repository at this point in the history
Remove logging handler config from e2e library
  • Loading branch information
adamtheturtle authored Apr 23, 2019
2 parents 8762d8c + 56d7331 commit 3449c57
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog
Next
----

* The library no longer configures logger handler. Applications using ``dcos_e2e`` library that were relying on logging being printed to stdout should configure ``logging`` on its own.

2019.04.18.2
------------

Expand Down
1 change: 1 addition & 0 deletions spelling_private_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bootstrap
breakpoint
bytestring
calledprocesserror
caplog
centos
cgroup
cgroups
Expand Down
35 changes: 1 addition & 34 deletions src/dcos_e2e/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,7 @@
from subprocess import PIPE, STDOUT, CompletedProcess, Popen
from typing import Dict, List, Optional, Union


def get_logger(name: str) -> logging.Logger:
"""
Return a customized logger that is able to log on DEBUG level.
Args:
name: Name of the logger. Setting this to ``__name__`` will log
the path to the file where the logger has been created.
Returns:
See :py:class:`logging.Logger`.
"""
# This gets the root logger with a ``logging.lastResort``
# StreamHandler that logs on WARNING level.
logger = logging.getLogger(name=name)
logger.setLevel(logging.DEBUG)

# Add a new StreamHandler that logs on DEBUG level in order
# to override the ``logging.lastResort`` handler.
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)

# Take control of the logging format
formatter = logging.Formatter(
fmt='%(asctime)s %(levelname)-8s %(name)s | %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
handler.setFormatter(formatter)

logger.addHandler(handler)
return logger


LOGGER = get_logger(__name__)
LOGGER = logging.getLogger(__name__)


def _safe_decode(output_bytes: bytes) -> str:
Expand Down
5 changes: 3 additions & 2 deletions src/dcos_e2e/backends/_docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Helpers for creating and interacting with clusters on Docker.
"""

import logging
import socket
import stat
import subprocess
Expand All @@ -19,7 +20,7 @@
from cryptography.hazmat.primitives.asymmetric import rsa
from docker.types import Mount

from dcos_e2e._common import get_logger, run_subprocess
from dcos_e2e._common import run_subprocess
from dcos_e2e.base_classes import ClusterBackend, ClusterManager
from dcos_e2e.cluster import Cluster
from dcos_e2e.distributions import Distribution
Expand All @@ -30,7 +31,7 @@
from ._containers import start_dcos_container
from ._docker_build import build_docker_image

LOGGER = get_logger(__name__)
LOGGER = logging.getLogger(__name__)


def _write_key_pair(public_key_path: Path, private_key_path: Path) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/dcos_e2e/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Output(Enum):
LOG_AND_CAPTURE: Log output at the debug level. If the code returns a
``subprocess.CompletedProcess``, the stdout and stderr will be
contained in the return value. However, they will be merged into
stderr.
stdout.
CAPTURE: Capture stdout and stderr. If the code returns a
``subprocess.CompletedProcess``, the stdout and stderr will be
contained in the return value.
Expand Down
7 changes: 6 additions & 1 deletion src/dcos_e2e_cli/common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,12 @@ def _set_logging(
2: logging.DEBUG,
3: logging.NOTSET,
}
logging.basicConfig(level=logging.NOTSET)
logging.basicConfig(level=logging.DEBUG)

# Disable debug output from `docker` and `urllib3` libraries
logging.getLogger('urllib3.connectionpool').setLevel(logging.WARN)
logging.getLogger('docker').setLevel(logging.WARN)

# Disable logging calls of the given severity level or below.
logging.disable(verbosity_map[int(verbosity_level or 0)])

Expand Down
8 changes: 8 additions & 0 deletions tests/test_dcos_e2e/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ class TestInstallDcosFromPathLogging:
``Cluster``.
"""

@pytest.fixture(autouse=True)
def configure_logging(self, caplog: LogCaptureFixture) -> None:
"""
Set the ``caplog`` logging level to ``DEBUG`` so it captures any log
messages produced by ``dcos_e2e`` library.
"""
caplog.set_level(logging.DEBUG, logger='dcos_e2e')

def _two_masters_error_logged(
self,
log_records: List[logging.LogRecord],
Expand Down
8 changes: 8 additions & 0 deletions tests/test_dcos_e2e/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ class TestOutput:
Tests for the ``output`` parameter of ``Node.run``.
"""

@pytest.fixture(autouse=True)
def configure_logging(self, caplog: LogCaptureFixture) -> None:
"""
Set the ``caplog`` logging level to ``DEBUG`` so it captures any log
messages produced by ``dcos_e2e`` library.
"""
caplog.set_level(logging.DEBUG, logger='dcos_e2e')

def test_default(
self,
caplog: LogCaptureFixture,
Expand Down

0 comments on commit 3449c57

Please sign in to comment.