<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def debug_layer(self, layer, check_fields=True, add_to_datastore=None):
 """Write the layer produced to the datastore if debug mode is on. :param layer: The QGIS layer to check and save. :type layer: QgsMapLayer :param check_fields: Boolean to check or not inasafe_fields. By default, it's true. :type check_fields: bool :param add_to_datastore: Boolean if we need to store the layer. This parameter will overwrite the debug mode behaviour. Default to None, we usually let debug mode choose for us. :param add_to_datastore: bool :return: The name of the layer added in the datastore. :rtype: basestring """

        # This one checks the memory layer.
        check_layer(layer, has_geometry=None)

        if isinstance(layer, QgsVectorLayer) and check_fields:
            is_geojson = '.geojson' in layer.source().lower()
            if layer.featureCount() == 0 and is_geojson:
                # https://issues.qgis.org/issues/18370
                # We can't check a geojson file with 0 feature.
                pass
            else:
                check_inasafe_fields(layer)

        # Be careful, add_to_datastore can be None, True or False.
        # None means we let debug_mode to choose for us.
        # If add_to_datastore is not None, we do not care about debug_mode.
        if isinstance(add_to_datastore, bool) and add_to_datastore:
            save_layer = True
        elif isinstance(add_to_datastore, bool) and not add_to_datastore:
            save_layer = False
        elif self.debug_mode:
            save_layer = True
        else:
            save_layer = False

        if save_layer:
            result, name = self.datastore.add_layer(
                layer, layer.keywords['title'])
            if not result:
                raise Exception(
                    'Something went wrong with the datastore : {error_message}'
                    .format(error_message=name))
            if self.debug_mode:
                # This one checks the GeoJSON file. We noticed some difference
                # between checking a memory layer and a file based layer.
                check_layer(self.datastore.layer(name))

            return name