Skip to content

Commit

Permalink
Add option to log non-error output to stdout
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
webfiltered committed Dec 27, 2024
1 parent c7038ef commit d6b7618
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def on_flush(callback):
if stderr_interceptor is not None:
stderr_interceptor.on_flush(callback)

def setup_logger(log_level: str = 'INFO', capacity: int = 300):
def setup_logger(log_level: str = 'INFO', capacity: int = 300, use_stdout: bool = False):
global logs
if logs:
return
Expand All @@ -70,4 +70,15 @@ def setup_logger(log_level: str = 'INFO', capacity: int = 300):

stream_handler = logging.StreamHandler()
stream_handler.setFormatter(logging.Formatter("%(message)s"))

if use_stdout:
# Only errors and critical to stderr
stream_handler.addFilter(lambda record: not record.levelno < logging.ERROR)

# Lesser to stdout
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setFormatter(logging.Formatter("%(message)s"))
stdout_handler.addFilter(lambda record: record.levelno < logging.ERROR)
logger.addHandler(stdout_handler)

logger.addHandler(stream_handler)
1 change: 1 addition & 0 deletions comfy/cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class LatentPreviewMethod(enum.Enum):
parser.add_argument("--multi-user", action="store_true", help="Enables per-user storage.")

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

# The default built-in provider hosted under web/
DEFAULT_VERSION_STRING = "comfyanonymous/ComfyUI@latest"
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
os.environ['DO_NOT_TRACK'] = '1'


setup_logger(log_level=args.verbose)
setup_logger(log_level=args.verbose, use_stdout=args.log_stdout)

def apply_custom_paths():
# extra model paths
Expand Down

0 comments on commit d6b7618

Please sign in to comment.