Python Logger

You can use NeptuneHandler to store logs from Python's Logger as a Runs metadata.

Installation

Python Logger integration is part of the Neptune Client Library and requires no additional installation. Simply import the NeptuneHandler from the integrations module in your script.

from neptune.new.integrations.python_logger import NeptuneHandler

NeptuneHandler

A Handler object that sends the log records created by the logger to which it's attached to Neptune. Logs will be stored as a StringSeries field.

__init__

Initializes a NeptuneHandler object.

Parameters

run

(Run) - An existing run reference (as returned by neptune.init()).

level

(int, optional, default is logging.NOTSET) - Log level of the logs to be captured by the handler. Defaults to logging.NOTSET, which captures all logs that match logger's level.

path

(str, optional, default is None) - Path to the StringSeries field used for captured logs. If None, tracked metadata will be stored inside monitoring_namespace.

Examples

# Create a Python's Logger
import logging
logger = logging.getLogger("root_experiment")
logger.setLevel(logging.DEBUG)
# Instantiate a Run object
import neptune.new as neptune
run = neptune.init(project="neptune/sandbox")
# Create a NeptuneHandler object to capture the logs
from neptune.new.integrations.python_logger import NeptuneHandler
npt_handler = NeptuneHandler(run=run)
logger.addHandler(npt_handler)
# Log something to the logger
logger.debug("Starting data preparation")
logger.debug("Data preparation done")