schrodinger.utils.log module

Schrodinger logging utilities, including configuration.

To get a logger for a python script output, call:

import schrodinger.utils.log as log
logger = log.get_output_logger(name)

You can send messages to that logger as follows:"text")

Use setLevel() method to specify the minimum level of messages that need to be logged. For example, if you want to include debugging messages; do:


Copyright Schrodinger, LLC. All rights reserved.


Returns the logging level requested by the user via the SCHRODINGER_PYTHON_DEBUG environment variable as an integer.

Possible return values:

ERROR (40)
INFO (20)
DEBUG (10)


schrodinger.utils.log.get_logger(name: Optional[str] = None) logging.Logger

A convenience function to call default_logging_config and return a logger object.

schrodinger.utils.log.get_output_logger_handler() logging.Handler

Get the common handler used for output loggers.

schrodinger.utils.log.get_output_logger(name: str) logging.Logger

Use this function to get a standard Schrodinger logger that prints logging messages to stdout.

The default level for the logger is INFO.

The logger returned will not propagate upward, so messages sent to it will not appear in the standard python log.

schrodinger.utils.log.remove_handlers(logger: logging.Logger)

Remove all handlers of a logger.

schrodinger.utils.log.file_config(config_file: str, root: Optional[logging.Logger] = None)

Configure logging from a file, but don’t disable existing loggers.

The logging.config.fileConfig() function has the (IMO) odd behavior of disabling all existing loggers. This function is a wrapper that re-enables loggers after calling fileConfig.

Note that the overall goal of logging.config.fileConfig() is to reset any previous logging configuration, so don’t attempt to use this function incrementally. It’s recommended to call it once from your program as early as possible.


A centrally configurable logging config function to call from library modules.

If logging is used and a handler is not provided, a message like ‘No handlers could be found for logger “root”’ will be printed to stderr. To avoid this, each module that uses logging should call this method. Scripts can explicitly call logging_config to override this default configuration.

Users can modify the default logging behavior by creating a configuration file at ~/.schrodinger/python_logging.conf

The logging level of this function can also be modified through the SCHRODINGER_PYTHON_DEBUG environment variable. It can be set to any of the logging level names (i.e. DEBUG, INFO, WARN (or WARNING), ERROR, or CRITICAL (or FATAL)) or an integer value between 0 and 50. The environment variable will be ignored if a python_logging.conf file is present.

schrodinger.utils.log.logging_config(level: int = 30, file: Optional[str] = None, filemode: str = 'a', format: Optional[str] = None, append: bool = False, stream: Optional[io.IOBase] = None)

A flexible but simple root handler configuration that is similar to logging.basicConfig(), but wipes out existing handlers by default.

To log to a file, specify file; to log to a stream, specify stream; otherwise, stderr will be used. If both a file and stream are specified, the file will be used.

The default file mode is append, user can change different mode.

The default format has a timestamp, the level, and the logger name, followed by the logging mesage.

Unless append is true, it wipes out existing handlers. This is so modules can call default_logging_config() to provide a fallback stderr handler, but a script can easily override the default.

schrodinger.utils.log.get_stream_handler(stream: io.IOBase, format_string: str = '%(asctime)s %(levelname)s: %(message)s') logging.StreamHandler

Return a stream handler with a given formatter.