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

Remove neptune.logging package #1698

Merged
merged 2 commits into from
Mar 18, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Deleted `neptune.common` package ([#1693](https://github.com/neptune-ai/neptune-client/pull/1693))
([#1690](https://github.com/neptune-ai/neptune-client/pull/1690))
- Renamed `metadata_containers` to `objects` ([#1696](https://github.com/neptune-ai/neptune-client/pull/1696))
- Deleted `neptune.logging` package ([#1698](https://github.com/neptune-ai/neptune-client/pull/1698))

### Features
- ?
Expand Down
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ component_management:
- src/neptune/cli/**
- src/neptune/common/**
- src/neptune/internal/**
- src/neptune/logging/**
- src/neptune/objects/**
- src/neptune/new/**
- src/neptune/types/**
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ module = [
"neptune.internal.utils.uncaught_exception_handler",
"neptune.internal.websockets.websocket_signals_background_job",
"neptune.internal.websockets.websockets_factory",
"neptune.logging.logger",
"neptune.management.exceptions",
"neptune.management.internal.api",
"neptune.management.internal.dto",
Expand Down
9 changes: 3 additions & 6 deletions src/neptune/integrations/python_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from neptune import Run
from neptune.internal.state import ContainerState
from neptune.internal.utils import verify_type
from neptune.logging import Logger
from neptune.version import version as neptune_client_version

INTEGRATION_VERSION_KEY = "source_code/integrations/neptune-python-logger"
Expand Down Expand Up @@ -58,13 +57,11 @@ class NeptuneHandler(logging.Handler):
def __init__(self, *, run: Run, level=logging.NOTSET, path: str = None):
verify_type("run", run, Run)
verify_type("level", level, int)
if path is None:
path = f"{run.monitoring_namespace}/python_logger"
verify_type("path", path, str)
verify_type("path", path, (str, type(None)))

super().__init__(level=level)
self._path = path if path else f"{run.monitoring_namespace}/python_logger"
self._run = run
self._logger = Logger(run, path)
self._thread_local = threading.local()

self._run[INTEGRATION_VERSION_KEY] = str(neptune_client_version)
Expand All @@ -77,6 +74,6 @@ def emit(self, record: logging.LogRecord) -> None:
try:
self._thread_local.inside_write = True
message = self.format(record)
self._logger.log(message)
self._run[self._path].append(message)
finally:
self._thread_local.inside_write = False
9 changes: 6 additions & 3 deletions src/neptune/internal/streams/std_stream_capture_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@
from typing import TextIO

from neptune.internal.threading.daemon import Daemon
from neptune.logging import Logger as NeptuneLogger
from neptune.objects import NeptuneObject


class StdStreamCaptureLogger:
def __init__(self, container: NeptuneObject, attribute_name: str, stream: TextIO):
self._logger = NeptuneLogger(container, attribute_name)
self._container = container
self._attribute_name = attribute_name
self.stream = stream
self._thread_local = threading.local()
self.enabled = True
self._log_data_queue = Queue()
self._logging_thread = self.ReportingThread(self, "NeptuneThread_" + attribute_name)
self._logging_thread.start()

def log_data(self, data):
self._container[self._attribute_name].append(data)

def pause(self):
self._log_data_queue.put_nowait(None)
self._logging_thread.pause()
Expand Down Expand Up @@ -67,7 +70,7 @@ def work(self) -> None:
data = self._logger._log_data_queue.get()
if data is None:
break
self._logger._logger.log(data)
self._logger.log_data(data)


class StdoutCaptureLogger(StdStreamCaptureLogger):
Expand Down
18 changes: 0 additions & 18 deletions src/neptune/logging/__init__.py

This file was deleted.

31 changes: 0 additions & 31 deletions src/neptune/logging/logger.py

This file was deleted.

16 changes: 2 additions & 14 deletions tests/unit/neptune/new/internal/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@
StdoutCaptureLogger,
StdStreamCaptureLogger,
)
from neptune.logging import Logger as NeptuneLogger


class FakeLogger:
def __init__(self, event_to_wait: threading.Event, real_logger: NeptuneLogger):
self._event_to_wait = event_to_wait
self._real_logger = real_logger

def log(self, data):
self._event_to_wait.wait()
self._real_logger.log(data)


class TestStdStreamCaptureLogger(unittest.TestCase):
Expand All @@ -49,7 +38,7 @@ def test_catches_stdout(self):
logger.close()

self.assertListEqual(
mock_run[attr_name].log.call_args_list,
mock_run[attr_name].append.call_args_list,
[
(("testing",), {}),
(("\n",), {}),
Expand Down Expand Up @@ -79,7 +68,6 @@ def test_logger_with_lock_does_not_cause_deadlock(self):

logger = StdStreamCaptureLogger(mock_run, attr_name, stream)
done_waiting = threading.Event()
logger._logger = FakeLogger(done_waiting, logger._logger)

# The logger is blocked in background, the main thread is still awake
logger.write("testing")
Expand All @@ -91,7 +79,7 @@ def test_logger_with_lock_does_not_cause_deadlock(self):
done_waiting.set()
logger.close()
self.assertListEqual(
mock_run[attr_name].log.call_args_list,
mock_run[attr_name].append.call_args_list,
[
(("testing",), {}),
],
Expand Down
1 change: 0 additions & 1 deletion tests/unit/neptune/new/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
)
from neptune.handler import Handler
from neptune.integrations.python_logger import NeptuneHandler
from neptune.logging.logger import Logger

# ------------- management ---------------
from neptune.management.exceptions import (
Expand Down
Loading