Skip to content

Commit

Permalink
Lint logger.py
Browse files Browse the repository at this point in the history
- Added type annotations
- Missing docstrings (D100, D101, D102, D103, D107) ignored for now
  • Loading branch information
garlic-os committed Jul 19, 2024
1 parent 085146c commit e0fa378
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tools/RAiDER/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import logging
import os
from pathlib import Path
import sys
from logging import FileHandler, Formatter, StreamHandler
from logging import FileHandler, Formatter, LogRecord, StreamHandler
from pathlib import Path

import RAiDER.cli.conf as conf

Expand All @@ -26,14 +26,14 @@ class UnixColorFormatter(Formatter):

COLORS = {logging.WARNING: yellow, logging.ERROR: red, logging.CRITICAL: bold_red}

def __init__(self, fmt=None, datefmt=None, style='%', use_color=True) -> None:
def __init__(self, fmt: str = None, datefmt: str = None, style: str = '%', use_color: bool=True) -> None:
super().__init__(fmt, datefmt, style)
# Save the old function so we can call it later
self.__formatMessage = self.formatMessage
if use_color:
self.formatMessage = self.formatMessageColor

def formatMessageColor(self, record):
def formatMessageColor(self, record: LogRecord) -> str:
message = self.__formatMessage(record)
color = self.COLORS.get(record.levelno)
if color:
Expand All @@ -43,8 +43,7 @@ def formatMessageColor(self, record):

class CustomFormatter(UnixColorFormatter):
"""Adds levelname prefixes to the message on warning or above."""

def formatMessage(self, record):
def formatMessage(self, record: LogRecord) -> str:
message = super().formatMessage(record)
if record.levelno >= logging.WARNING:
message = ': '.join((record.levelname, message))
Expand All @@ -53,10 +52,10 @@ def formatMessage(self, record):

#####################################
# DEFINE THE LOGGER
if conf.LOGGER_PATH is None:
logger_path = Path.cwd()
else:
if conf.LOGGER_PATH is not None:
logger_path = conf.LOGGER_PATH
else:
logger_path = Path.cwd()

logger = logging.getLogger('RAiDER')
logger.setLevel(logging.DEBUG)
Expand Down

0 comments on commit e0fa378

Please sign in to comment.