Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify logging implementations and remove simplelog #10686

Merged
merged 6 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/python/pants/engine/internals/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def default_cache_path(self) -> str:
def default_config_path(self) -> str:
return cast(str, self.lib.default_config_path())

def setup_pantsd_logger(self, log_file_path, level):
return self.lib.setup_pantsd_logger(log_file_path, level)
def setup_pantsd_logger(self, log_file_path):
return self.lib.setup_pantsd_logger(log_file_path)

def setup_stderr_logger(self, level):
return self.lib.setup_stderr_logger(level)
def setup_stderr_logger(self):
return self.lib.setup_stderr_logger()

def write_log(self, msg: str, *, level: int, target: str):
"""Proxy a log message to the Rust logging faculties."""
Expand Down
31 changes: 8 additions & 23 deletions src/python/pants/init/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import http.client
import logging
import os
import sys
import warnings
from logging import Formatter, Handler, LogRecord, StreamHandler
from typing import List, Optional, TextIO, Tuple
from typing import List, Optional, Tuple

import pants.util.logging as pants_logging
from pants.base.exception_sink import ExceptionSink
Expand All @@ -31,26 +30,15 @@ class NativeHandler(StreamHandler):
method) and proxies logs to the Rust logging infrastructure."""

def __init__(
self,
log_level: LogLevel,
stream: Optional[TextIO] = None,
native_filename: Optional[str] = None,
self, log_level: LogLevel, native_filename: Optional[str] = None,
):

if stream is not None and native_filename is not None:
raise RuntimeError("NativeHandler must output to either a stream or a file, not both")

super().__init__(stream)
super().__init__(None)
self.native = Native()
self.native_filename = native_filename
self.setLevel(log_level.level)

if stream:
try:
self.native.setup_stderr_logger(log_level.level)
except Exception as e:
print(f"Error setting up pantsd logger: {e!r}", file=sys.stderr)
raise e
if not self.native_filename:
self.native.setup_stderr_logger()

def emit(self, record: LogRecord) -> None:
self.native.write_log(
Expand All @@ -61,10 +49,7 @@ def flush(self) -> None:
self.native.flush_log()

def __repr__(self) -> str:
return (
f"NativeHandler(id={id(self)}, level={self.level}, filename={self.native_filename}, "
f"stream={self.stream})"
)
return f"NativeHandler(id={id(self)}, level={self.level}, filename={self.native_filename}"


class ExceptionFormatter(Formatter):
Expand Down Expand Up @@ -150,7 +135,7 @@ def setup_logging_to_stderr(
_common_logging_setup(level, warnings_filter_regexes)

python_logger = logging.getLogger(None)
handler = NativeHandler(level, stream=sys.stderr)
handler = NativeHandler(level)
handler.setFormatter(ExceptionFormatter())
python_logger.addHandler(handler)
LogLevel.TRACE.set_level_for(python_logger)
Expand All @@ -171,7 +156,7 @@ def setup_logging_to_file(
safe_mkdir(log_dir)
log_path = os.path.join(log_dir, log_filename)

fd = native.setup_pantsd_logger(log_path, level.level)
fd = native.setup_pantsd_logger(log_path)
ExceptionSink.reset_interactive_output_stream(os.fdopen(os.dup(fd), "a"))
handler = NativeHandler(level, native_filename=log_path)

Expand Down
44 changes: 0 additions & 44 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions src/rust/engine/logging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ lazy_static = "1"
log = "0.4"
num_enum = "0.4"
parking_lot = "0.11"
simplelog = "0.7.4"
# TODO: See #10291.
tokio = { version = "=0.2.20", features = ["rt-util"] }
tokio = { version = "=0.2.20", features = ["rt-util"] } # TODO: see https://github.com/pantsbuild/pants/issues/10291
uuid = { version = "0.7", features = ["v4"] }

[build-dependencies]
Expand Down
Loading