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

Use consistent logging #1611

Merged
merged 20 commits into from
Jan 30, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Handle logging in the `AsyncOperationProcessor` with `OperationLogger` and signal queue ([#1610](https://github.com/neptune-ai/neptune-client/pull/1610))
- Stringify `Handler` paths ([#1623](https://github.com/neptune-ai/neptune-client/pull/1623))
- Added processor id to `ProcessorStopSignalData` ([#1625](https://github.com/neptune-ai/neptune-client/pull/1625))
- Use the same logger instance for logging ([#1611](https://github.com/neptune-ai/neptune-client/pull/1611))


## 1.8.6
Expand Down
4 changes: 3 additions & 1 deletion src/neptune/attributes/atoms/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
)
from neptune.internal.container_type import ContainerType
from neptune.internal.operation import AssignInt
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger
from neptune.types.atoms.integer import Integer as IntegerVal

if typing.TYPE_CHECKING:
from neptune.internal.backends.neptune_backend import NeptuneBackend

logger = get_logger()


class Integer(CopiableAtom):
@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion src/neptune/attributes/atoms/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
from neptune.attributes.atoms.copiable_atom import CopiableAtom
from neptune.internal.container_type import ContainerType
from neptune.internal.operation import AssignString
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger
from neptune.internal.utils.paths import path_to_str
from neptune.types.atoms.string import String as StringVal

if typing.TYPE_CHECKING:
from neptune.internal.backends.neptune_backend import NeptuneBackend
from neptune.metadata_containers import MetadataContainer

logger = get_logger()


class String(CopiableAtom):

Expand Down
3 changes: 2 additions & 1 deletion src/neptune/attributes/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
NoValue,
atomic_attribute_types_map,
)
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger
from neptune.internal.utils.paths import (
parse_path,
path_to_str,
Expand All @@ -46,6 +46,7 @@
if TYPE_CHECKING:
from neptune.metadata_containers import MetadataContainer

logger = get_logger()
RunStructure = ContainerStructure # backwards compatibility


Expand Down
4 changes: 3 additions & 1 deletion src/neptune/attributes/series/string_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Operation,
)
from neptune.internal.utils import is_collection
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger
from neptune.internal.utils.paths import path_to_str
from neptune.types.series.string_series import MAX_STRING_SERIES_VALUE_LENGTH
from neptune.types.series.string_series import StringSeries as StringSeriesVal
Expand All @@ -43,6 +43,8 @@
Data = str
LogOperation = LogStrings

logger = get_logger()


class StringSeries(
Series[Val, Data, LogOperation], FetchableSeries[StringSeriesValues], max_batch_size=10, operation_cls=LogOperation
Expand Down
4 changes: 3 additions & 1 deletion src/neptune/cli/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
from neptune.cli.status import StatusRunner
from neptune.cli.utils import get_offline_dirs
from neptune.constants import SYNC_DIRECTORY
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger

if TYPE_CHECKING:
from neptune.internal.backends.api_model import ApiExperiment
from neptune.internal.id_formats import UniqueId

logger = get_logger(with_prefix=False)


class ClearRunner(AbstractBackendRunner):
def clear(self, path: Path, force: bool = False, clear_eventual: bool = True) -> None:
Expand Down
4 changes: 3 additions & 1 deletion src/neptune/cli/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
from neptune.constants import OFFLINE_NAME_PREFIX
from neptune.envs import PROJECT_ENV_NAME
from neptune.internal.backends.api_model import ApiExperiment
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger

logger = get_logger(with_prefix=False)

offline_run_explainer = """
Runs that execute offline are not created on the server and are not assigned to projects;
Expand Down
6 changes: 3 additions & 3 deletions src/neptune/cli/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

__all__ = ["SyncRunner"]

import logging
import os
import threading
import time
Expand Down Expand Up @@ -61,8 +60,9 @@
)
from neptune.internal.operation import Operation
from neptune.internal.operation_processors.operation_storage import OperationStorage
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger

logger = get_logger(with_prefix=False)
retries_timeout = int(os.getenv(NEPTUNE_SYNC_BATCH_TIMEOUT_ENV, "3600"))


Expand Down Expand Up @@ -186,7 +186,7 @@ def _register_offline_container(self, project: Project, container_type: Containe
logger.warning(
"Exception occurred while trying to create a run" " on the Neptune server. Please try again later",
)
logging.exception(e)
logger.exception(e)
return None

@staticmethod
Expand Down
7 changes: 4 additions & 3 deletions src/neptune/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"split_dir_name",
]

import logging
import os
import textwrap
import threading
Expand Down Expand Up @@ -59,7 +58,9 @@
UniqueId,
)
from neptune.internal.operation import Operation
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger

logger = get_logger(with_prefix=False)


def get_metadata_container(
Expand All @@ -74,7 +75,7 @@ def get_metadata_container(
logger.warning("Can't fetch %s %s. Skipping.", public_container_type, container_id)
except NeptuneException as e:
logger.warning("Exception while fetching %s %s. Skipping.", public_container_type, container_id)
logging.exception(e)
logger.exception(e)

return None

Expand Down
4 changes: 2 additions & 2 deletions src/neptune/common/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
__all__ = ["with_api_exceptions_handler", "get_retry_from_headers_or_default"]

import itertools
import logging
import os
import time

Expand Down Expand Up @@ -47,8 +46,9 @@
NeptuneInvalidApiTokenException,
Unauthorized,
)
from neptune.internal.utils.logger import get_logger

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

MAX_RETRY_TIME = 30
MAX_RETRY_MULTIPLIER = 10
Expand Down
16 changes: 7 additions & 9 deletions src/neptune/common/hardware/gpu/gpu_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
# limitations under the License.
#

import logging

from neptune.common.warnings import (
NeptuneWarning,
warn_once,
)
from neptune.vendor.pynvml import (
NVMLError,
nvmlDeviceGetCount,
Expand All @@ -25,8 +27,6 @@
nvmlInit,
)

_logger = logging.getLogger(__name__)


class GPUMonitor(object):

Expand Down Expand Up @@ -62,14 +62,12 @@ def __nvml_get_or_else(self, getter, default=None):
try:
nvmlInit()
return getter()
except NVMLError as e:
except NVMLError:
if not GPUMonitor.nvml_error_printed:
warning = (
"Info (NVML): %s. GPU usage metrics may not be reported. For more information, "
"see https://docs-legacy.neptune.ai/logging-and-managing-experiment-results"
"/logging-experiment"
"-data.html#hardware-consumption "
"see https://docs.neptune.ai/help/nvml_error/"
)
_logger.warning(warning, e)
warn_once(message=warning, exception=NeptuneWarning)
GPUMonitor.nvml_error_printed = True
return default
5 changes: 3 additions & 2 deletions src/neptune/common/storage/storage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
#
import io
import logging
import os
import stat
import time
Expand All @@ -35,7 +34,9 @@

import six

_logger = logging.getLogger(__name__)
from neptune.internal.utils.logger import get_logger

_logger = get_logger()


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions src/neptune/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import functools
import glob as globlib
import logging
import math
import os
import re
Expand All @@ -37,8 +36,9 @@
)
from neptune.common.git_info import GitInfo
from neptune.common.patterns import PROJECT_QUALIFIED_NAME_PATTERN
from neptune.internal.utils.logger import get_logger

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

IS_WINDOWS = sys.platform == "win32"
IS_MACOS = sys.platform == "darwin"
Expand Down
3 changes: 2 additions & 1 deletion src/neptune/internal/backends/hosted_file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@
get_absolute_paths,
get_common_root,
)
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger

logger = get_logger()
DEFAULT_CHUNK_SIZE = 5 * BYTES_IN_ONE_MB
DEFAULT_UPLOAD_CONFIG = AttributeUploadConfiguration(chunk_size=DEFAULT_CHUNK_SIZE)

Expand Down
4 changes: 2 additions & 2 deletions src/neptune/internal/backends/hosted_neptune_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
__all__ = ["HostedNeptuneBackend"]

import itertools
import logging
import os
import re
import typing
Expand Down Expand Up @@ -136,6 +135,7 @@
from neptune.internal.utils import base64_decode
from neptune.internal.utils.generic_attribute_mapper import map_attribute_result_to_value
from neptune.internal.utils.git import GitInfo
from neptune.internal.utils.logger import get_logger
from neptune.internal.utils.paths import path_to_str
from neptune.internal.websockets.websockets_factory import WebsocketsFactory
from neptune.management.exceptions import ObjectNotFound
Expand All @@ -147,7 +147,7 @@
from neptune.internal.backends.api_model import ClientConfig


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


class HostedNeptuneBackend(NeptuneBackend):
Expand Down
4 changes: 2 additions & 2 deletions src/neptune/internal/backends/project_name_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#
__all__ = ["project_name_lookup"]

import logging
import os
from typing import Optional

Expand All @@ -25,8 +24,9 @@
from neptune.internal.backends.neptune_backend import NeptuneBackend
from neptune.internal.id_formats import QualifiedName
from neptune.internal.utils import verify_type
from neptune.internal.utils.logger import get_logger

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


def project_name_lookup(backend: NeptuneBackend, name: Optional[QualifiedName] = None) -> Project:
Expand Down
5 changes: 2 additions & 3 deletions src/neptune/internal/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
]

import dataclasses
import logging
import os
import socket
from functools import (
Expand Down Expand Up @@ -78,9 +77,9 @@
Operation,
)
from neptune.internal.utils import replace_patch_version
from neptune.internal.utils.logger import logger
from neptune.internal.utils.logger import get_logger

_logger = logging.getLogger(__name__)
logger = get_logger()

if TYPE_CHECKING:
from neptune.internal.backends.neptune_backend import NeptuneBackend
Expand Down
4 changes: 2 additions & 2 deletions src/neptune/internal/disk_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
__all__ = ["QueueElement", "DiskQueue"]

import json
import logging
import os
import shutil
import threading
Expand All @@ -39,12 +38,13 @@
should_clean_internal_data,
)
from neptune.internal.utils.json_file_splitter import JsonFileSplitter
from neptune.internal.utils.logger import get_logger
from neptune.internal.utils.sync_offset_file import SyncOffsetFile

T = TypeVar("T")
Timestamp = float

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


@dataclass
Expand Down
5 changes: 2 additions & 3 deletions src/neptune/internal/hardware/gpu/gpu_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#
__all__ = ["GPUMonitor"]

import logging

from neptune.internal.utils.logger import get_logger
from neptune.vendor.pynvml import (
NVMLError,
nvmlDeviceGetCount,
Expand All @@ -26,7 +25,7 @@
nvmlInit,
)

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


class GPUMonitor(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#
__all__ = ["HardwareMetricReportingJob"]

import logging
import os
import time
from itertools import groupby
Expand All @@ -36,12 +35,13 @@
from neptune.internal.background_job import BackgroundJob
from neptune.internal.hardware.gpu.gpu_monitor import GPUMonitor
from neptune.internal.threading.daemon import Daemon
from neptune.internal.utils.logger import get_logger
from neptune.types.series import FloatSeries

if TYPE_CHECKING:
from neptune.metadata_containers import MetadataContainer

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


class HardwareMetricReportingJob(BackgroundJob):
Expand Down