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

Option to redirect log messages to console #17

Open
jburos opened this issue Apr 25, 2017 · 3 comments
Open

Option to redirect log messages to console #17

jburos opened this issue Apr 25, 2017 · 3 comments

Comments

@jburos
Copy link
Member

jburos commented Apr 25, 2017

When fitting long-running models, it can be helpful to see error messages / warnings produced by stancache in the console.

It would be nice to add this option to the config file so that messages are broadcast more widely, particularly when they involve being unable to save to disk.

@jburos
Copy link
Member Author

jburos commented Apr 25, 2017

I'm pretty sure @tavinathanson set this up by default for cohorts, will likely borrow his implementation

@maximz
Copy link

maximz commented Apr 26, 2017

Here's a way to print to the console from which jupyter notebook is running, rather than to a notebook itself:

import sys
print("stdout -- visible only in jupyter notebook", file=sys.stdout)
print("stderr -- visible only in jupyter notebook", file=sys.stderr)
alt_stdout = open('/dev/stdout', 'w')
print("this only shows up in the console", file=alt_stdout)

@jburos
Copy link
Member Author

jburos commented Apr 26, 2017

I was thinking of adding something like this snippet of code to add a second output stream handler to the logger, depending on the user's preferences.

    if logger.handlers:
        logger.handlers = []
    stdout_handler = logging.StreamHandler(sys.stdout)
    logger.addHandler(stdout_handler)
    logger.setLevel(logging.INFO)

You can do this now with logging, in a notebook, yourself. I was going to add a convenience so that this can be set in the config files. It looks like you would want to replace the sys.stdout with your alt_stdout above.

Putting these pieces together, it would look something like the following:

    alt_stdout = open('/dev/stdout', 'w')
    stdout_handler = logging.StreamHandler(alt_stdout)
    logger.addHandler(stdout_handler)

or,

    stdout_handler = logging.FileHandler('/dev/stdout')
    logger.addHandler(stdout_handler)

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

2 participants