fix: disable the console log wrapper by default to preview spamming log issues
Running with export CD_ENABLE_LOG=true; python main.py to enable log
This commit is contained in:
parent
a838cb7ad4
commit
f73baa091a
@ -7,45 +7,56 @@ import threading
|
|||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
|
|
||||||
handler = RotatingFileHandler('comfy-deploy.log', maxBytes=500000, backupCount=5)
|
# Running with export CD_ENABLE_LOG=true; python main.py
|
||||||
|
|
||||||
original_stdout = sys.stdout
|
# Check for 'cd-enable-log' flag in input arguments
|
||||||
original_stderr = sys.stderr
|
# cd_enable_log = '--cd-enable-log' in sys.argv
|
||||||
|
cd_enable_log = os.environ.get('CD_ENABLE_LOG', 'false').lower() == 'true'
|
||||||
|
|
||||||
class StreamToLogger():
|
def setup():
|
||||||
def __init__(self, log_level):
|
handler = RotatingFileHandler('comfy-deploy.log', maxBytes=500000, backupCount=5)
|
||||||
self.log_level = log_level
|
|
||||||
|
|
||||||
def write(self, buf):
|
original_stdout = sys.stdout
|
||||||
if (self.log_level == logging.INFO):
|
original_stderr = sys.stderr
|
||||||
original_stdout.write(buf)
|
|
||||||
original_stdout.flush()
|
|
||||||
elif (self.log_level == logging.ERROR):
|
|
||||||
original_stderr.write(buf)
|
|
||||||
original_stderr.flush()
|
|
||||||
|
|
||||||
for line in buf.rstrip().splitlines():
|
class StreamToLogger():
|
||||||
handler.handle(
|
def __init__(self, log_level):
|
||||||
logging.LogRecord(
|
self.log_level = log_level
|
||||||
name="comfy-deploy",
|
|
||||||
level=self.log_level,
|
def write(self, buf):
|
||||||
pathname="prestartup_script.py",
|
if (self.log_level == logging.INFO):
|
||||||
lineno=1,
|
original_stdout.write(buf)
|
||||||
msg=line.rstrip(),
|
original_stdout.flush()
|
||||||
args=None,
|
elif (self.log_level == logging.ERROR):
|
||||||
exc_info=None
|
original_stderr.write(buf)
|
||||||
|
original_stderr.flush()
|
||||||
|
|
||||||
|
for line in buf.rstrip().splitlines():
|
||||||
|
handler.handle(
|
||||||
|
logging.LogRecord(
|
||||||
|
name="comfy-deploy",
|
||||||
|
level=self.log_level,
|
||||||
|
pathname="prestartup_script.py",
|
||||||
|
lineno=1,
|
||||||
|
msg=line.rstrip(),
|
||||||
|
args=None,
|
||||||
|
exc_info=None
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
if (self.log_level == logging.INFO):
|
if (self.log_level == logging.INFO):
|
||||||
original_stdout.flush()
|
original_stdout.flush()
|
||||||
elif (self.log_level == logging.ERROR):
|
elif (self.log_level == logging.ERROR):
|
||||||
original_stderr.flush()
|
original_stderr.flush()
|
||||||
|
|
||||||
# Redirect stdout and stderr to the logger
|
# Redirect stdout and stderr to the logger
|
||||||
sys.stdout = StreamToLogger(logging.INFO)
|
sys.stdout = StreamToLogger(logging.INFO)
|
||||||
sys.stderr = StreamToLogger(logging.ERROR)
|
sys.stderr = StreamToLogger(logging.ERROR)
|
||||||
|
|
||||||
|
if cd_enable_log:
|
||||||
|
print("** Comfy Deploy logging enabled")
|
||||||
|
setup()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get the absolute path of the script's directory
|
# Get the absolute path of the script's directory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user