Skip to content

Log Level Configuration#282

Open
bprobert97 wants to merge 15 commits intomainfrom
281-configurable-log-levels
Open

Log Level Configuration#282
bprobert97 wants to merge 15 commits intomainfrom
281-configurable-log-levels

Conversation

@bprobert97
Copy link
Contributor

@bprobert97 bprobert97 commented Mar 4, 2026

Add --debug argument to CLI to make the THING LOGGER level configurable between debug and info. Unit test also added.

Closes #281

Tested on a microscope as part of https://gitlab.com/openflexure/openflexure-microscope-server/-/merge_requests/523

…le between debug and info. Unit test also added.
@bprobert97 bprobert97 linked an issue Mar 4, 2026 that may be closed by this pull request
@barecheck
Copy link

barecheck bot commented Mar 4, 2026

Barecheck - Code coverage report

Total: 96.56%

Your code coverage diff: 0.04% ▴

Uncovered files and lines
FileLines
src/labthings_fastapi/server/__init__.py204, 365
src/labthings_fastapi/server/cli.py102, 184

@bprobert97 bprobert97 marked this pull request as draft March 4, 2026 16:52
@bprobert97 bprobert97 marked this pull request as ready for review March 4, 2026 18:18
@bprobert97 bprobert97 changed the title DRAFT: Log Level Configuration Log Level Configuration Mar 4, 2026
config_json = json.dumps(
{"things": {"my_thing": {"cls": "tests.test_logs.ThingWithDebugInit"}}}
)

Copy link
Contributor

Choose a reason for hiding this comment

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

A bit belt and braces. But It wasn't clear to me whether caplog respects the loggers configuration. It does. This has been tested locally and passes (assuming I format the suggestion correctly)

Suggested change
# Run without --debug and capture logs
with caplog.at_level(logging.DEBUG, logger="labthings_fastapi.things"):
serve_from_cli(["--json", config_json], dry_run=True)
# There are no logs
assert len(caplog.messages) == 0


@classmethod
def from_config(cls, config: ThingServerConfig) -> Self:
def from_config(cls, config: ThingServerConfig, debug: bool = False) -> Self:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to put debug into the config file? I can see arguments either way. I think we will want to retain the --debug flag either way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the answer is "yes", I think it's absolutely fine for that to mean "yes in a future PR"...

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a command line flag is more normal for debug mode. I can see the OFM may want to do something else at some point as we have a service. But as there is an argument to "from_config" a downstream application can always add what they want there

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.

Configurable Log Levels

3 participants