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

Set info logging level in find_tailcuts #1349

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

moralejo
Copy link
Collaborator

@moralejo moralejo commented Feb 7, 2025

Not sure if there is a better way to set it (let me know if that is the case). Doing it in the script which calls the function did not work.

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 72.86%. Comparing base (76540cc) to head (604988c).

Files with missing lines Patch % Lines
lstchain/image/cleaning.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1349      +/-   ##
==========================================
- Coverage   72.86%   72.86%   -0.01%     
==========================================
  Files         137      137              
  Lines       14515    14516       +1     
==========================================
  Hits        10577    10577              
- Misses       3938     3939       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@morcuended
Copy link
Member

morcuended commented Feb 7, 2025

@morcuended Are the loggers of the script and of the called functions independent? Should I pass the logging level explicitly as an argument of find_tailcuts? I want it always set to "info", so the original code should do.

In principle not, I think it should be controlled by the level set in the main script calling the other module (see example at the top of https://docs.python.org/3/library/logging.html). Maybe need to set explicitly the level for file handler as well.

In lstchain_find_tailcuts.py

def main():
    args = parser.parse_args()

    output_dir = args.output_dir.absolute()
    output_dir.mkdir(exist_ok=True, parents=True)

    log.setLevel(logging.INFO)
    
    # Console handler
    console_handler = logging.StreamHandler(sys.stdout)
    console_handler.setLevel(logging.INFO)
    logging.getLogger().addHandler(console_handler)

    # File handler
    log_file = args.log_file or f'log_find_tailcuts_Run{run_id:05d}.log'
    log_file = output_dir / log_file
    file_handler = logging.FileHandler(log_file, mode='w')
    file_handler.setLevel(logging.INFO)
    logging.getLogger().addHandler(file_handler)
    ...

@moralejo
Copy link
Collaborator Author

moralejo commented Feb 7, 2025

I will try, thanks a lot for the info!

@moralejo
Copy link
Collaborator Author

moralejo commented Feb 7, 2025

Adding the console handler resulted in duplication of the (incomplete) output in stdout.
Then adding the setting for the file handler did not help either. Will keep trying.

@moralejo
Copy link
Collaborator Author

@morcuended I tried to follow the suggestions in the link you sent and did not help. The only way I seem to be able to activate INFO logging is inside cleaning.py

Copy link
Member

@morcuended morcuended left a comment

Choose a reason for hiding this comment

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

I do not know the reason why. It is still strange to me that it is not controlled by the main script calling the function.

Therefore, use the definition inside the function for the time being.

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.

2 participants