# opentelemetry._logs package

## Submodules

- opentelemetry._logs.severity
  - `SeverityNumber`
    - `SeverityNumber.UNSPECIFIED`
    - `SeverityNumber.TRACE`
    - `SeverityNumber.TRACE2`
    - `SeverityNumber.TRACE3`
    - `SeverityNumber.TRACE4`
    - `SeverityNumber.DEBUG`
    - `SeverityNumber.DEBUG2`
    - `SeverityNumber.DEBUG3`
    - `SeverityNumber.DEBUG4`
    - `SeverityNumber.INFO`
    - `SeverityNumber.INFO2`
    - `SeverityNumber.INFO3`
    - `SeverityNumber.INFO4`
    - `SeverityNumber.WARN`
    - `SeverityNumber.WARN2`
    - `SeverityNumber.WARN3`
    - `SeverityNumber.WARN4`
    - `SeverityNumber.ERROR`
    - `SeverityNumber.ERROR2`
    - `SeverityNumber.ERROR3`
    - `SeverityNumber.ERROR4`
    - `SeverityNumber.FATAL`
    - `SeverityNumber.FATAL2`
    - `SeverityNumber.FATAL3`
    - `SeverityNumber.FATAL4`

## Module contents

The OpenTelemetry logging API describes the classes used to generate logs and events.

The `LoggerProvider` provides users access to the `Logger`.

This module provides abstract (i.e. unimplemented) classes required for logging, and a concrete no-op implementation `NoOpLogger` that allows applications to use the API package alone without a supporting implementation.

To get a logger, you need to provide the package name from which you are calling the logging APIs to OpenTelemetry by calling `LoggerProvider.get_logger` with the calling module name and the version of your package.

The following code shows how to obtain a logger using the global `LoggerProvider`:

    from opentelemetry._logs import get_logger

    logger = get_logger("example-logger")

Added in version 1.15.0.

class opentelemetry._logs.Logger(name, version=None, schema_url=None, attributes=None)

  Bases: `ABC`

  Handles emitting events and logs via `LogRecord`.

  abstractmethod emit(record=None, *, timestamp=None, observed_timestamp=None, context=None, severity_number=None, severity_text=None, body=None, attributes=None, event_name=None, exception=None)
    Overloads:

      - self, timestamp (int | None), observed_timestamp (int | None), context (Context | None), severity_number (SeverityNumber | None), severity_text (str | None), body (AnyValue | None), attributes (_ExtendedAttributes | None), event_name (str | None), exception (BaseException | None) → None

      - self, record (LogRecord) → None

    Emits a `LogRecord` representing a log to the processing pipeline.

class opentelemetry._logs.LoggerProvider

  Bases: `ABC`

  LoggerProvider is the entry point of the API. It provides access to Logger instances.

  abstractmethod get_logger(name, version=None, schema_url=None, attributes=None)

    Returns a `Logger` for use by the given instrumentation library.

    For any two calls with identical parameters, it is undefined whether the same or different `Logger` instances are returned.

    This function may return different `Logger` types (e.g. a no-op logger vs. a functional logger).

    Parameters:

      - name (`str`) –

        The name of the instrumenting module, package or class. This should not be the name of the module, package or class that is instrumented but the name of the code doing the instrumentation. E.g., instead of `"requests"`, use `"opentelemetry.instrumentation.requests"`.

        For log sources which define a logger name (e.g. logging.Logger.name) the Logger Name should be recorded as the instrumentation scope name.

      - version (`str` | `None`) – Optional. The version string of the instrumenting library. Usually this should be the same as `importlib.metadata.version(instrumenting_library_name)`.

      - schema_url (`str` | `None`) – Optional. Specifies the Schema URL of the emitted telemetry.

      - attributes (`Mapping`[`str`, `str` | `bool` | `int` | `float` | `bytes` | `Sequence`[AnyValue] | `Mapping`[`str`, AnyValue] | `None`] | `None`) – Optional. Specifies the instrumentation scope attributes to associate with emitted telemetry.

    Return type:

      `Logger`

class opentelemetry._logs.LogRecord(*, timestamp=None, observed_timestamp=None, context=None, trace_id=None, span_id=None, trace_flags=None, severity_text=None, severity_number=None, body=None, attributes=None, event_name=None, exception=None)

  Bases: `ABC`

  A LogRecord instance represents an event being logged.

  LogRecord instances are created and emitted via `Logger` every time something is logged. They contain all the information pertinent to the event being logged.

class opentelemetry._logs.NoOpLogger(name, version=None, schema_url=None, attributes=None)

  Bases: `Logger`

  The default Logger used when no Logger implementation is available.

  All operations are no-op.

  emit(record=None, *, timestamp=None, observed_timestamp=None, context=None, severity_number=None, severity_text=None, body=None, attributes=None, event_name=None, exception=None)
    Overloads:

      - self, timestamp (int | None), observed_timestamp (int | None), context (Context | None), severity_number (SeverityNumber | None), severity_text (str | None), body (AnyValue | None), attributes (_ExtendedAttributes | None), event_name (str | None), exception (BaseException | None) → None

      - self, record (LogRecord) → None

    Emits a `LogRecord` representing a log to the processing pipeline.

class opentelemetry._logs.NoOpLoggerProvider

  Bases: `LoggerProvider`

  The default LoggerProvider used when no LoggerProvider implementation is available.

  get_logger(name, version=None, schema_url=None, attributes=None)

    Returns a NoOpLogger.

    Return type:

      `Logger`

opentelemetry._logs.get_logger(instrumenting_module_name, instrumenting_library_version='', logger_provider=None, schema_url=None, attributes=None)

  Returns a `Logger` for use within a python process.

  This function is a convenience wrapper for opentelemetry.sdk._logs.LoggerProvider.get_logger.

  If logger_provider param is omitted the current configured one is used.

  Return type:

    `Logger`

opentelemetry._logs.get_logger_provider()

  Gets the current global `LoggerProvider` object.

  Return type:

    `LoggerProvider`

opentelemetry._logs.set_logger_provider(logger_provider)

  Sets the current global `LoggerProvider` object.

  This can only be done once, a warning will be logged if any further attempt is made.

  Return type:

    `None`

class opentelemetry._logs.SeverityNumber(*values)

  Bases: `Enum`

  Numerical value of severity.

  Smaller numerical values correspond to less severe events (such as debug events), larger numerical values correspond to more severe events (such as errors and critical events).

  See the Log Data Model spec for more info and how to map the severity from source format to OTLP Model.

  UNSPECIFIED = 0
  TRACE = 1
  TRACE2 = 2
  TRACE3 = 3
  TRACE4 = 4
  DEBUG = 5
  DEBUG2 = 6
  DEBUG3 = 7
  DEBUG4 = 8
  INFO = 9
  INFO2 = 10
  INFO3 = 11
  INFO4 = 12
  WARN = 13
  WARN2 = 14
  WARN3 = 15
  WARN4 = 16
  ERROR = 17
  ERROR2 = 18
  ERROR3 = 19
  ERROR4 = 20
  FATAL = 21
  FATAL2 = 22
  FATAL3 = 23
  FATAL4 = 24