def log_if_needed(f):
    """
    A decorator used to log the query if logging is on.
    """
    def f_decorated(self, esQuery):
        if self.logging == 'query':
            self.query_log.append(esQuery)
        hits = f(self, esQuery)
        if self.logging == 'hits' and type(hits) == dict:
            self.query_log.append(hits)
        return hits
    return f_decorated