Skip to content

Commit

Permalink
Use a Python logger in exception_logger.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Miroshnychenko committed Apr 7, 2024
1 parent 560d335 commit e06fae1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
4 changes: 1 addition & 3 deletions plugin.video.external.library/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
import sys

import xbmc
Expand All @@ -24,7 +23,6 @@
from libs.kodi_service import GettextEmulator, initialize_logging

initialize_logging()
logger = logging.getLogger(__name__)
_ = GettextEmulator.gettext


Expand All @@ -39,5 +37,5 @@ def main():


if __name__ == '__main__':
with catch_exception(logger.error):
with catch_exception():
main()
7 changes: 3 additions & 4 deletions plugin.video.external.library/libs/exception_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Exception logger with extended diagnostic info"""

import inspect
import logging
import sys
from contextlib import contextmanager
from platform import uname
Expand All @@ -23,9 +24,7 @@

import xbmc


def _log_error(message: str) -> None:
xbmc.log(message, level=xbmc.LOGERROR)
logger = logging.getLogger(__name__)


def _format_vars(variables: Dict[str, Any]) -> str:
Expand Down Expand Up @@ -156,7 +155,7 @@ def format_exception(exc_obj: Optional[Exception] = None) -> str:


@contextmanager
def catch_exception(logger_func: Callable[[str], None] = _log_error) -> Generator[None, None, None]:
def catch_exception(logger_func: Callable[[str], None] = logger.error) -> Generator[None, None, None]:
"""
Diagnostic helper context manager
Expand Down
4 changes: 1 addition & 3 deletions plugin.video.external.library/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import sys
import logging

from libs.actions import router
from libs.exception_logger import catch_exception
from libs.kodi_service import initialize_logging

initialize_logging()
logger = logging.getLogger(__name__)

if __name__ == '__main__':
with catch_exception(logger.error):
with catch_exception():
router(sys.argv[2][1:])
2 changes: 1 addition & 1 deletion plugin.video.external.library/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
initialize_logging()
logger = logging.getLogger(__name__)

with catch_exception(logger.error):
with catch_exception():
logger.debug('Starting playback monitoring service...')
kodi_monitor = xbmc.Monitor()
play_monitor = PlayMonitor()
Expand Down

0 comments on commit e06fae1

Please sign in to comment.