Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: naming style #132

Merged
merged 1 commit into from
Jul 3, 2023
Merged
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
24 changes: 12 additions & 12 deletions aiotieba/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, name: str = '', stream_log_level: int = logging.DEBUG) -> Non
self.addHandler(stream_hd)


_LOGGER = TiebaLogger()
LOGGER = TiebaLogger()


def get_logger() -> TiebaLogger:
Expand All @@ -45,12 +45,12 @@ def get_logger() -> TiebaLogger:
TiebaLogger
"""

global _LOGGER
global LOGGER

if _LOGGER is None:
_LOGGER = TiebaLogger()
if LOGGER is None:
LOGGER = TiebaLogger()

return _LOGGER
return LOGGER


def set_logger(new_logger: logging.Logger) -> None:
Expand All @@ -61,8 +61,8 @@ def set_logger(new_logger: logging.Logger) -> None:
new_logger (logging.Logger): 新日志记录器
"""

global _LOGGER
_LOGGER = new_logger
global LOGGER
LOGGER = new_logger


def set_formatter(formatter: logging.Formatter) -> None:
Expand All @@ -76,12 +76,12 @@ def set_formatter(formatter: logging.Formatter) -> None:
global _FORMATTER
_FORMATTER = formatter

if _LOGGER is not None:
for hd in _LOGGER.handlers:
if LOGGER is not None:
for hd in LOGGER.handlers:
hd.setFormatter(formatter)


def enableFileLog(log_level: int = logging.INFO, log_dir: Path = Path('log'), backup_count: int = 5) -> None:
def enable_filelog(log_level: int = logging.INFO, log_dir: Path = Path('log'), backup_count: int = 5) -> None:
"""
启用文件日志

Expand All @@ -94,8 +94,8 @@ def enableFileLog(log_level: int = logging.INFO, log_dir: Path = Path('log'), ba
Path(log_dir).mkdir(0o755, exist_ok=True)

file_hd = logging.handlers.TimedRotatingFileHandler(
f"log/{_LOGGER.name}.log", when='MIDNIGHT', backupCount=backup_count, encoding='utf-8'
f"log/{LOGGER.name}.log", when='MIDNIGHT', backupCount=backup_count, encoding='utf-8'
)
file_hd.setLevel(log_level)
file_hd.setFormatter(_FORMATTER)
_LOGGER.addHandler(file_hd)
LOGGER.addHandler(file_hd)