Skip to content

Exposing the stream in the logging module #5357

Description

@jauy123

The logging module should have an option to only stream to standard out/error rather than forcing a log file to disk.

In many HPC environments, the job controller capture both standard out and error to a text file. For many people, this is enough to debug their scripts if logging is redirected to those streams instead. Thus, logging to a file should be optional.

Describe the solution you'd like

Replace the logfile parameter in MDAnalysis.start_logging(logfile='MDAnalysis.log', version='2.1.0') with a stream parameter that acts like stream in logging.basicConfig

import logging
import sys

logging.basicConfig(
    level=logging.INFO,
    stream=sys.stdout,  
    format="%(asctime)s - %(levelname)s - %(message)s"
)

logging.info("This goes to stdout")
logging.error("This also goes to stdout")

Describe alternatives you've considered

You could wrap something elaborate with file steam redirection like in bash, but that is too complicated compared to this fix.

Additional context

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions