Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing logcfg to Step.from_cmdline (and likly other config uses) changes global state #185

Open
braingram opened this issue Aug 22, 2024 · 0 comments

Comments

@braingram
Copy link
Collaborator

There are a few tests in jwst that use logcfg:
https://github.com/spacetelescope/jwst/blob/8efc26fdbda7936199d1a05cb57707d2c1cb0665/jwst/pipeline/tests/test_calwebb_image2.py#L82-L84
https://github.com/spacetelescope/jwst/blob/8efc26fdbda7936199d1a05cb57707d2c1cb0665/jwst/pipeline/tests/test_calwebb_image2.py#L82C5-L82C11

These change global logging state and can lead to later tests that check log output failing. Here's a somewhat minimal example:

import jwst
from stpipe.config_parser import logger as log
from jwst.stpipe import Step

LOGFILE="foo.log"
LOGCFG="log.cfg"

logcfg_content = f"[*] \n \
    level = INFO \n \
    handler = file:{LOGFILE}"
with open(LOGCFG, 'w') as f:
    f.write(logcfg_content)

args = ["dq_init", "some_uncal.fits", f"--logcfg={LOGCFG}"]
print(log.level)
Step.from_cmdline(args)
print(log.level)

print("Log contents")
with open(LOGFILE, "r") as f:
    print(f.read())

print("Second run, no config")
args = ["dq_init", "some_uncal.fits"]
Step.from_cmdline(args)

print("Log contents")
with open(LOGFILE, "r") as f:
    print(f.read())

Running the example the first call to from_cmdline runs as expected logging messages to foo.log. However the second run (when no logcfg is provided also logs to the same file (appending log messages) and runs at the same level as configured in the first run.

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

No branches or pull requests

1 participant