The idea is in the right direction, but has a number of flaws in detail.
First, for positive integers $n$, $\log n$ will only rarely be an integer, and the answer you want is clearly an integer.
Second, there is the question of the base of the logarithms you are using. For decimals you need base $10$.
Now for how to get it right. If $n$ has $r$ digits in base $10$ we have $$10^r\gt n \ge 10^{r-1}$$ ($10^r$ is the least integer with $r+1$ digits) and taking logs to base $10$ gives us $$r\gt \log_{10}n\ge r-1$$So what we need to do is to take the integer part of $\log_{10}n$, which is $r-1$ and add $1$.
The formula becomes $r=\lfloor\log_{10}n\rfloor +1$
The number of digits in base $b$ is likewise $r=\lfloor\log_{b}n\rfloor +1$