logging.py — langchain Source File
Architecture documentation for logging.py, a python file in the langchain codebase. 7 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR c93b073e_0531_3422_6c6f_b830d435b217["logging.py"] c93b073e_0531_3422_6c6f_b830d435b217["logging.py"] c93b073e_0531_3422_6c6f_b830d435b217 --> c93b073e_0531_3422_6c6f_b830d435b217 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] c93b073e_0531_3422_6c6f_b830d435b217 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"] c93b073e_0531_3422_6c6f_b830d435b217 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5 75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"] c93b073e_0531_3422_6c6f_b830d435b217 --> 75137834_4ba7_dc43_7ec5_182c05eceedf 8bf7b3ca_c639_e4bc_1078_4c3d567f3209["langchain_core.tracers.stdout"] c93b073e_0531_3422_6c6f_b830d435b217 --> 8bf7b3ca_c639_e4bc_1078_4c3d567f3209 75b56223_6cf5_b347_8586_de20156157a1["langchain_core.utils.input"] c93b073e_0531_3422_6c6f_b830d435b217 --> 75b56223_6cf5_b347_8586_de20156157a1 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] c93b073e_0531_3422_6c6f_b830d435b217 --> 91721f45_4909_e489_8c1f_084f8bd87145 c93b073e_0531_3422_6c6f_b830d435b217["logging.py"] c93b073e_0531_3422_6c6f_b830d435b217 --> c93b073e_0531_3422_6c6f_b830d435b217 style c93b073e_0531_3422_6c6f_b830d435b217 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
__all__ = ["LoggingCallbackHandler"]
import logging
from typing import Any
from uuid import UUID
from langchain_core.exceptions import TracerException
from langchain_core.tracers.stdout import FunctionCallbackHandler
from langchain_core.utils.input import get_bolded_text, get_colored_text
from typing_extensions import override
class LoggingCallbackHandler(FunctionCallbackHandler):
"""Tracer that logs via the input Logger."""
name: str = "logging_callback_handler"
def __init__(
self,
logger: logging.Logger,
log_level: int = logging.INFO,
extra: dict | None = None,
**kwargs: Any,
) -> None:
"""Initialize the LoggingCallbackHandler.
Args:
logger: the logger to use for logging
log_level: the logging level (default: logging.INFO)
extra: the extra context to log (default: None)
**kwargs: additional keyword arguments.
"""
log_method = getattr(logger, logging.getLevelName(level=log_level).lower())
def callback(text: str) -> None:
log_method(text, extra=extra)
super().__init__(function=callback, **kwargs)
@override
def on_text(
self,
text: str,
*,
run_id: UUID,
parent_run_id: UUID | None = None,
**kwargs: Any,
) -> None:
try:
crumbs_str = f"[{self.get_breadcrumbs(run=self._get_run(run_id=run_id))}] "
except TracerException:
crumbs_str = ""
self.function_callback(
f"{get_colored_text('[text]', color='blue')}"
f" {get_bolded_text(f'{crumbs_str}New text:')}\n{text}",
)
Domain
Subdomains
Classes
Dependencies
- langchain_core.exceptions
- langchain_core.tracers.stdout
- langchain_core.utils.input
- logging.py
- typing
- typing_extensions
- uuid
Source
Frequently Asked Questions
What does logging.py do?
logging.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does logging.py depend on?
logging.py imports 7 module(s): langchain_core.exceptions, langchain_core.tracers.stdout, langchain_core.utils.input, logging.py, typing, typing_extensions, uuid.
What files import logging.py?
logging.py is imported by 1 file(s): logging.py.
Where is logging.py in the architecture?
logging.py is located at libs/langchain/langchain_classic/callbacks/tracers/logging.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic/callbacks/tracers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free