Convert LogEvent object to a dictionary.

def to_dict(self, labels=None):
        """Convert LogEvent object to a dictionary."""
        output = {}
        if labels is None:
            labels = ['line_str', 'split_tokens', 'datetime', 'operation',
                      'thread', 'namespace', 'nscanned', 'ntoreturn',
                      'nreturned', 'ninserted', 'nupdated', 'ndeleted',
                      'duration', 'r', 'w', 'numYields']

        for label in labels:
            value = getattr(self, label, None)
            if value is not None:
                output[label] = value

        return output