Skip to main content

OCI Log Handler

A buffered Python logging handler that sends application logs to Oracle Cloud Infrastructure Logging by using the OCI Python SDK Logging Ingestion client.

Requires Python 3.11 or later.

Installation

pip install oci-log-handler

Usage

import logging

import oci
from oci_log_handler import OciLoggingHandler

config = oci.config.from_file()

handler = OciLoggingHandler(
    "ocid1.log.oc1..example",
    config=config,
    capacity=100,
)
handler.setFormatter(logging.Formatter("%(levelname)s:%(name)s:%(message)s"))

logger = logging.getLogger("my-app")
logger.setLevel(logging.INFO)
logger.addHandler(handler)

logger.info("Application started")

You can also pass an existing OCI Logging Ingestion client:

import logging

import oci
from oci import loggingingestion
from oci_log_handler import OciLoggingHandler

config = oci.config.from_file()
client = loggingingestion.LoggingClient(config)

handler = OciLoggingHandler(
    "ocid1.log.oc1..example",
    client=client,
    capacity=100,
)

logger = logging.getLogger("my-app")
logger.addHandler(handler)

For signer-based authentication, pass signer= when constructing the handler or create the LoggingClient with your signer and pass it as client=.

Handler arguments

OciLoggingHandler takes the target OCI log OCID as its first argument:

OciLoggingHandler("ocid1.log.oc1..example", ...)

Optional keyword arguments:

  • config: OCI SDK config dictionary.
  • signer: OCI signer to use instead of config-file key authentication.
  • capacity: number of log records to buffer before flushing. Defaults to 100.
  • client: existing oci.loggingingestion.LoggingClient. When provided, config and signer are not used to create a client.
  • source: OCI log entry batch source. Defaults to "oci-log-handler".
  • log_type: OCI log entry batch type. Defaults to "python_application".
  • specversion: OCI logs payload spec version. Defaults to "1.0".
  • raise_exceptions: re-raise OCI submission errors instead of using logging.Handler.handleError. Defaults to False.

Provide one of config, signer, or client.

Delivery behavior

This handler is best-effort and keeps its retry buffer in memory. By default, failed submissions are restored to the handler's bounded buffer and do not raise exceptions into the application. If the process exits before a later successful flush, those buffered records are not durable.

Pass raise_exceptions=True if your application should fail fast when OCI submission fails.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oci_log_handler-0.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oci_log_handler-0.1.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file oci_log_handler-0.1.2.tar.gz.

File metadata

  • Download URL: oci_log_handler-0.1.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.11

File hashes

Hashes for oci_log_handler-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3b99653d7fa9b1d25b8723c9e51529219b964b7ab2fb3feffcc79c5594e0bf1c
MD5 249bae645b0b0f5537b53b7ce212af10
BLAKE2b-256 46b614e6bc51a753e3bb578394c0f0a1caeeb4fa46b696650a8312e276bbbf92

See more details on using hashes here.

File details

Details for the file oci_log_handler-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for oci_log_handler-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 995905c06d819257e6651c668f329e4c33acebfa3c0ca6adedc1727d9ca23089
MD5 93f142257aeea19d30c2722f0e10c757
BLAKE2b-256 ea863418cdfe4c3e0566141be9e727e0c5849e4da43b96fe7be488888484b559

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page