Determine the current auto indentation setting. Specify auto indent behavior (on/off/fixed) by passing in extra={"auto_indent": [value]} to the call to logging.log() or using a --log-auto-indent [value] command line or the log_auto_indent [value] config option.
(auto_indent_option: int | str | bool | None)
| 150 | |
| 151 | @staticmethod |
| 152 | def _get_auto_indent(auto_indent_option: int | str | bool | None) -> int: |
| 153 | """Determine the current auto indentation setting. |
| 154 | |
| 155 | Specify auto indent behavior (on/off/fixed) by passing in |
| 156 | extra={"auto_indent": [value]} to the call to logging.log() or |
| 157 | using a --log-auto-indent [value] command line or the |
| 158 | log_auto_indent [value] config option. |
| 159 | |
| 160 | Default behavior is auto-indent off. |
| 161 | |
| 162 | Using the string "True" or "on" or the boolean True as the value |
| 163 | turns auto indent on, using the string "False" or "off" or the |
| 164 | boolean False or the int 0 turns it off, and specifying a |
| 165 | positive integer fixes the indentation position to the value |
| 166 | specified. |
| 167 | |
| 168 | Any other values for the option are invalid, and will silently be |
| 169 | converted to the default. |
| 170 | |
| 171 | :param None|bool|int|str auto_indent_option: |
| 172 | User specified option for indentation from command line, config |
| 173 | or extra kwarg. Accepts int, bool or str. str option accepts the |
| 174 | same range of values as boolean config options, as well as |
| 175 | positive integers represented in str form. |
| 176 | |
| 177 | :returns: |
| 178 | Indentation value, which can be |
| 179 | -1 (automatically determine indentation) or |
| 180 | 0 (auto-indent turned off) or |
| 181 | >0 (explicitly set indentation position). |
| 182 | """ |
| 183 | match auto_indent_option: |
| 184 | case None | False: |
| 185 | return 0 |
| 186 | case True: |
| 187 | return -1 |
| 188 | case int(): |
| 189 | return auto_indent_option |
| 190 | case str(): |
| 191 | try: |
| 192 | return int(auto_indent_option) |
| 193 | except ValueError: |
| 194 | pass |
| 195 | try: |
| 196 | if _strtobool(auto_indent_option): |
| 197 | return -1 |
| 198 | except ValueError: |
| 199 | return 0 |
| 200 | return 0 |
| 201 | |
| 202 | def format(self, record: logging.LogRecord) -> str: |
| 203 | if "\n" in record.message: |
no test coverage detected