Skip to content

Commit

Permalink
✨ Logging: Added file support (Fixes #182)
Browse files Browse the repository at this point in the history
- Added `VIDGEAR_LOGFILE` environment variable to manually add file/dir path.
- Reworked `logger_handler()` Helper methods (in asyncio too).
- Added new formatter and Filehandler for handling logger files.
- Added auto version extraction from package `version.py` in setup.py.
  • Loading branch information
abhiTronix committed Dec 21, 2020
1 parent d0dfd90 commit 4a80ae0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import setuptools

from pkg_resources import parse_version
from distutils.util import convert_path
from setuptools import setup


Expand All @@ -47,6 +48,11 @@ def test_opencv():
return False


pkg_version = {}
ver_path = convert_path("vidgear/version.py")
with open(ver_path) as ver_file:
exec(ver_file.read(), pkg_version)

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
long_description = long_description.replace( # patch for images
Expand All @@ -59,7 +65,7 @@ def test_opencv():
setup(
name="vidgear",
packages=["vidgear", "vidgear.gears", "vidgear.gears.asyncio"],
version="0.2.0-dev3",
version=pkg_version["__version__"],
description="High-performance cross-platform Video Processing Python framework powerpacked with unique trailblazing features.",
license="Apache License 2.0",
author="Abhishek Thakur",
Expand Down
15 changes: 15 additions & 0 deletions vidgear/gears/asyncio/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,23 @@ def logger_handler():
"CRITICAL": "bold_red,bg_white",
},
)
# check if VIDGEAR_LOGFILE defined
file_mode = os.environ.get("VIDGEAR_LOGFILE", False)
# define handler
handler = log.StreamHandler()
if file_mode and isinstance(file_mode, str):
file_path = os.path.abspath(file_mode)
if (os.name == "nt" or os.access in os.supports_effective_ids) and os.access(
os.path.dirname(file_path), os.W_OK
):
file_path = (
os.path.join(file_path, "log.txt")
if os.path.isdir(file_path)
else file_path
)
handler = log.FileHandler(file_path, mode="a")
formatter = log.Formatter("%(name)s :: %(levelname)s :: %(message)s")

handler.setFormatter(formatter)
return handler

Expand Down
15 changes: 15 additions & 0 deletions vidgear/gears/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,23 @@ def logger_handler():
"CRITICAL": "bold_red,bg_white",
},
)
# check if VIDGEAR_LOGFILE defined
file_mode = os.environ.get("VIDGEAR_LOGFILE", False)
# define handler
handler = log.StreamHandler()
if file_mode and isinstance(file_mode, str):
file_path = os.path.abspath(file_mode)
if (os.name == "nt" or os.access in os.supports_effective_ids) and os.access(
os.path.dirname(file_path), os.W_OK
):
file_path = (
os.path.join(file_path, "log.txt")
if os.path.isdir(file_path)
else file_path
)
handler = log.FileHandler(file_path, mode="a")
formatter = log.Formatter("%(name)s :: %(levelname)s :: %(message)s")

handler.setFormatter(formatter)
return handler

Expand Down
2 changes: 1 addition & 1 deletion vidgear/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.0-dev3"
__version__ = "0.2.0-dev5"

0 comments on commit 4a80ae0

Please sign in to comment.