diff options
author | Lucas Daniel Velazquez M <19197331+Luxter77@users.noreply.github.com> | 2023-11-16 19:43:59 +0000 |
---|---|---|
committer | Your Name <you@example.com> | 2023-11-16 19:49:59 +0000 |
commit | cdb60a690dcd35e865eb0caef6c6d8ff64e1b0d5 (patch) | |
tree | dc639dc4fa6a122a4ac13772927e450006ea5f3e /modules | |
parent | 236eb82c3a91960ba5db7b82efbe0f6a9fd7cf24 (diff) | |
download | stable-diffusion-webui-gfx803-cdb60a690dcd35e865eb0caef6c6d8ff64e1b0d5.tar.gz stable-diffusion-webui-gfx803-cdb60a690dcd35e865eb0caef6c6d8ff64e1b0d5.tar.bz2 stable-diffusion-webui-gfx803-cdb60a690dcd35e865eb0caef6c6d8ff64e1b0d5.zip |
Take into account tqdm not being installed before first boot for logging
Diffstat (limited to 'modules')
-rw-r--r-- | modules/logging_config.py | 37 |
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=[]
)
-
|