Skip to content

Commit

Permalink
Add log wrapper + move some logs to debug (#139)
Browse files Browse the repository at this point in the history
* Add log wrapper

* Update to use log wrapper; move some logs to debug

* you get debugged
  • Loading branch information
Caedis authored Mar 3, 2024
1 parent 080aeba commit 4d02095
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 55 deletions.
3 changes: 1 addition & 2 deletions src/gtnh/assembler/assembler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from pathlib import Path
from typing import Awaitable, Callable, Dict, List, Optional

from structlog import get_logger

from gtnh.assembler.curse import CurseAssembler
from gtnh.assembler.modrinth import ModrinthAssembler
from gtnh.assembler.multi_poly import MMCAssembler
from gtnh.assembler.technic import TechnicAssembler
from gtnh.assembler.zip_assembler import ZipAssembler
from gtnh.defs import RELEASE_CHANGELOG_DIR, Archive, Side
from gtnh.gtnh_logger import get_logger
from gtnh.models.gtnh_release import GTNHRelease
from gtnh.modpack_manager import GTNHModpackManager
from gtnh.utils import compress_changelog
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/assembler/curse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import httpx
from colorama import Fore
from structlog import get_logger

from gtnh.assembler.downloader import get_asset_version_cache_location
from gtnh.assembler.generic_assembler import GenericAssembler
from gtnh.defs import CACHE_DIR, RELEASE_CURSE_DIR, ROOT_DIR, ModSource, Side
from gtnh.gtnh_logger import get_logger
from gtnh.models.gtnh_config import GTNHConfig
from gtnh.models.gtnh_release import GTNHRelease
from gtnh.models.gtnh_version import GTNHVersion
Expand Down
3 changes: 1 addition & 2 deletions src/gtnh/assembler/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import re
from pathlib import Path

from structlog import get_logger

from gtnh.defs import CACHE_DIR
from gtnh.gtnh_logger import get_logger
from gtnh.models.gtnh_version import ExtraAsset, GTNHVersion
from gtnh.models.versionable import Versionable

Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/assembler/generic_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from zipfile import ZIP_DEFLATED, ZipFile

from colorama import Fore
from structlog import get_logger

from gtnh.assembler.downloader import get_asset_version_cache_location
from gtnh.assembler.exclusions import Exclusions
from gtnh.defs import README_TEMPLATE, RELEASE_README_DIR, ModSource, Side
from gtnh.gtnh_logger import get_logger
from gtnh.models.gtnh_config import GTNHConfig
from gtnh.models.gtnh_release import GTNHRelease
from gtnh.models.gtnh_version import GTNHVersion
Expand Down
5 changes: 2 additions & 3 deletions src/gtnh/assembler/technic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import re
import shutil
from pathlib import Path
Expand All @@ -8,14 +7,14 @@
from gtnh.assembler.downloader import get_asset_version_cache_location
from gtnh.assembler.generic_assembler import GenericAssembler
from gtnh.defs import RELEASE_TECHNIC_DIR, Side
from gtnh.gtnh_logger import get_logger
from gtnh.models.gtnh_config import GTNHConfig
from gtnh.models.gtnh_release import GTNHRelease
from gtnh.models.gtnh_version import GTNHVersion
from gtnh.models.mod_info import GTNHModInfo
from gtnh.modpack_manager import GTNHModpackManager

log = logging.getLogger("technic process")
log.setLevel(logging.INFO)
log = get_logger("technic process")


def technify(string: str) -> str:
Expand Down
3 changes: 1 addition & 2 deletions src/gtnh/assembler/zip_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from typing import Callable, List, Optional, Tuple
from zipfile import ZIP_DEFLATED, ZipFile

from structlog import get_logger

from gtnh.assembler.downloader import get_asset_version_cache_location
from gtnh.assembler.generic_assembler import GenericAssembler
from gtnh.defs import RELEASE_ZIP_DIR, SERVER_ASSETS_DIR, ServerBrand, Side
from gtnh.gtnh_logger import get_logger
from gtnh.models.gtnh_config import GTNHConfig
from gtnh.models.gtnh_release import GTNHRelease
from gtnh.models.gtnh_version import GTNHVersion
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/add_mod.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncclick as click
import httpx
from structlog import get_logger

from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/assemble_nightly.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncclick as click
from colorama import Fore
from httpx import AsyncClient
from structlog import get_logger

from gtnh.assembler.assembler import ReleaseAssembler
from gtnh.defs import Side
from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/assemble_release.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncclick as click
from colorama import Fore
from httpx import AsyncClient
from structlog import get_logger

from gtnh.assembler.assembler import ReleaseAssembler
from gtnh.defs import Side
from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
8 changes: 4 additions & 4 deletions src/gtnh/cli/close_old_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import httpx
from dateutil.parser import parse as parse_date
from gidgethub.httpx import GitHubAPI
from structlog import get_logger

from gtnh.github.uri import API_BASE_URI, repo_issues_uri
from gtnh.gtnh_logger import get_logger
from gtnh.utils import AttributeDict, get_github_token

log = get_logger(__name__)
Expand All @@ -17,7 +17,7 @@
async def close_old_issues() -> None:
async with httpx.AsyncClient(http2=True) as client:
gh = GitHubAPI(client, "DreamAssemblerXXL", oauth_token=get_github_token())
log.info("Closing older issues")
log.debug("Closing older issues")
org = "GTNewHorizons"
repo = "GT-New-Horizons-Modpack"
issues = gh.getiter(repo_issues_uri(org, repo))
Expand All @@ -44,7 +44,7 @@ async def close_old_issues() -> None:
async def get_issue(num: int) -> AttributeDict:
async with httpx.AsyncClient(http2=True) as client:
gh = GitHubAPI(client, "DreamAssemblerXXL", oauth_token=get_github_token())
log.info(f"Getting issue {num}")
log.debug(f"Getting issue {num}")
return AttributeDict(
await gh.getitem(f"{API_BASE_URI}/repos/GTNewHorizons/GT-New-Horizons-Modpack/issues/{num}")
)
Expand All @@ -55,7 +55,7 @@ def display(issue: AttributeDict) -> str:


def log_reason(issue: AttributeDict, should_close: bool, reason: str) -> None:
log.info(f""" {"Will" if should_close else "Won't"} close issue {display(issue)} - {reason}""")
log.debug(f""" {"Will" if should_close else "Won't"} close issue {display(issue)} - {reason}""")


def should_close_issue(issue: AttributeDict) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/download_mod.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncclick as click
import httpx
from colorama import Fore
from structlog import get_logger

from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/download_release.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncclick as click
import httpx
from colorama import Fore
from structlog import get_logger

from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/generate_changelog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
from httpx import AsyncClient
from structlog import get_logger

from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/generate_nightly.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncclick as click
import httpx
from structlog import get_logger

from gtnh.exceptions import ReleaseNotFoundException
from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/generate_old_changelogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import gidgethub
import httpx
from gidgethub.httpx import GitHubAPI
from structlog import get_logger

from gtnh.defs import ModSource
from gtnh.github.uri import repo_releases_uri
from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager
from gtnh.utils import get_github_token

Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/remove_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import asyncclick as click
import httpx
from colorama import init
from structlog import get_logger

from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/update_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import asyncclick as click
import httpx
from colorama import Fore, Style, init
from structlog import get_logger

from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down
8 changes: 4 additions & 4 deletions src/gtnh/cli/update_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import asyncclick as click
import httpx
from in_place import InPlace
from structlog import get_logger

from gtnh.defs import ModSource
from gtnh.gtnh_logger import get_logger
from gtnh.modpack_manager import GTNHModpackManager

log = get_logger(__name__)
Expand Down Expand Up @@ -66,9 +66,9 @@ async def find_and_update_deps() -> None:
fp.write(line)
continue
else:
log.info(f"{mod_name} is already at the latest version '{latest_version}'")
log.debug(f"{mod_name} is already at the latest version '{latest_version}'")
else:
log.info(f"No latest version info for mod {mod_name}")
log.warn(f"No latest version info for mod {mod_name}")

# No match
fp.write(line)
Expand All @@ -82,7 +82,7 @@ def verify_gtnh_maven() -> None:
with open(REPO_FILE) as fp:
repos = fp.read()
if repos.find("http://jenkins.usrv.eu:8081/nexus/content/groups/public/") != -1:
log.info("GTNH Maven already found")
log.debug("GTNH Maven already found")
return

with InPlace(REPO_FILE) as fp:
Expand Down
12 changes: 12 additions & 0 deletions src/gtnh/gtnh_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging
import os
import typing

import structlog


def get_logger(name: str) -> structlog.BoundLogger:
if not structlog.is_configured():
LOG_LEVEL = getattr(logging, os.environ.get("LOG_LEVEL", "INFO").upper())
structlog.configure(wrapper_class=structlog.make_filtering_bound_logger(LOG_LEVEL))
return typing.cast(structlog.BoundLogger, structlog.get_logger(name))
2 changes: 1 addition & 1 deletion src/gtnh/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import httpx
from colorama import Fore
from structlog import get_logger
from ttkthemes import ThemedTk

from gtnh.assembler.assembler import ReleaseAssembler
from gtnh.defs import Archive, ModSource, Position, Side
from gtnh.exceptions import NoModAssetFound, ReleaseNotFoundException
from gtnh.gtnh_logger import get_logger
from gtnh.gui.exclusion.exclusion_panel import ExclusionPanel, ExclusionPanelCallback
from gtnh.gui.external.external_panel import ExternalPanel, ExternalPanelCallback
from gtnh.gui.github.github_panel import GithubPanel, GithubPanelCallback
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/models/available_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import Dict, List

from pydantic import Field
from structlog import get_logger

from gtnh.defs import ModSource, Side
from gtnh.exceptions import NoModAssetFound
from gtnh.gtnh_logger import get_logger
from gtnh.models.base import GTNHBaseModel
from gtnh.models.gtnh_config import GTNHConfig
from gtnh.models.gtnh_version import GTNHVersion
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/models/gtnh_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

from colorama import Fore
from pydantic import Field, ValidationError
from structlog import get_logger

from gtnh.defs import GREEN_CHECK, RED_CROSS, RELEASE_MANIFEST_DIR
from gtnh.gtnh_logger import get_logger
from gtnh.models.available_assets import AvailableAssets
from gtnh.models.base import GTNHBaseModel
from gtnh.models.mod_version_info import ModVersionInfo
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/models/gtnh_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import List, Optional, Tuple

from pydantic import Field
from structlog import get_logger

from gtnh.defs import VersionableType
from gtnh.gtnh_logger import get_logger
from gtnh.models.base import GTNHBaseModel
from gtnh.utils import AttributeDict

Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/models/mod_info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Using LegacyVersion because we want everything to be comparable
from pydantic import Field
from structlog import get_logger

from gtnh.defs import UNKNOWN, ModSource, Side
from gtnh.gtnh_logger import get_logger
from gtnh.models.base import GTNHBaseModel
from gtnh.models.versionable import Versionable

Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/models/versionable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from packaging.version import LegacyVersion
from pydantic import BaseModel, Field
from structlog import get_logger

from gtnh.defs import VersionableType
from gtnh.gtnh_logger import get_logger
from gtnh.models.gtnh_version import GTNHVersion

log = get_logger(__name__)
Expand Down
Loading

0 comments on commit 4d02095

Please sign in to comment.