Why is $\int_{-\infty}^\infty |g(x)|\,dx = \int_0^\infty \mu(\{x : |g(x)| \ge t\})\,dt$ true? Why do we have the following equality$$\int_{-\infty}^\infty |g(x)|\,dx = \int_0^\infty \mu(\{x : |g(x)| \ge t\})\,dt,$$where $\mu$ is Lebesgue measure?

We claim that for a nonnegative measurable function $g:\Bbb{R}\to[0,\infty)$,
$$
\int_\Bbb{R}g(x)\ d\mu(x)=\int_{[0,\infty)}\mu(\{x\in\Bbb{R}\mid g(x)\geq s\}) \ d\mu(s).
$$
This is a good example of applications of the Fubini-Tonelli's Theorem. 
Let $\nu:=g_*\mu$ be the pushforward of $\mu$, i.e., $\nu=\mu\circ g^{-1}$. Then
$$
\int_\Bbb{R}g(x)\ d\mu(x)=\int_{[0,\infty)}x\ d\nu(x).
$$
Note that
$$
\begin{align*}
\int_{[0,\infty)}x\ d\nu(x)&=\int_{[0,\infty)}\left(\int_{[0,\infty)}1_{[0,x]}(y)\ d\mu(y)\right)\ d\nu(x)\\
&=\int_{[0,\infty)} \left(\int_{[0,\infty)}1_{[y,\infty]}(x)\ d\nu(x)\right)\ d\mu(y)\\
&=\int_{[0,\infty)} \nu([y,\infty))\ d\mu(y)\\
&=\int_{[0,\infty)} \mu\circ g^{-1}([y,\infty))\ d\mu(y)\\
&=\int_{[0,\infty)}\mu(\{x\in\Bbb{R}\mid g(x)\geq y\}) \ d\mu(y).
\end{align*}
$$
