TITLE: Is a function necessarily measurable, given that all of its level sets are measurable?
QUESTION [9 upvotes]: Let $f: \mathbb{R}^n \rightarrow \mathbb{R}$ be a function such that the set $$T_{\alpha} \equiv \{ x \in \mathbb{R}^n : f(x) = \alpha\}$$ is measurable $\forall \alpha \in \mathbb{R}$. Is $f$ measurable?
Here's the proof I've sketched, but I'd like to know whether I'm on the right way or not.
Since $T_\alpha$ is measurable $\forall \alpha \in \mathbb{R}$, the set $$T^{+}_{\beta} \equiv \mathbb{R}/\bigcup_{\alpha = \beta}^{+\infty}T_{\alpha} = \{x \in \mathbb{R} : f(x) < \beta\}$$ is also measurable $\forall \beta \in \mathbb{R}$, therefore $f$ is measurable.

REPLY [11 votes]: I'd like to know whether I'm on the right way or not.

Unfortunately not. Others have already provided counterexamples, so you now know that your conjecture is false, and that your proof must therefore contain a wrong step. In particular, your proof states that
$$\bigcup_{\alpha = \beta}^{+\infty}T_{\alpha}$$
is measurable since each $T_\alpha$ is such, but this reasoning step is unsound.
Indeed, the above argument only holds for countable unions, and the union above is not countable: it involves a set for every real $\geq \beta$.
If any union (with no size bounds) of measurable sets were measurable, then all sets would be measurable, provided singletons are. This follows by the trivial union
$$A = \bigcup_{a\in A} \{a\}$$