-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6694213
commit db65b85
Showing
7 changed files
with
67 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
import time | ||
import requests | ||
|
||
|
||
from ..qqGuild.api import QQGuildAPI, log | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import sys | ||
import logging | ||
|
||
from typing import Optional | ||
from concurrent_log_handler import ConcurrentRotatingFileHandler | ||
from amiyabot.util import argv | ||
|
||
|
||
LOG_FILE_SAVE_PATH = argv('log-file-save-path', str) or './log' | ||
LOG_FILE_MAX_BYTES = argv('log-file-max-bytes', int) or (512 * 1024) | ||
LOG_FILE_BACKUP_COUNT = argv('log-file-backup-count', int) or 10 | ||
|
||
|
||
class LogHandlers: | ||
debug_mode = argv('debug', bool) | ||
level = logging.DEBUG if debug_mode else logging.INFO | ||
formatter = logging.Formatter(f'%(asctime)s [%(name)9s][%(levelname)9s]%(message)s') | ||
stream_handler: Optional[logging.StreamHandler] = None | ||
|
||
@classmethod | ||
def get_stream_handler(cls): | ||
if not cls.stream_handler: | ||
cls.stream_handler = logging.StreamHandler(stream=sys.stdout) | ||
cls.stream_handler.setFormatter(cls.formatter) | ||
cls.stream_handler.setLevel(cls.level) | ||
|
||
return cls.stream_handler | ||
|
||
@classmethod | ||
def get_file_handler(cls, save_path: str, save_filename: str): | ||
file_handler = ConcurrentRotatingFileHandler( | ||
filename=os.path.join(save_path, f'{save_filename}.log'), | ||
encoding='utf-8', | ||
maxBytes=LOG_FILE_MAX_BYTES, | ||
backupCount=LOG_FILE_BACKUP_COUNT, | ||
) | ||
file_handler.setFormatter(cls.formatter) | ||
file_handler.setLevel(cls.level) | ||
|
||
return file_handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ setuptools~=60.2.0 | |
starlette~=0.19.1 | ||
uvicorn~=0.18.2 | ||
websockets~=10.1 | ||
zhon~=1.1.5 | ||
zhon~=1.1.5 |