| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| import logging |
| from typing import Union # TODO: move to the TYPE_CHECKING block |
| |
| from rich.console import Console |
| from rich.logging import RichHandler |
| |
| |
| def setup_logging(terminal_width: Union[int, None] = None) -> None: |
| logger = logging.getLogger("graphar_cli") |
| console = Console(width=terminal_width) if terminal_width else None |
| rich_handler = RichHandler( |
| show_time=False, |
| rich_tracebacks=True, |
| tracebacks_show_locals=True, |
| markup=True, |
| show_path=False, |
| console=console, |
| ) |
| rich_handler.setFormatter(logging.Formatter("%(message)s")) |
| logger.addHandler(rich_handler) |
| |
| logger.setLevel(logging.INFO) |
| logger.propagate = False |