1# SPDX-License-Identifier: MIT OR Apache-2.0
2# This file is dual licensed under the terms of the Apache License, Version
3# 2.0, and the MIT License. See the LICENSE file in the root of this
4# repository for complete details.
5
6
7from __future__ import annotations
8
9from structlog import (
10 contextvars,
11 dev,
12 processors,
13 stdlib,
14 testing,
15 threadlocal,
16 tracebacks,
17 types,
18 typing,
19)
20from structlog._base import BoundLoggerBase, get_context
21from structlog._config import (
22 configure,
23 configure_once,
24 get_config,
25 get_logger,
26 getLogger,
27 is_configured,
28 reset_defaults,
29 wrap_logger,
30)
31from structlog._generic import BoundLogger
32from structlog._native import make_filtering_bound_logger
33from structlog._output import (
34 BytesLogger,
35 BytesLoggerFactory,
36 PrintLogger,
37 PrintLoggerFactory,
38 WriteLogger,
39 WriteLoggerFactory,
40)
41from structlog.exceptions import DropEvent
42from structlog.testing import ReturnLogger, ReturnLoggerFactory
43
44
45try:
46 from structlog import twisted
47except ImportError:
48 twisted = None # type: ignore[assignment]
49
50
51__title__ = "structlog"
52
53__author__ = "Hynek Schlawack"
54
55__license__ = "MIT or Apache License, Version 2.0"
56__copyright__ = "Copyright (c) 2013 " + __author__
57
58
59__all__ = [
60 "BoundLogger",
61 "BoundLoggerBase",
62 "BytesLogger",
63 "BytesLoggerFactory",
64 "DropEvent",
65 "PrintLogger",
66 "PrintLoggerFactory",
67 "ReturnLogger",
68 "ReturnLoggerFactory",
69 "WriteLogger",
70 "WriteLoggerFactory",
71 "configure",
72 "configure_once",
73 "contextvars",
74 "dev",
75 "getLogger",
76 "get_config",
77 "get_context",
78 "get_logger",
79 "is_configured",
80 "make_filtering_bound_logger",
81 "processors",
82 "reset_defaults",
83 "stdlib",
84 "testing",
85 "threadlocal",
86 "tracebacks",
87 "twisted",
88 "types",
89 "typing",
90 "wrap_logger",
91]
92
93
94def __getattr__(name: str) -> str:
95 import warnings
96
97 from importlib.metadata import metadata, version
98
99 dunder_to_metadata = {
100 "__description__": "summary",
101 "__uri__": "",
102 "__email__": "",
103 "__version__": "",
104 }
105 if name not in dunder_to_metadata:
106 msg = f"module {__name__} has no attribute {name}"
107 raise AttributeError(msg)
108
109 if name != "__version__":
110 warnings.warn(
111 f"Accessing structlog.{name} is deprecated and will be "
112 "removed in a future release. Use importlib.metadata directly "
113 "to query for structlog's packaging metadata.",
114 DeprecationWarning,
115 stacklevel=2,
116 )
117 else:
118 return version("structlog")
119
120 meta = metadata("structlog")
121
122 if name == "__uri__":
123 return meta["Project-URL"].split(" ", 1)[-1]
124
125 if name == "__email__":
126 return meta["Author-email"].split("<", 1)[1].rstrip(">")
127
128 return meta[dunder_to_metadata[name]]