It is well known that if $(X,\mathcal{S})$ is a measure space and $f:X\to\mathbb{R}$ is a function, said function is said to be $\mathcal{S} $-measurable if $f^{-1}(A)\in\mathcal{S}$ for all Borel subsets $A\subset\mathbb{R}$ and a sufficient condition to verify this is to check if $f^{-1}((a,\infty))\in\mathcal{S}$ for all $a\in\mathbb{R}$
Now, the equivalent theorem for a function $:X\to [-\infty,\infty]$ which can take on infinite values is to check whether $f^{-1}((a,\infty])\in\mathcal{S}$ for all $a\in\mathbb{R}$ so (I guess) there must be some counterexample of a function $f:X\to [-\infty,\infty]$ such that $f^{-1}((a,\infty))\in\mathcal{S}$ but $f$ is not $\mathcal{S}$-measurable and I have tried to build one by, for example
mapping a non-measurable set to $\infty$ and its complement to $0$ (or some other number) so that $f^{-1}(A)\in\mathcal{S}$ for every $A\subset\mathbb{R}$ Borel subset of $\mathbb{R}$ turns out to be measurable but $f^{-1}(\{\infty\})$ does not, something like
let $(X,\mathcal{S})=(\mathbb{R},\mathcal{B})$, $V$ denote the Vitali set and $f:\mathbb{R}\to [-\infty,\infty]$ be such that $f(x):=\begin{cases}\infty &\text{ if }x\in V\\ 0 &\text{ if }x\in \mathbb{R}\setminus V\end{cases}$
which doesn't work since $\mathbb{R}\setminus V$ is also non-measurable...
so I would appreciate an hint about how to build such a counterexample, if, as I believe, it exists. Thanks.
Take $f(x):=\begin{cases}\infty &\text{ if }x\in V\\ -\infty &\text{ if }x\in \mathbb{R}\setminus V\end{cases}$.
Then $f^{-1}(a,\infty)$ is empty for any real number $a$ but $f$ is not meaurable.