Skip to content

Use standard python logging facilities instead of printing to stdout #1657

@saulbein

Description

@saulbein

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions