Skip to content

Add log-file-mode option to enable appending instead of truncating #11978

@Leithal3

Description

@Leithal3

What's the problem this feature will solve?

I'm trying to add custom headers to my log-files before running pytest. This is currently impossible because the LoggingPlugin hard-codes the _FileHandler mode to be "w" which truncates the log-file before printing logs.

Describe the solution you'd like

I'd like to be able to pass a --log-file-mode=a option that is respected by the LoggingPlugin and enables it to append to, rather than truncate, the log-file.

This would allow me to add custom headers to my log-files, providing additional context of the test run and the state of the system. These log-files are provided to users for debugging purposes and, as such, additional context is valuable.

Alternative Solutions

It would be possible to achieve this post hoc by reading the contents of the log-file, adding the custom header, then rewriting the contents, but this seems inefficient.

Additional context

During my search, I found this seemingly related issue that was closed due to a lack of information.

I'm happy to provide a PR with the required changes and tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: loggingrelated to the logging builtin plugintype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions