mirror of
https://github.com/karma-riuk/crab.git
synced 2025-07-04 13:18:13 +02:00
made more general function to move logging to file
This commit is contained in:
@ -26,10 +26,11 @@ from errors import (
|
||||
MultipleFilesError,
|
||||
NoDiffsAfterError,
|
||||
NoDiffsBeforeError,
|
||||
NoLinesForCommentError,
|
||||
SetupException,
|
||||
)
|
||||
from handlers import HandlerException, get_build_handler
|
||||
from utils import has_only_1_comment, move_github_logging_to_file, clone, run_git_cmd
|
||||
from utils import has_only_1_comment, move_logger_to_file, clone, run_git_cmd
|
||||
|
||||
EXCLUSION_LIST = [
|
||||
"edmcouncil/idmp", # requires authentication
|
||||
@ -647,6 +648,7 @@ if __name__ == "__main__":
|
||||
import requests_cache
|
||||
|
||||
requests_cache.install_cache('github_cache', expire_after=requests_cache.NEVER_EXPIRE)
|
||||
move_logger_to_file("requests_cache", "requests_cache.log")
|
||||
|
||||
github_api_token = os.environ.get("GITHUB_AUTH_TOKEN_CRAB")
|
||||
if github_api_token is None:
|
||||
@ -656,7 +658,7 @@ if __name__ == "__main__":
|
||||
g = Github(github_api_token, seconds_between_requests=0)
|
||||
|
||||
docker_client = docker.from_env()
|
||||
move_github_logging_to_file()
|
||||
move_logger_to_file("github", "github_api.log")
|
||||
|
||||
# df = get_good_projects(args.csv_file)
|
||||
df = pd.read_csv(args.csv_file)
|
||||
|
6
utils.py
6
utils.py
@ -10,14 +10,14 @@ from tqdm import tqdm
|
||||
from errors import CantCloneRepoError
|
||||
|
||||
|
||||
def move_github_logging_to_file():
|
||||
github_logger = logging.getLogger("github")
|
||||
def move_logger_to_file(logger_name, filename):
|
||||
github_logger = logging.getLogger(logger_name)
|
||||
|
||||
# Remove existing handlers to prevent duplicate logging
|
||||
for handler in github_logger.handlers[:]:
|
||||
github_logger.removeHandler(handler)
|
||||
|
||||
file_handler = logging.FileHandler("github_api.log") # Log to file
|
||||
file_handler = logging.FileHandler(filename) # Log to file
|
||||
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
|
||||
file_handler.setFormatter(formatter)
|
||||
github_logger.addHandler(file_handler)
|
||||
|
Reference in New Issue
Block a user