If $f_n$ are measurable and $f_n\to f$ almost everywhere, then $f$ is measurable (values on a topological space) In Folland's Real Analysis book, it's an exercise to prove:

Given a complete measure $\mu$, if $f_0, f_1, f_2, \ldots$ are measurable, and $f_n \to f$ almost everywhere, then $f$ is measurable.

I can prove it using other propositions from the book in the simple case that the functions take values on the reals (or complex plane): $$ f_0,f_1,f_2,\ldots,f:X\to\mathbb R\text{ or }\mathbb C$$
Also, I think that the point of the exercise is indeed to prove it just to these cases.
But I'm curious if it's possible to generalize this result for functions $$f_0,f_1,f_2,\ldots,f:X\to Y$$ where $Y$ is a generic measure space. Of course, we need some structure on $Y$ to talk about convergence, so $Y$ should be a topological space, with a measure defined on its Borel $\sigma$-algebra. Or maybe we need $Y$ to be a metric space? I think it must be easy when $Y=\mathbb R^n$ or $\mathbb C^n$, using the fact that a function is measurable iff its coordinate-functions are measurable.
To be precise, my question is: is it true that Folland's proposition above holds for functions takings values on arbitrary topological spaces with Borel measures? If not, is it true for functions taking values on arbitrary metric spaces with Borel measures? If not, what kind of property do we need on the range space of the functions to be able to prove the quoted proposition above?
P.S.: The proof that Folland's book leads to is based on $\sup$s and $\inf$s; that's why I'm having a hard time generalizing it to arbitrary spaces.
 A: Let us first show that if $f_n \to f$ everywhere, then $f$ is also measurable, if $Y$ is a metric space. The proof is more or less literally taken from Serge Lang's "Real and Functional Analysis". A different (shorter) proof is given in Dudley's book "Real Analysis and Probability", Theorem 4.2.2.
First, let $U \subset Y$ be open. For each $x \in f^{-1}(U)$, we have $f_n (x) \to f(x) \in U$ and thus $f_n (x) \in U$, i.e. $x \in f_n^{-1}(U)$ for all sufficiently large $n \geq n_x$. This proves
$$
f^{-1}(U) \subset \bigcap_{m=1}^\infty \bigcup_{k=m}^\infty f_k^{-1}(U). \qquad (\dagger)
$$
Now, let $A \subset Y$ be closed. If
$$
x \in \bigcap_{m=1}^\infty \bigcup_{k=m}^\infty f_k^{-1}(A),
$$
then for each $m$ arbitrarily large, there is some $k \geq m$ with $f_k (x) \in A$. This implies that there is some subsequence $(f_{k_\ell})$ with $f_{k_\ell} (x) \in A$ for all $\ell$. But $f_{k_\ell} (x) \to f(x)$. Since $A$ is closed, this yields $f(x) \in A$, i.e. $x \in f^{-1}(A)$. Hence,
$$
\bigcap_{m=1}^\infty \bigcup_{k=m}^\infty f_k^{-1}(A) \subset f^{-1}(A). \qquad (\ddagger)
$$
Now, let $U \subset Y$ be open and define
\begin{eqnarray*}
A_n &:=& \{y \in Y \mid {\rm dist}(y, U^c) \geq 1/n\},\\
U_n &:=& \{y \in Y \mid {\rm dist}(y, U^c) > 1/n\}.
\end{eqnarray*}
Since the ${\rm dist}$ function is continuous, we see that $U_n$ is open and $A_n$ is closed with $U_n \subset A_n \subset U$ and $\bigcup_n U_n = \bigcup_n A_n = U$. Here, the equality to $U$ uses the fact that $U$ is open.
Using $(\ddagger)$, we see
$$
f^{-1}(U) = \bigcup_n f^{-1}(U) \supset \bigcup_n \bigcap_{m=1}^\infty \bigcup_{k=m}^\infty f_k^{-1}(A_n) \supset \bigcup_n \bigcap_{m=1}^\infty \bigcup_{k=m}^\infty f_k^{-1}(U_n).
$$
Conversely, $(\dagger)$ implies
$$
f^{-1}(U) = \bigcup_n f^{-1}(U_n) \subset \bigcup_n \bigcap_m \bigcup_{k=m}^\infty f_k^{-1}(U_n).
$$
All in all, we get equality. Since the right-hand side is a measurable set, $f^{-1}(U)$ is measurable. This shows that $f$ is measurable.

Now, if $X$ is a complete measure space and if $f = g$ a.e. with $g$ measurable, then $f$ is also measurable. To see this, let $N \subset X$ be of measure zero with $f = g$ on $N^c$. Now, if $U \subset Y$ is open, then
$$
f^{-1}(U) = [g^{-1}(U) \cap N^c] \cup [f^{-1}(U) \cap N],
$$
where $[g^{-1}(U) \cap N^c]$ is measurable because $g$ is and $[f^{-1}(U) \cap N]$ is measurable as a subset of a null-set, because the measure space is assumed complete.

Thus, if the convergence is only true almost everywhere, i.e. on $N^c$, where $N \subset X$ is of measure zero, then $g_n := f_n \cdot \chi_{N^c}$ is measurable with $g_n \to f \cdot \chi_{N^c}$ pointwise. Hence, $f \cdot \chi_{N^c}$ is measurable. But $f = f \cdot \chi_{N^c}$ on $N^c$, i.e. almost everywhere. Hence, $f$ is measurable.

Finally, we show that the statement is false in general if $Y$ is not a metric space. This counterexample is taken from Dudley's book, Proposition 4.2.3.
We take $Y = I^I$, where $I =[0,1]$ is the unit interval. We equip $I$ with the usual product topology and we define
$$
f_n : I \to I^I, x\mapsto (y\mapsto  \max \{0, 1- n|x-y|\}).
$$
Since $I$ is first countable, $f_n$ is continuous if we can show that $x_k \to x \in I$ implies $f_n(x_k) \to f_n(x)$. But this simply means $f_n(x_k)(y) \to f_n (x)(y)$ for all $y \in I$, which is easy to see.
Now define
$$
f : I \to I^I, x \mapsto (y \mapsto \chi_\Delta (x,y)),
$$
where $\Delta = \{(x,x) \in I\times I \mid x\in I\}$.
It is easy to see $f_n (x)(y) \to f(x)(y)$ for all $x,y\in I$. But this means $f_n(x) \to f(x)$ for all $x \in I$.
Now, let $E \subset I$ be an arbitrary subset (potentially nonmeasurable) and let
$$
W := \{g \in I^I \mid \exists y\in E : g(y) > 1/2 \} = \bigcup_{y \in E} {g \in I^I \mid g(y)>1/2}.
$$
Then $W \subset I^I$ is open, but $f^{-1}(W) = E$. If we take $E$ to be nonmeasurable (w.r.t. the Lebesgue $\sigma$-algebra), this shows that $f$ is not Lebesgue-measurable, although all $f_n$ are continuous and hence measurable.
