Skip to content

Commit 9cfd185

Browse files
authored
Add option to log non-error output to stdout (#6243)
* nit * Add option to log non-error output to stdout - No change to default behaviour - Adds CLI argument: --log-stdout - With this arg present, any logging of a level below logging.ERROR will be sent to stdout instead of stderr
1 parent 4b5bcd8 commit 9cfd185

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

app/logger.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def on_flush(callback):
5151
if stderr_interceptor is not None:
5252
stderr_interceptor.on_flush(callback)
5353

54-
def setup_logger(log_level: str = 'INFO', capacity: int = 300):
54+
def setup_logger(log_level: str = 'INFO', capacity: int = 300, use_stdout: bool = False):
5555
global logs
5656
if logs:
5757
return
@@ -70,4 +70,15 @@ def setup_logger(log_level: str = 'INFO', capacity: int = 300):
7070

7171
stream_handler = logging.StreamHandler()
7272
stream_handler.setFormatter(logging.Formatter("%(message)s"))
73+
74+
if use_stdout:
75+
# Only errors and critical to stderr
76+
stream_handler.addFilter(lambda record: not record.levelno < logging.ERROR)
77+
78+
# Lesser to stdout
79+
stdout_handler = logging.StreamHandler(sys.stdout)
80+
stdout_handler.setFormatter(logging.Formatter("%(message)s"))
81+
stdout_handler.addFilter(lambda record: record.levelno < logging.ERROR)
82+
logger.addHandler(stdout_handler)
83+
7384
logger.addHandler(stream_handler)

comfy/cli_args.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class LatentPreviewMethod(enum.Enum):
122122
vram_group.add_argument("--novram", action="store_true", help="When lowvram isn't enough.")
123123
vram_group.add_argument("--cpu", action="store_true", help="To use the CPU for everything (slow).")
124124

125-
parser.add_argument("--reserve-vram", type=float, default=None, help="Set the amount of vram in GB you want to reserve for use by your OS/other software. By default some amount is reverved depending on your OS.")
125+
parser.add_argument("--reserve-vram", type=float, default=None, help="Set the amount of vram in GB you want to reserve for use by your OS/other software. By default some amount is reserved depending on your OS.")
126126

127127

128128
parser.add_argument("--default-hashing-function", type=str, choices=['md5', 'sha1', 'sha256', 'sha512'], default='sha256', help="Allows you to choose the hash function to use for duplicate filename / contents comparison. Default is sha256.")
@@ -141,6 +141,7 @@ class LatentPreviewMethod(enum.Enum):
141141
parser.add_argument("--multi-user", action="store_true", help="Enables per-user storage.")
142142

143143
parser.add_argument("--verbose", default='INFO', const='DEBUG', nargs="?", choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Set the logging level')
144+
parser.add_argument("--log-stdout", action="store_true", help="Send normal process output to stdout instead of stderr (default).")
144145

145146
# The default built-in provider hosted under web/
146147
DEFAULT_VERSION_STRING = "comfyanonymous/ComfyUI@latest"

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
os.environ['DO_NOT_TRACK'] = '1'
1818

1919

20-
setup_logger(log_level=args.verbose)
20+
setup_logger(log_level=args.verbose, use_stdout=args.log_stdout)
2121

2222
def apply_custom_paths():
2323
# extra model paths

0 commit comments

Comments
 (0)