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: Union[int, str, bool, None])
| 120 | |
| 121 | @staticmethod |
| 122 | def _get_auto_indent(auto_indent_option: Union[int, str, bool, None]) -> int: |
| 123 | """Determine the current auto indentation setting. |
| 124 | |
| 125 | Specify auto indent behavior (on/off/fixed) by passing in |
| 126 | extra={"auto_indent": [value]} to the call to logging.log() or |
| 127 | using a --log-auto-indent [value] command line or the |
| 128 | log_auto_indent [value] config option. |
| 129 | |
| 130 | Default behavior is auto-indent off. |
| 131 | |
| 132 | Using the string "True" or "on" or the boolean True as the value |
| 133 | turns auto indent on, using the string "False" or "off" or the |
| 134 | boolean False or the int 0 turns it off, and specifying a |
| 135 | positive integer fixes the indentation position to the value |
| 136 | specified. |
| 137 | |
| 138 | Any other values for the option are invalid, and will silently be |
| 139 | converted to the default. |
| 140 | |
| 141 | :param None|bool|int|str auto_indent_option: |
| 142 | User specified option for indentation from command line, config |
| 143 | or extra kwarg. Accepts int, bool or str. str option accepts the |
| 144 | same range of values as boolean config options, as well as |
| 145 | positive integers represented in str form. |
| 146 | |
| 147 | :returns: |
| 148 | Indentation value, which can be |
| 149 | -1 (automatically determine indentation) or |
| 150 | 0 (auto-indent turned off) or |
| 151 | >0 (explicitly set indentation position). |
| 152 | """ |
| 153 | |
| 154 | if auto_indent_option is None: |
| 155 | return 0 |
| 156 | elif isinstance(auto_indent_option, bool): |
| 157 | if auto_indent_option: |
| 158 | return -1 |
| 159 | else: |
| 160 | return 0 |
| 161 | elif isinstance(auto_indent_option, int): |
| 162 | return int(auto_indent_option) |
| 163 | elif isinstance(auto_indent_option, str): |
| 164 | try: |
| 165 | return int(auto_indent_option) |
| 166 | except ValueError: |
| 167 | pass |
| 168 | try: |
| 169 | if _strtobool(auto_indent_option): |
| 170 | return -1 |
| 171 | except ValueError: |
| 172 | return 0 |
| 173 | |
| 174 | return 0 |
| 175 | |
| 176 | def format(self, record: logging.LogRecord) -> str: |
| 177 | if "\n" in record.message: |
no test coverage detected