Skip to content

Commit 9c91357

Browse files
committed
additionally log to file
1 parent 33d0ecc commit 9c91357

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

scripts/spartan/World.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
import time
1212
from typing import List, Dict, Union
1313
from threading import Thread
14-
from inspect import getsourcefile
15-
from os.path import abspath
16-
from pathlib import Path
1714
from modules.processing import process_images, StableDiffusionProcessingTxt2Img
1815
import modules.shared as shared
1916
from .Worker import Worker, State
20-
from .shared import logger, warmup_samples
17+
from .shared import logger, warmup_samples, extension_path
2118
from .pmodels import Config_Model, Benchmark_Payload
2219
from . import shared as sh
2320

@@ -70,7 +67,6 @@ class World:
7067
"""
7168

7269
# I'd rather keep the sdwui root directory clean.
73-
extension_path = Path(abspath(getsourcefile(lambda: 0))).parent.parent.parent
7470
config_path = shared.cmd_opts.distributed_config
7571
old_config_path = worker_info_path = extension_path.joinpath('workers.json')
7672

scripts/spartan/shared.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
import logging
2+
from inspect import getsourcefile
23
from typing import Union
34
from rich.logging import RichHandler
45
from modules.shared import cmd_opts
56
from pydantic import BaseModel, Field
7+
from os.path import abspath
8+
9+
from pathlib import Path
10+
extension_path = Path(abspath(getsourcefile(lambda: 0))).parent.parent.parent
611

712
# https://rich.readthedocs.io/en/stable/logging.html
813
log_level = 'DEBUG' if cmd_opts.distributed_debug else 'INFO'
914
logger = logging.getLogger("distributed")
10-
handler = RichHandler(
15+
rich_handler = RichHandler(
1116
rich_tracebacks=True,
1217
markup=True,
1318
show_time=False,
1419
keywords=["distributed", "Distributed", "worker", "Worker", "world", "World"]
1520
)
16-
logger.addHandler(handler)
17-
logger.setLevel(log_level)
1821
logger.propagate = False # prevent log duplication by webui since it now uses the logging module
22+
logger.setLevel(log_level)
23+
log_path = extension_path.joinpath('distributed.log')
24+
file_handler = logging.FileHandler(log_path)
25+
file_handler.formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
26+
logger.addHandler(rich_handler)
27+
logger.addHandler(file_handler)
28+
# end logging
1929

2030
warmup_samples = 2 # number of samples to do before recording a valid benchmark sample
2131

0 commit comments

Comments
 (0)