What is the logarithm of a kilometer? Is it a dimensionless number?
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})$$
Here's one "mathematical" but highly unphysical answer.
Using that $km\cdot km = (km)^2$ etc, we can formally define arithmetic of numbers with units over a graded algebra $A = \oplus_{k\in \mathbb{N}} V_k$ where $V_k = \otimes^k V$ where $V$ is treated as a one-dimensional real vector space ($V_0$ is the scalar $\mathbb{R}$). The choice of unit is the choice of a basis vector in $V$. $V_0$ is the pure scalars. So for each choice of a basis vector $v \in V$, we get mapping from the infinite sequence $\mathbb{R}^{\mathbb{N}}\to A$ realizing that sequence via $(r_k) \to [r_k]_v = \sum r_k (\otimes^k v)$. We define multiplication $V_k\times V_{k'} \to V_{k+k'}$ as usual.
(We won't define the negative power units for now. But they probably can be incorporated analogously.)
Then formally we can define $\exp: A \to A$ by the power series expansion
$$ \exp a = \sum_{k = 0}^{\infty} \frac{1}{k!} a^k $$
where $a^k$ is defined in the sense of the graded algebra. And there, we have defined what it means for $\exp$ of something with units. Change of base of $\exp$ is handled by $y^a = \exp (\ln(y)\cdot a)$. And similarly the change of units is naturally incorporated, using the fact that a change of basis on a one dimensional real vector space is just multiplication by scalars. In other words, we have $[r_k]_v = [r'_k]_{v'}$ where $r_k = s^kr'_k$ when $v = s v'$.
Using this we can formally invert the power series expansion to find what $\ln$ "should" be. Fix a unit $v$. Take $(r_k) \in \mathbb{R}^{\mathbb{N}}$ and consider $[r_k]_v \in A$. To find $\ln [r_k]_v$ we need to find $(s_k)\in \mathbb{R}^{\mathbb{N}}$ such that
$$ \begin{align} r_0 & = \exp s_0\\ r_1 & = e^{s_0} s_1 \\ r_2 & = e^{s_0} (s_2 + \frac{1}{2} s_1^2)\\ & \vdots \end{align} $$
(We can also use the Taylor expansion of $\ln$ around $1\in\mathbb{R}$ to get the expression for $(s_k)$ in terms of $(r_k)$.)
Unfortunately, even in this frame work $\ln 1 km$ is still not well-defined: in the image of $\exp$, $r_0$ is necessarily positive. Formally, it is possible to define $\ln (1 km) = \ln (1 + (1 km - 1))$ as the rather divergent, power series
$$ \ln (1 m) = \sum \frac{(-1)^{k+1}}{k} (-1 + 1 (m))^k = \sum \frac{-1}{k} + \sum 1(m) - \sum \frac{k-1}{2} (m^2) + \cdots $$
Now some fun with divergent series: note that $\sum 1 = \sum (-1)^k(-1)^k = \sum (-1)^kx^k |_{-1}$ is the Taylor series expansion of $1/x$ around $x_0 = 1$ evaluated at $-1$, so the second term is nominally $\lim_{x\to 0+} 1/x$. So even if we regularise:
$$ \lim_{\delta \to 0+} \ln (\delta + 1m) = \lim_{\delta \to 0+} \ln \delta + \delta^{-1} m + \cdots $$
is still heavily divergent.
(Observe, that, however, $\ln (1 + 1km) = \sum (-1)^{j+1}/j (km)^j$ is well defined as a formal power series.)
So what was the point of this post? This post is primarily addressed at the conclusion that $\log m$ is a "dimensionless number" as stated in the statement of the question. While in the usual arithmetic we are taught that we cannot add apples to oranges, that is only if we take the point of view of trying to add an object in the $\mathbb{Z}$-module of apples to a separate object in the $\mathbb{Z}$-module of oranges. If you are willing to work in the direct sum module of apples $\oplus$ oranges, you can indeed add apples to oranges.
Now, implicitly in asserting that $\log$ makes sense for objects with units, (and similarly that $\exp$ makes sense for objects of units), it is necessary that we already work in a system, that of the graded $\mathbb{R}$-algebra, in which you can add a scalar (an object with no units) to a vector (some object with units). So in asserting that you want to make sense of $\log km$, you cannot conclude from it that $3$ and $\log m$ must have the same units.
This is a fun question. I have a hard time getting a good grip on the transformation that is $ln$ so I'll write things in terms of exponents.
$$\mathrm{value} = \ln(10\ \mathrm{ km})$$ $$e^{\mathrm{value}} = 10\ \mathrm{ km}$$
The number $e$ is, of course, unit-less. If I raise a number to a power, what are the permissible units of the power? If I write $x^2$, I have an intuitive assumption that $2$ has no units, because it is just a count used to express $x \times x = x^2$.
Thus, I have convinced myself of Carl's answer, and I would require a logarithm to have a reference to make sense. For example:
$$e^{\mathrm{value}} = \frac{ 10\ \mathrm{ km} }{1\ \mathrm{ km}}$$
The previous alternative of $e$ raised to a power equaling a physical quantity with real units seems like the perfect example of something that is nonsensical.
log plots
I have another question that stemmed from your question and I will try to answer it here. I specifically remember taking the derivative of log-log and linear-log plots in engineering classes. We had some justification for that, but it would appear to be nonsensical on the surface, so let's dive in. Here is an example of a log-log plot. I'll show the graph and then offer an equation of the line that is being represented.
Image source: Wikipedia
I'll start writing things from the basic $y=mx+b$ form, then change things as necessary. Since I'm using an arbitrary constant, I'll fudge it whenever necessary.
$$\log(p) = a \log(m) + b = a ( \log(m) + b' ) = a \log( b'' m ) = \log( b''^a m^a ) = \log\bigg( \frac{p_0}{m_0^a} m^a \bigg) $$ $$p = p_0 \left( \frac{m}{m_0} \right)^a$$
Like magic, a recognizable form comes through. Observing a linear relation in a log-log plot really means you're observing a power fit, not a linear fit. A student may still ask "but what are a and b", which is a bit more difficult. Firstly, I did no manipulation of $a$, so you can take the meaning directly from the final form, which is to say it's an exponent and thus unitless. For b:
$$b = a b' = a \log(b'') = a \log\bigg( \frac{p_0^{1/a}}{m_0} \bigg) = \log\left( \frac{p_0}{m_0^a} \right) $$
This shows that $b$ is also unitless, but it also gives interpretation to $p_0$, which is the reference y-value at some reference x-value ($m_0$). I'll move on to linear-log plot, or a semi-log scale.
Image source: J. Exp. Med. 103, 653 (1956).
I'll denote $f$ for "surviving fraction" and $d$ for dose. The equation for a regression that appears linear on the above plot will be the following.
$$\log(f) = a d + b$$ $$f = e^{a d + b} = e^b e^{a d} = f_0 e^{a d}$$
It's important to note here that $b$ had dubious units all along, just like in the log-log case, but it doesn't really matter because a more useful form comes out of the mathematics naturally. The value $f_0$ would be the baseline value (100% in this case) at $d=0$.
Summary: assuming a linear relation in log plots really makes the assumption that the actual relation follows some nonlinear form, and the units will work out once you do the mathematics, but the interpretation of the values may be nontrivial.