raise error if syslogging requested and syslog lib not available

This commit is contained in:
Lincoln Stein 2023-05-25 10:10:46 -04:00
parent 7f5992d6a5
commit ca7b267326

View File

@ -33,8 +33,6 @@ IAILogger.debug('this is a debugging message')
import logging import logging
import logging.handlers import logging.handlers
import socket import socket
import syslog
import sys
import urllib.parse import urllib.parse
from abc import abstractmethod from abc import abstractmethod
@ -42,6 +40,12 @@ from pathlib import Path
from invokeai.app.services.config import InvokeAIAppConfig, get_invokeai_config from invokeai.app.services.config import InvokeAIAppConfig, get_invokeai_config
try:
import syslog
SYSLOG_AVAILABLE = True
except:
SYSLOG_AVAILABLE = False
# module level functions # module level functions
def debug(msg, *args, **kwargs): def debug(msg, *args, **kwargs):
InvokeAILogger.getLogger().debug(msg, *args, **kwargs) InvokeAILogger.getLogger().debug(msg, *args, **kwargs)
@ -90,7 +94,7 @@ _FACILITY_MAP = dict(
LOG_LOCAL5 = syslog.LOG_LOCAL5, LOG_LOCAL5 = syslog.LOG_LOCAL5,
LOG_LOCAL6 = syslog.LOG_LOCAL6, LOG_LOCAL6 = syslog.LOG_LOCAL6,
LOG_LOCAL7 = syslog.LOG_LOCAL7, LOG_LOCAL7 = syslog.LOG_LOCAL7,
) ) if SYSLOG_AVAILABLE else dict()
_SOCK_MAP = dict( _SOCK_MAP = dict(
SOCK_STREAM = socket.SOCK_STREAM, SOCK_STREAM = socket.SOCK_STREAM,
@ -220,6 +224,8 @@ class InvokeAILogger(object):
def _parse_syslog_args( def _parse_syslog_args(
args: str=None args: str=None
)-> logging.Handler: )-> logging.Handler:
if not SYSLOG_AVAILABLE:
raise ValueError("syslog is not available on this system")
if not args: if not args:
args='/dev/log' if Path('/dev/log').exists() else 'address:localhost:514' args='/dev/log' if Path('/dev/log').exists() else 'address:localhost:514'
syslog_args = dict() syslog_args = dict()