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

NextcloudApp: setup_nextcloud_logging function for transparent logging #294

Merged
merged 4 commits into from
Sep 5, 2024

Conversation

bigcat88
Copy link
Contributor

@bigcat88 bigcat88 commented Sep 5, 2024

Usage:

import logging
from pathlib import Path
from os import environ

import nc_py_api


environ["APP_ID"] = "nc_py_api"
environ["APP_VERSION"] = "1.0.0"
environ["APP_SECRET"] = "12345"
environ["NEXTCLOUD_URL"] = "http://nextcloud.local"


if __name__ == "__main__":
    nc_app = nc_py_api.NextcloudApp()
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s: [%(funcName)s]:%(levelname)s: %(message)s",
        datefmt="%H:%M:%S",
    )
    logging.getLogger("httpx").setLevel(logging.ERROR)  # not needed, but better to hide spam to console
    nc_py_api.ex_app.setup_nextcloud_logging() # setup logging handler in one line of code
    logging.fatal("Fatal test")
    logging.error("Error test")
    logging.warning("Warning test")
    logging.info("Info test")
    logging.debug("Debug test")
    logging.fatal("Fatal test2")
    try:
        a = 0
        b = z
    except Exception as e:
        logging.exception("Exception test")

setup_nextcloud_logging

def setup_nextcloud_logging(logger_name: str | None = None, logging_level: int = logging.DEBUG):
     """Function to easily send all or selected log entries to Nextcloud."""
     logger = logging.getLogger(logger_name)
     nextcloud_handler = _NextcloudStorageHandler()
     nextcloud_handler.setLevel(logging_level)
     logger.addHandler(nextcloud_handler)
     return nextcloud_handler

…logging

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 94.87179% with 2 lines in your changes missing coverage. Please review.

Project coverage is 94.81%. Comparing base (1471e90) to head (7cb959b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
nc_py_api/ex_app/logging.py 92.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #294      +/-   ##
==========================================
- Coverage   94.82%   94.81%   -0.01%     
==========================================
  Files          45       46       +1     
  Lines        5312     5341      +29     
==========================================
+ Hits         5037     5064      +27     
- Misses        275      277       +2     
Files with missing lines Coverage Δ
nc_py_api/ex_app/__init__.py 100.00% <100.00%> (ø)
nc_py_api/nextcloud.py 96.34% <100.00%> (+0.02%) ⬆️
nc_py_api/ex_app/logging.py 92.30% <92.30%> (ø)

bigcat88 and others added 3 commits September 5, 2024 18:59
…thon 3.13+)

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
@bigcat88 bigcat88 merged commit 2924701 into main Sep 5, 2024
18 checks passed
@bigcat88 bigcat88 deleted the feat/exapp-logging branch September 5, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant