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

GMT API callback to get error messages #49

Closed
leouieda opened this issue Sep 19, 2017 · 0 comments
Closed

GMT API callback to get error messages #49

leouieda opened this issue Sep 19, 2017 · 0 comments

Comments

@leouieda
Copy link
Member

Paul implemented a new API function that might be useful. For now, we only include the error code in the traceback while GMT prints the error message to stderr. It would be better to capture that message and include it in the exceptions.

EXTERN_MSC int GMT_Handle_Messages (void *API, unsigned int mode, unsigned int method, void *dest);

mode can be GMT_LOG_OFF, GMT_LOG_ONCE, or GMT_LOG_SET. First resets logging back to stderr (which is the default), ONCE sets logging from the next module to go to dest, then resets to stderr, while SET sets logging to go to dest until changed (or until session ends).
method is either GMT_IS_FILE, GMT_IS_STREAM, or GMT_IS_FDESC. So, to turn logging on to a file this.log for the next module, try GMT_Handle_Messages (API, GMT_LOG_ONCE, GMT_IS_FILE, “this.log”);

Could include a call using GMT_LOG_SET into gmt.clib.LibGMT to capture the messages.

leouieda added a commit that referenced this issue Nov 23, 2017
Fixes #49 

Uses `GMT_Handle_Messages` to send error messages to a log file.
In `call_module` retrieve those messages and use them in the 
exceptions for a more informative message (instead of just a status code).

Implements a context manager method `LibGMT.log_to_file` that 
creates a temp file and sets up logging. Logs only a single API call so it
must be used inside each method that wants to log. Actually only useful for
`call_module`. Most other API calls don't produce error messages.

Example:

    with self.log_to_file() as logfile:
        status = self._c_call_module(...)
        with open(logfile) as f:
            log = f.read()
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