How can the length of a string be $O(\log n)$?
The length of the binary representation of a natural number $n$ is roughly $\log_2 n$. As an example, the number represented by the binary string $10^{n-1}$ of length $n$ is $2^n$.

Your sources are misleading. Usually $n$ is reserved for the input length or a related quantity, not the input value. If the input to a function is an integer $m$, then the input length is only $\sim \log_2 |m|$. In particular, intToStr actually runs in linear time in the input length, rather than logarithmic time.