aboutsummaryrefslogtreecommitdiff
path: root/modules/logging_config.py
diff options
context:
space:
mode:
authorLucas Daniel Velazquez M <19197331+Luxter77@users.noreply.github.com>2023-11-16 16:43:59 -0300
committerYour Name <you@example.com>2023-11-16 16:49:59 -0300
commitcdb60a690dcd35e865eb0caef6c6d8ff64e1b0d5 (patch)
treedc639dc4fa6a122a4ac13772927e450006ea5f3e /modules/logging_config.py
parent236eb82c3a91960ba5db7b82efbe0f6a9fd7cf24 (diff)
Take into account tqdm not being installed before first boot for logging
Diffstat (limited to 'modules/logging_config.py')
-rw-r--r--modules/logging_config.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/modules/logging_config.py b/modules/logging_config.py
index ce831b5c..99ed2855 100644
--- a/modules/logging_config.py
+++ b/modules/logging_config.py
@@ -1,30 +1,41 @@
import os
import logging
-from tqdm.auto import tqdm
+try:
+ from tqdm.auto import tqdm
-class TqdmLoggingHandler(logging.Handler):
- def __init__(self, level=logging.INFO):
- super().__init__(level)
+ class TqdmLoggingHandler(logging.Handler):
+ def __init__(self, level=logging.INFO):
+ super().__init__(level)
- def emit(self, record):
- try:
- msg = self.format(record)
- tqdm.write(msg)
- self.flush()
- except Exception:
- self.handleError(record)
+ def emit(self, record):
+ try:
+ msg = self.format(record)
+ tqdm.write(msg)
+ self.flush()
+ except Exception:
+ self.handleError(record)
+
+ TQDM_IMPORTED = True
+except ImportError:
+ # tqdm does not exist before first launch
+ # I will import once the UI finishes seting up the enviroment and reloads.
+ TQDM_IMPORTED = False
def setup_logging(loglevel):
if loglevel is None:
loglevel = os.environ.get("SD_WEBUI_LOG_LEVEL")
+ loghandlers = []
+
+ if TQDM_IMPORTED:
+ loghandlers.append(TqdmLoggingHandler())
+
if loglevel:
log_level = getattr(logging, loglevel.upper(), None) or logging.INFO
logging.basicConfig(
level=log_level,
format='%(asctime)s %(levelname)s [%(name)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
- handlers=[TqdmLoggingHandler()]
+ handlers=[]
)
-