<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _merge_before_set(self, key, existing, value, is_secret):
 """Merge the new value being set with the existing value before set"""


        def _log_before_merging(_value):
            self.logger.debug(
                "Merging existing %s: %s with new: %s", key, existing, _value
            )

        def _log_after_merge(_value):
            self.logger.debug("%s merged to %s", key, _value)

        global_merge = getattr(self, "MERGE_ENABLED_FOR_DYNACONF", False)

        if isinstance(value, dict):
            local_merge = value.pop(
                "dynaconf_merge", value.pop("dynaconf_merge_unique", None)
            )
            if global_merge or local_merge:
                safe_value = {k: "***" for k in value} if is_secret else value
                _log_before_merging(safe_value)
                object_merge(existing, value)
                safe_value = (
                    {
                        k: ("***" if k in safe_value else v)
                        for k, v in value.items()
                    }
                    if is_secret
                    else value
                )
                _log_after_merge(safe_value)

        if isinstance(value, (list, tuple)):
            local_merge = (
                "dynaconf_merge" in value or "dynaconf_merge_unique" in value
            )
            if global_merge or local_merge:
                value = list(value)
                unique = False

                if local_merge:
                    try:
                        value.remove("dynaconf_merge")
                    except ValueError:  # EAFP
                        value.remove("dynaconf_merge_unique")
                        unique = True

                original = set(value)
                _log_before_merging(
                    ["***" for item in value] if is_secret else value
                )
                object_merge(existing, value, unique=unique)
                safe_value = (
                    ["***" if item in original else item for item in value]
                    if is_secret
                    else value
                )
                _log_after_merge(safe_value)

        return value