MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / configure_logging

Function configure_logging

dwave/cloud/utils/logging.py:154–233  ·  view source on GitHub ↗

Configure cloud-client's `dwave.cloud` base logger. Logging output from the cloud-client is suppressed by default. This utility function can be used to quickly setup basic logging from the library. .. note:: This function is currently intended for internal/private use only.

(logger: Optional[logging.Logger] = None,
                      *,
                      level: Union[str, int] = logging.WARNING,
                      filter_secrets: bool = True,
                      output_stream: Optional[io.BytesIO] = None,
                      output_file: Optional[Union[str, bytes, os.PathLike]] = None,
                      in_utc: bool = False,
                      structured_output: bool = False,
                      handler_level: Optional[int] = None,
                      additive: bool = False,
                      )

Source from the content-addressed store, hash-verified

152
153
154def configure_logging(logger: Optional[logging.Logger] = None,
155 *,
156 level: Union[str, int] = logging.WARNING,
157 filter_secrets: bool = True,
158 output_stream: Optional[io.BytesIO] = None,
159 output_file: Optional[Union[str, bytes, os.PathLike]] = None,
160 in_utc: bool = False,
161 structured_output: bool = False,
162 handler_level: Optional[int] = None,
163 additive: bool = False,
164 ) -> logging.Logger:
165 """Configure cloud-client's `dwave.cloud` base logger.
166
167 Logging output from the cloud-client is suppressed by default. This utility
168 function can be used to quickly setup basic logging from the library.
169
170 .. note::
171 This function is currently intended for internal/private use only.
172
173 .. versionadded:: 0.12.0
174 Explicit optional logging configuration. Previously, logger was minimally
175 configured by default.
176
177 .. versionadded:: 0.13.4
178 ``output_file`` parameter to simplify logging to a file.
179 """
180
181 level = parse_loglevel(level)
182
183 if logger is None:
184 logger = logging.getLogger('dwave.cloud')
185 if handler_level is None:
186 handler_level = level
187
188 handler_level = parse_loglevel(handler_level)
189
190 Formatter = ISOFormatter
191
192 if structured_output:
193 class Formatter(JSONFormatter, Formatter):
194 pass
195
196 if filter_secrets:
197 class Formatter(FilteredSecretsFormatter, Formatter):
198 pass
199
200 format = dict(
201 fmt='%(asctime)s %(name)s %(levelname)s %(threadName)s [%(funcName)s] %(message)s',
202 as_tz=datetime.timezone.utc if in_utc else None,
203 )
204 formatter = Formatter(**format)
205
206 if not additive:
207 # make sure handlers are not accumulated
208 while len(logger.handlers):
209 handler = logger.handlers[-1]
210 # release handler resources before disposing it
211 handler.close()

Callers 9

enable_loggingFunction · 0.90
enable_loglevelFunction · 0.90
tearDownMethod · 0.90
test_file_loggingMethod · 0.90

Calls 3

parse_loglevelFunction · 0.85
FormatterClass · 0.85
closeMethod · 0.45

Tested by 6

tearDownMethod · 0.72
test_file_loggingMethod · 0.72