ExperimentalMineralPhysics / Continuous-Peak-Fit

Fits azimuth/time dependency of peaks with Fourier Series descriptions
MIT License
5 stars 2 forks source link

Convert all Print Statements in CPF CLI Version to Logging Statements #10

Open Adina-Rahim opened 2 years ago

Adina-Rahim commented 2 years ago
S-Hunt commented 2 years ago

Danielle and I will replace all these statements. The limiting step is piping the output from lmfit into the logger, which will involve capturing the output of the print statements.

daniellefenech commented 1 year ago

@AdinaRahim Are you able to give some details of what you tried with regards to logging and lmfit and what issues you found?

S-Hunt commented 1 year ago

Lmfit uses print to write outputs to the command line. We will have to capture the output of the print statements and send them to the logger and back to sys.stdout.

Adina-Rahim commented 1 year ago
logger = logging.getLogger()

logger.setLevel(logging.DEBUG)

stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.DEBUG)

file_handler = logging.FileHandler('new_log.log')
file_handler.setLevel(logging.DEBUG)

logger.addHandler(file_handler)
logger.addHandler(stdout_handler)

@daniellefenech @S-Hunt, I tried to set handler for both standard_output and file as depicted above. It's generating log file as well as keeping output on console. Made replacements only on settings.py file.

aharwood2 commented 1 year ago

This is really outside the scope of the initial project request for the GUI as it is an update to the core application so will be at the bottom of the backlog.

aharwood2 commented 1 year ago

Capturing the stdout may well be possible. A quick Google gives this: https://stackoverflow.com/questions/5136611/capture-stdout-from-a-script