-
Notifications
You must be signed in to change notification settings - Fork 2
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
Adding feature to intercept errors and save information to files #45
Conversation
I think this PR branches off the other one about the crawler. I'll wait for you to merge the first one before reviewing. |
I've merged it now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe dumb question, but why are we using an "error file" in the first place and not just using logger to log errors to file ?
No, that's a good question. (i) I didn't know how to add a common file handler to the multiple loggers that are generated in the Thoughts, comments, suggestions? |
It's possible to configure the LOGGER object to write both to the terminal and to a file on disk. So if that meets the requirements, it could be an option. In another project I've used this:
which logs ERRORs to the terminal, but stores all INFO messages to a file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like @huard mentioned, I think it would work better if the logger was reused.
One way to implement it would be to add multiple log handlers.
This way, you only need to call log.<level>()
methods once, and each handler performs whatever it needs to do with the record respectively.
logger = get_logger("stac-populator")
log_handler = logging.StreamHandler(sys.stderr)
log_handler.setFormatter(logging._defaultFormatter) # or whatever
err_handler = logging.FileHandler("<file-path>")
err_handler.setFormatter(logging.Formatter(fmt="{stac_item_name}: {stac_item_loc}"))
logger.addHandler(log_handler)
logger.addHandler(err_handler)
logger.debug("Custom message: {stac_item_name}: {stac_item_loc}", stac_item_name, stac_item_loc)
A custom formatter could be defined to ignore the records when required arguments (stac_item_name, stac_item_loc, etc.) are missing. Just need to define the emit
method that handles the log record.
@dchandan |
Thanks for the comments and the useful video on the log file. I do like the JSON lines output format shown in the video as it would make parsing the log files for issues much easier. I've now revamped the whole app logging to use the setup in the video. |
Is it good to merge now? |
) | ||
parser.add_argument("--debug", action="store_true", help="Set logger level to debug") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be in the parent argparser (generic one before specific implementation is called).
ns.debug
will not exist if using other implementations than CMIP6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I've moved it. I'm not sure I like the current position much. Right now, one has to do:
stac-populator --debug run CMIP6_UofT stac-host catalog-url --auth-handler cookie --auth-identity ~/daccs_cookie.txt
I'd prefer if one could instead just do:
stac-populator run CMIP6_UofT stac-host catalog-url --auth-handler cookie --auth-identity ~/daccs_cookie.txt --debug
By the way, this might be related to #46. I noticed that there is something off with the CLI parser system you've put into place. I'll let you look into it since you put it in and hence you probably understand it better than me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To allow stac-populator run CMIP6_UofT --debug ...
, you could define the logging options as their own log_parser = argparse.ArgumentParser(...)
and pass that log_parser
in parents
:
stac-populator/STACpopulator/cli.py
Line 163 in 24eeb6b
parents=[populator_parser], |
Need to pass it down also to parser_maker
so it can add log_parser
to its own parents
as well.
stac-populator/STACpopulator/cli.py
Line 158 in 24eeb6b
populator_parser = parser_maker() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dchandan
Good to merge, but I let you decide if you want to try out #45 (comment) before or not.
@fmigneault |
Adding feature to intercept errors encountered while (i) generating STAC items, (ii) posting STAC items to the server. Information about the dataset and the error it encountered are saved to separate log files. An example log file from a run of the stac-populator is included below.
stac-populator_CMIP6populator_errors_20240119-185007.txt