You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use standard python logging facilities instead of printing to stdout #1657
Describe the feature you'd like
Currently, the library uses print() statements to print most logs from the framework itself, and also the ones it receives from models. If the library is used in, for example, a web service, it would be preferable to be able to use the standard python logging library to configure log levels, and be able to send the logs somewhere else than stdout.
How would this feature be used? Please describe.
This would allow the logging to be configured in a standard pythonic way. For example, if I wanted to redirect the logs to a file, I could attach a logging.FileHandler to the sagemaker logger, or alternatively sagemaker.session logger if I wanted to redirect only the session logs. It would also allow customizing the log format, and other features of the python logging module.
Describe alternatives you've considered
The current workaround I am using is to redirect all stdout text to a custom stream handler, which then re-prints them via logging. The problem with this is that I can not control log levels and formats, and if any other library prints to stdout it's output will also end up in the logs.
I've looked up if I would be able to do a PR myself, and it seems most of the print culprits are in session.py. The difficulty comes from the progress bar like behaviour of some actions, for example when creating a training job:
2020-07-02 10:00:41 Starting - Starting the training job...
The dots here are printed each poll, so they show up like this in logs:
2020-07-02 10:00:41 Starting - Starting the training job
.
.
.
The question then becomes either:
is this behaviour really necessary?
can we preserve this behaviour only when printing to the console, but ignore it when logging?
Well, I would strongly prefer the first option - print is essentially the same as logging to stdout (which can be easily set up in cli, and it seems like jupyter sets up logging automatically, so not much work to do there as well). The only real difference is with polling / progress bars, since they would create separate messages for each 'tick'.
In my opinion the third option is a no go, since a stream handler will capture stdout output from other stuff, for example a user's print() statements.
I will try to get some PR done next week, to see how difficult the changes would be. As for the polling 'tick' text, maybe adding an option to disable it would be best? I would not want my logs to end up like this:
2020-07-02 10:00:41 Starting - Starting the training job
2020-07-02 10:00:46 .
2020-07-02 10:00:51 .
2020-07-02 10:00:56 .
Activity
metrizable commentedon Jul 2, 2020
@saulbein Thanks for the great suggestion!
saulbein commentedon Jul 2, 2020
I've looked up if I would be able to do a PR myself, and it seems most of the
printculprits are insession.py. The difficulty comes from the progress bar like behaviour of some actions, for example when creating a training job:The dots here are printed each poll, so they show up like this in logs:
The question then becomes either:
metrizable commentedon Jul 2, 2020
off the top of my head, we have a few options:
print()to a call to the loggerprint()statements to calls to the loggersys.stdout, convertprint()to calls to this loggerthere are probably others that we can consider.
saulbein commentedon Jul 3, 2020
Well, I would strongly prefer the first option - print is essentially the same as logging to stdout (which can be easily set up in cli, and it seems like jupyter sets up logging automatically, so not much work to do there as well). The only real difference is with polling / progress bars, since they would create separate messages for each 'tick'.
In my opinion the third option is a no go, since a stream handler will capture stdout output from other stuff, for example a user's
print()statements.I will try to get some PR done next week, to see how difficult the changes would be. As for the polling 'tick' text, maybe adding an option to disable it would be best? I would not want my logs to end up like this:
akrishna1995 commentedon Dec 21, 2023
Thanks for opening this issue. The fix PR has been merged : #4133. Feel free to reopen if you have any issues - Thank you
Always add code channel, regardless of network isolation (aws#1657)
feature: support training for JumpStart model references as part of C…
feature: support training for JumpStart model references as part of C…
feature: support training for JumpStart model references as part of C…
feature: support training for JumpStart model references as part of C…
feature: support training for JumpStart model references as part of C…
feature: support training for JumpStart model references as part of C…
kandinsky, nova, zimmer to Keynote 3 v2 (#1924)
Reinvent keynote3 v2 (#5353)
feature: support training for JumpStart model references as part of C…