Yes, logarithms always give dimensionless numbers, but no, it's not physical to take the logarithm of anything with units.
Instead, there is always some standard unit. For your example, the standard is the kilometer. Then 20 km, under the log transformation, becomes $\ln(20\;\textrm{km}\;/\;\textrm{km}\;)$. Similarly, the log of 10 cm, with this scale is
$$\ln(10\;\textrm{cm}\;/10\;\textrm{km}\;) = \ln(10\times 10^{-3} / 10^{3}) = \ln(10^{-5})$$
Not sure if this will answer your queries, but I did get intrigued by the implied question:
Could Newton have derived his theory of gravitation from dimensional analysis?
Newton had a hunch that planetary motion is nothing more than a direct result of the same effect that makes objects drop to earth: the presumed universal attraction between all masses. He wanted to derive the consequences of this hypothesis. Available to him were his three laws of motion, as well as two important observations:
1) the empirical fact that different masses undergo the same acceleration (observed by Galileo)
2) Kepler's third law of planetary motion: the square of the orbital period of a planet is proportional to the cube of the radius of its orbit around the sun.
The first observation tells Newton he has to consider the acceleration $g = F_g/m$ ($m$ being the planetary mass) due to gravity rather than the force $F_g$ itself. The second observation tells him that a constant (which we will refer to as Kepler's constant) $K$ will probably play a role in the law of gravitation that he is seeking. This constant is the product of the square of the angular frequency $\omega$ with the cube of the radius $r$ of the planetary orbital motion: $K = \omega^2 r^3$. And finally, apart from $g$ and $K$, the distance $r$ is expected to feature in the equation sought.
So, Newton was seeking a relation $f(K, r, g) = 0$. Kepler's constant $K = (2 \pi)^2 AU^3 yr^{-2}$ has dimensions $[L^3 T^{-2}]$, the distance $r$ has dimension $[L]$, and the acceleration $g$ has dimension $[L T^{-2}]$. So one dimensionless parameter can be defined: $r^2 g/K$. This directs Newton towards an equation of the form $g \propto K/r^2$. In terms of the force $F_g = m \ g$, this reads:
$$F_g \propto K \frac{m}{r^2}$$
However, according to Newton's third law, this force needs to be mutual between the two bodies. If $M$ denotes the sun's mass, it follows that $K = G M$ with $G$ a universal constant equal to $(2 \pi)^2 M_{sol}^{-1} AU^3 yr^{-2}$. The result is an equation symmetric in both masses:
$$F_g \propto G \frac{M \ m}{r^2}$$
Obviously, we can replace the proportionality sign with an equal sign provided we absorb any mathematical factors hidden from the dimensional analysis into the constant $G$.
Best Answer
A standard argument to deny possibility of inserting dimensionful quantities into transcendental functions is the following expression for Taylor expansion of e.g. $\exp(\cdot)$:
$$ e^x = \sum_n \frac{x^{n}}{n!} = 1 + x +\frac{x^2}{2} + \dots\,.\tag1$$
Here we'd add quantities with different dimensions, which you have already accepted makes no sense.
OTOH, there's an argument (paywalled paper), that in the Taylor expansion where the derivatives are taken "correctly", you'd get something like the following for a function $f$:
\begin{multline} f(x+\delta x)=f(x)+\delta x\frac{df(x)}{dx}+\frac{\delta x^2}2\frac{d^2f(x)}{dx^2}+\frac{\delta x^3}{3!}\frac{d^3f(x)}{dx^3}+\dots=\\ =f(x)+\sum_{n=1}^\infty\frac{\delta x^n}{n!}\frac{d^nf(x)}{dx^n},\tag2 \end{multline}
and the dimensions of derivatives are those of $1/dx^n$, which cancel those of $\delta x^n$ terms, making the argument above specious.