Skip to content

Commit

Permalink
consistently use getLogger(__name__), no root logger (#2989)
Browse files Browse the repository at this point in the history
re
#439 (comment)

I think it's not polite for a library to use the root logger

both of these forms are also used:
```
logger = logging.getLogger(__name__)
logger = logging.getLogger(__file__)
```
I am not sure if there is any reason behind one vs the other? (...I am
guessing maybe just contributed by different people)

it seems to me it'd be better to consistently use
`logging.getLogger(__name__)`

this makes it easier for consumers of the library to set up log
handlers, e.g. for everything with `langchain.` prefix
  • Loading branch information
anentropic committed Apr 16, 2023
1 parent 32db2a2 commit 69698be
Show file tree
Hide file tree
Showing 19 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion langchain/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from langchain.tools.base import BaseTool
from langchain.utilities.asyncio import asyncio_timeout

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


class BaseSingleActionAgent(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion langchain/chat_models/azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from langchain.chat_models.openai import ChatOpenAI
from langchain.utils import get_from_dict_or_env

logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


class AzureChatOpenAI(ChatOpenAI):
Expand Down
2 changes: 1 addition & 1 deletion langchain/chat_models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from langchain.utils import get_from_dict_or_env

logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


def _create_retry_decorator(llm: ChatOpenAI) -> Callable[[Any], Any]:
Expand Down
2 changes: 1 addition & 1 deletion langchain/document_loaders/diffbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseLoader

logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


class DiffbotLoader(BaseLoader):
Expand Down
2 changes: 1 addition & 1 deletion langchain/document_loaders/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
FILE_LOADER_TYPE = Union[
Type[UnstructuredFileLoader], Type[TextLoader], Type[BSHTMLLoader]
]
logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


def _is_visible(p: Path) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion langchain/document_loaders/html_bs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseLoader

logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


class BSHTMLLoader(BaseLoader):
Expand Down
2 changes: 1 addition & 1 deletion langchain/document_loaders/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseLoader

logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


class UnstructuredURLLoader(BaseLoader):
Expand Down
2 changes: 1 addition & 1 deletion langchain/document_loaders/url_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseLoader

logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


class PlaywrightURLLoader(BaseLoader):
Expand Down
2 changes: 1 addition & 1 deletion langchain/document_loaders/url_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseLoader

logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


class SeleniumURLLoader(BaseLoader):
Expand Down
2 changes: 1 addition & 1 deletion langchain/document_loaders/web_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseLoader

logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)

default_header_template = {
"User-Agent": "",
Expand Down
2 changes: 1 addition & 1 deletion langchain/llms/huggingface_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
DEFAULT_TASK = "text-generation"
VALID_TASKS = ("text2text-generation", "text-generation")

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


class HuggingFacePipeline(LLM):
Expand Down
2 changes: 1 addition & 1 deletion langchain/llms/self_hosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from langchain.llms.base import LLM
from langchain.llms.utils import enforce_stop_tokens

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


def _generate_text(
Expand Down
2 changes: 1 addition & 1 deletion langchain/llms/self_hosted_hugging_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
DEFAULT_TASK = "text-generation"
VALID_TASKS = ("text2text-generation", "text-generation")

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


def _generate_text(
Expand Down
2 changes: 1 addition & 1 deletion langchain/prompts/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from langchain.utilities.loading import try_load_from_hub

URL_BASE = "https://raw.githubusercontent.com/hwchase17/langchain-hub/master/prompts/"
logger = logging.getLogger(__file__)
logger = logging.getLogger(__name__)


def load_prompt_from_config(config: dict) -> BasePromptTemplate:
Expand Down
2 changes: 1 addition & 1 deletion langchain/text_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from langchain.docstore.document import Document

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


class TextSplitter(ABC):
Expand Down
2 changes: 1 addition & 1 deletion langchain/vectorstores/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from langchain.embeddings.base import Embeddings
from langchain.vectorstores.base import VectorStore

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


class AtlasDB(VectorStore):
Expand Down
2 changes: 1 addition & 1 deletion langchain/vectorstores/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import chromadb
import chromadb.config

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


def _results_to_docs(results: Any) -> List[Document]:
Expand Down
2 changes: 1 addition & 1 deletion langchain/vectorstores/deeplake.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from langchain.vectorstores.base import VectorStore
from langchain.vectorstores.utils import maximal_marginal_relevance

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

distance_metric_map = {
"l2": lambda a, b: np.linalg.norm(a - b, axis=1, ord=2),
Expand Down
2 changes: 1 addition & 1 deletion langchain/vectorstores/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from langchain.utils import get_from_dict_or_env
from langchain.vectorstores.base import VectorStore

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


# required modules
Expand Down

0 comments on commit 69698be

Please sign in to comment.