Skip to main content

Logging

If you wish to log information about some events occurring at model loading or prediction, you have to use the gunicorn.error logger. Other output streams of the model script are suppressed in the MLflow model container logs.

Example:

import logging
...


class Predictor(mlflow.pyfunc.PythonModel):

...

def predict(self, context: mlflow.pyfunc.PythonModelContext,
model_input: pd.DataFrame) -> dict:

logger = logging.getLogger('gunicorn.error')
logger.info('Predicting ...') # will appear in the log
print('print("Predicting...")') # will not appear in the log

return self._predict(model_input)