Skip to content

Feature: Log to file for GraphServer CLI#248

Open
griffinmilsap wants to merge 6 commits into
devfrom
feature/log-to-file
Open

Feature: Log to file for GraphServer CLI#248
griffinmilsap wants to merge 6 commits into
devfrom
feature/log-to-file

Conversation

@griffinmilsap
Copy link
Copy Markdown
Collaborator

Closes #246

Summary

Add file logging for the ezmsg start / ezmsg serve service envelope.

This change adds --log-file support to both commands, passes the option through from start to the spawned serve subprocess, and otherwise falls back to EZMSG_LOG_FILE or a default per-run log path under a platform-appropriate ezmsg data directory. Default logs are organized by GraphServer port and use a timestamped filename for each execution.

Scope

This intentionally stays narrow and only affects the start / serve workflow. It does not attempt to define broader logging behavior yet for ez.run, GraphRunner, subprocess/session aggregation, or remote clients.

Testing

  • Added one parser test for serve --log-file
  • Added one command test verifying start passes --log-file through to serve
  • Ran:
uv run pytest tests/test_command.py -q

@griffinmilsap griffinmilsap changed the title Log to file for GraphServer CLI Feature: Log to file for GraphServer CLI May 19, 2026
Replaced inferring format from pre-exsiting logger handlers
log_level<WARNING goes to stdout and log_level>=WARNING goes to stderr
@KonradPilch KonradPilch self-requested a review June 2, 2026 18:34
Copy link
Copy Markdown
Contributor

@KonradPilch KonradPilch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like what you've done. I have a few suggestions which I have added as commits to this branch. Please look through them. My changes based on my review:

  1. Wired log_file into run_command to avoid an AttributeError.
  2. Lifecycle management of logging handlers we create.
  3. Defined a standard logging formatter in logconfig.py that is accessed via create_ezmsg_log_formatter().
  4. Split logs between stdout and stderr based on the log level (for when other processes own the Graph Service).

parser.add_argument("--address", help="Address for GraphServer", default=None)


def add_log_file_argument(parser: argparse.ArgumentParser) -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to plumb this into run_command() too.

Comment thread src/ezmsg/core/commands/common.py Outdated
and getattr(handler, "baseFilename", None) == str(log_path)
for handler in logger.handlers
):
formatter = next(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just define the standard ezmsg formatter and use that.

Comment thread src/ezmsg/core/commands/common.py Outdated
),
None,
)
handler = logging.FileHandler(log_path, encoding="utf-8")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably deal with lifecycle management here, so that we don't leave open handlers we created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add log-to-file support for ezmsg start (background GraphServer)

2 participants