From ca7b267326ec346f5d8bebe7b158ed351c1e5250 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Thu, 25 May 2023 10:10:46 -0400 Subject: [PATCH] raise error if syslogging requested and syslog lib not available --- invokeai/backend/util/logging.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/invokeai/backend/util/logging.py b/invokeai/backend/util/logging.py index 445fef24df..16efd56c03 100644 --- a/invokeai/backend/util/logging.py +++ b/invokeai/backend/util/logging.py @@ -33,8 +33,6 @@ IAILogger.debug('this is a debugging message') import logging import logging.handlers import socket -import syslog -import sys import urllib.parse from abc import abstractmethod @@ -42,6 +40,12 @@ from pathlib import Path from invokeai.app.services.config import InvokeAIAppConfig, get_invokeai_config +try: + import syslog + SYSLOG_AVAILABLE = True +except: + SYSLOG_AVAILABLE = False + # module level functions def debug(msg, *args, **kwargs): InvokeAILogger.getLogger().debug(msg, *args, **kwargs) @@ -90,7 +94,7 @@ _FACILITY_MAP = dict( LOG_LOCAL5 = syslog.LOG_LOCAL5, LOG_LOCAL6 = syslog.LOG_LOCAL6, LOG_LOCAL7 = syslog.LOG_LOCAL7, -) +) if SYSLOG_AVAILABLE else dict() _SOCK_MAP = dict( SOCK_STREAM = socket.SOCK_STREAM, @@ -220,6 +224,8 @@ class InvokeAILogger(object): def _parse_syslog_args( args: str=None )-> logging.Handler: + if not SYSLOG_AVAILABLE: + raise ValueError("syslog is not available on this system") if not args: args='/dev/log' if Path('/dev/log').exists() else 'address:localhost:514' syslog_args = dict()