Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/simple-http-checker-PedroLima)](https://pypi.org/project/simple-http-checker-PedroLima/)
[![PyPI version](https://img.shields.io/pypi/v/simple-http-checker-PedroLima)](https://pypi.org/project/simple-http-checker-PedroLima/)
[![Downloads](https://pepy.tech/badge/simple-http-checker-PedroLima/month)](https://pepy.tech/project/simple-http-checker-PedroLima)
[![CI/CD](https://github.com/PedroBizachi/python-devops-cicd-project/actions/workflows/python-ci.yaml/badge.svg)](https://github.com/PedroBizachi/python-devops-cicd-project/actions/workflows/python-ci.yaml)
[![Publish](https://github.com/PedroBizachi/python-devops-cicd-project/actions/workflows/publish.yaml/badge.svg)](https://github.com/PedroBizachi/python-devops-cicd-project/actions/workflows/publish.yaml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# Python for DevOps: CI/CD for Python Projects

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "1.2.0"
description = "A simple CLI tool to check the status of URLs."
readme = "README.md"
requires-python = ">=3.9"
dependencies = ["click>=8.0,<9.0", "requests>=2.28,<3.0"]
dependencies = ["click>=8.0,<9.0", "requests>=2.28,<3.0", "rich>=15.0,<16.0"]
authors = [{ name = "Pedro Lima" }, { email = "bizak.dev@outlook.com" }]
license = { text = "MIT" }
classifiers = [
Expand All @@ -29,7 +29,7 @@ classifiers = [

[project.urls]
Homepage = "https://github.com/PedroBizachi/python-devops-cicd-project"
Documentation = "https://github.com/lm-academy/python-devops-cicd-project/blob/main/README.md"
Documentation = "https://github.com/PedroBizachi/python-devops-cicd-project/blob/main/README.md"
Repository = "https://github.com/PedroBizachi/python-devops-cicd-project"
Issues = "https://github.com/PedroBizachi/python-devops-cicd-project/issues"
Changelog = "https://github.com/PedroBizachi/python-devops-cicd-project/blob/main/CHANGELOG.md"
Expand Down
41 changes: 10 additions & 31 deletions src/simple_http_checker/cli.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
import logging
from collections.abc import Collection
from typing import ClassVar

import click
from rich.logging import RichHandler

from simple_http_checker.checker import check_urls


class ColoredLevelFormatter(logging.Formatter):
LEVEL_COLORS: ClassVar[dict[int, str]] = {
logging.DEBUG: "cyan",
logging.INFO: "green",
logging.WARNING: "yellow",
logging.ERROR: "red",
logging.CRITICAL: "magenta",
}

def format(self, record: logging.LogRecord) -> str:
original_levelname = record.levelname
color = self.LEVEL_COLORS.get(record.levelno)
if color:
record.levelname = click.style(record.levelname, fg=color)

try:
return super().format(record)
finally:
record.levelname = original_levelname


handler = logging.StreamHandler()
handler.setFormatter(
ColoredLevelFormatter(
fmt="[%(asctime)s] %(levelname)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logging.basicConfig(
level=logging.INFO,
format="%(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[
RichHandler(
show_path=False,
)
],
)

logging.basicConfig(level=logging.INFO, handlers=[handler])

logger = logging.getLogger(__name__)


Expand Down
Loading