title: How to log from a custom ai platform model
body: <p>I recently deployed a custom model to google cloud's ai-platform, and I am trying to debug some parts of my preprocessing logic. However, My print statements are not being logged to the stackdriver output. I have also tried using the logging client imported from google.cloud, to no avail. Here is my custom prediction file:</p>
  
  <pre><code>import os
  import pickle
  
  import numpy as np
  from sklearn.datasets import load_iris
  import tensorflow as tf
  
  from google.cloud import logging
  
  class MyPredictor(object):
    def __init__(self, model, preprocessor):
      self.logging_client = logging.Client()
      self._model = model
      self._preprocessor = preprocessor
      self._class_names = ["Snare", "Kicks", "ClosedHH", "ClosedHH",  "Clap", "Crash", "Perc"]
  
    def predict(self, instances, **kwargs):
      log_name = "Here I am"
      logger = self.logging_client.logger(log_name)
      text = 'Hello, world!'
      logger.log_text(text)
      print('Logged: {}'.format(text), kwargs.get("sr"))
  
      inputs = np.asarray(instances)
  
      outputs = self._model.predict(inputs)
  
      if kwargs.get('probabilities'):
        return outputs.tolist()
        #return "[]"
      else:
        return [self._class_names[index] for index in np.argmax(outputs.tolist(), axis=1)]
  
    @classmethod
    def from_path(cls, model_dir):
      model_path = os.path.join(model_dir, 'model.h5')
      model = tf.keras.models.load_model(model_path, custom_objects={"adam": tf.keras.optimizers.Adam, 
   "categorical_crossentropy":tf.keras.losses.categorical_crossentropy, "lr":0.01, "name": "Adam"})
  
      preprocessor_path = os.path.join(model_dir, 'preprocessor.pkl')
      with open(preprocessor_path, 'rb') as f:
        preprocessor = pickle.load(f)
  
      return cls(model, preprocessor)
  
  </code></pre>
  
  <p>I can't find anything online for why my logs are not showing up in stackdriver (neither print statements nor the logging library calls). Has anyone faced this issue?</p>
  
  <p>Thanks,
  Nikita</p>
  
  <p>NOTE: If you have enough rep to create tags please add the google-ai-platform tag to this post. I think it would really help people who are in my position. Thanks!</p>