Skip to content

Commit

Permalink
Rename logger
Browse files Browse the repository at this point in the history
  • Loading branch information
le717 committed Jun 8, 2024
1 parent 8c5ca1a commit eba0523
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
6 changes: 4 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ _Released TDB_
- Update minimum Python version to 3.11
- Update to Flask v3
- ~~Update SQLAlchemy to v2~~ _update pending_
- Replace `requests` with `python-httpx`
- Update Docker image to `python:3.11-slim`
- Update all dependencies to their latest versions
- Switch to ruff for linting and formatting
- Replace `requests` with `python-httpx`
- Switch to [ruff](https://docs.astral.sh/ruff/) for linting and formatting
- Various internal tweaks and adjustments

# 1.2.0

Expand Down
4 changes: 2 additions & 2 deletions src/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def create_app() -> Flask:

# Enable Discord webhook event logging, falling back to a text log
if sys_vars.get_bool("ENABLE_DISCORD_LOGGING"):
logger.LINKROT.addHandler(logger.DiscordHandler())
logger.logger.addHandler(logger.DiscordHandler())
else:
logger.LINKROT.addHandler(logger.file_handler("error-linkrot.log", linkrot=True))
logger.logger.addHandler(logger.file_handler("error-linkrot.log", linkrot=True))

# Register the API endpoints
api = Api(app)
Expand Down
12 changes: 6 additions & 6 deletions src/core/database/linkrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from src.core.database import weblink
from src.core.database.schema import RottedLinks, WebLink, db
from src.core.logger import LINKROT
from src.core.logger import logger

__all__ = ["check_all", "check_one", "delete"]

Expand Down Expand Up @@ -90,7 +90,7 @@ def check_one(uuid: str) -> RotResult:

# A rotten link has been revived
if delete(uuid):
LINKROT.info({
logger.info({
"id": link.id,
"url": link.url,
"message": "Link has been marked to not be dead or a Web Archive reference.",
Expand All @@ -115,7 +115,7 @@ def __record_failure(data: WebLink) -> Check:
existing = __get(data.id)
if existing is None:
__create(data)
LINKROT.error({
logger.error({
"id": data.id,
"url": data.url,
"message": "Linkrot check failure #1.",
Expand All @@ -126,7 +126,7 @@ def __record_failure(data: WebLink) -> Check:
# We have an existing failure record, update the failure count
if (existing.times_failed + 1) < TIMES_FAILED_THRESHOLD:
__update(existing)
LINKROT.error({
logger.error({
"id": data.id,
"url": data.url,
"message": f"Linkrot check failure #{existing.times_failed}.",
Expand All @@ -141,7 +141,7 @@ def __record_failure(data: WebLink) -> Check:
revised_info["url"] = wb_url
revised_info["is_web_archive"] = 1
result["is_web_archive"] = True
LINKROT.critical({
logger.critical({
"id": data.id,
"url": data.url,
"message": "Link has been updated to indicate a Web Archive reference.",
Expand All @@ -151,7 +151,7 @@ def __record_failure(data: WebLink) -> Check:
else:
revised_info["is_dead"] = 1
result["is_dead"] = True
LINKROT.critical({
logger.critical({
"id": data.id,
"url": data.url,
"message": "Link has been marked as a dead link.",
Expand Down
11 changes: 5 additions & 6 deletions src/core/database/weblink.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from datetime import datetime, timezone
import uuid
from datetime import datetime, timezone
from typing import Any, Optional, OrderedDict

from markupsafe import Markup

from src.core.logger import LINKROT
from src.core.database.schema import WebLink, db

from src.core.logger import logger

__all__ = ["create", "delete", "exists", "get", "get_all", "update"]

Expand All @@ -24,7 +23,7 @@ def create(data: OrderedDict) -> dict:
db.session.add(weblink)
db.session.commit()
db.session.refresh(weblink)
LINKROT.info({
logger.info({
"id": entry_id,
"url": weblink.url,
"message": "Link has been added to the webring.",
Expand All @@ -39,7 +38,7 @@ def delete(uuid: str) -> bool:

db.session.delete(get(uuid))
db.session.commit()
LINKROT.info({
logger.info({
"id": uuid,
"url": "N/A",
"message": "Link has been deleted from the webring.",
Expand Down Expand Up @@ -89,7 +88,7 @@ def update(data: OrderedDict) -> bool:
synchronize_session="fetch",
)
db.session.commit()
LINKROT.info({
logger.info({
"id": data["id"],
"url": "N/A",
"message": f"Link has been updated with the following info: `{data}`",
Expand Down
6 changes: 3 additions & 3 deletions src/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import sys_vars
from flask import request

__all__ = ["LINKROT", "DiscordHandler", "file_handler"]
__all__ = ["logger", "DiscordHandler", "file_handler"]


LINKROT = logging.getLogger("linkrot-status")
LINKROT.setLevel(logging.DEBUG)
logger = logging.getLogger("linkrot-status")
logger.setLevel(logging.DEBUG)


def _linkrot_formatter(record: logging.LogRecord) -> str:
Expand Down

0 comments on commit eba0523

Please sign in to comment.