Does the logarithm of a non-dimensionless quantity make any sense? 
A train consists of an engine and $n$ trucks. It is travelling along a straight horizontal section of track. The mass of the engine and of each truck is $M$. The resistance to motion of the engine and of each truck is $R$, which is constant. The maximum power at which the engine can work is $P$.
The train starts from rest with the engine working at maximum power. Obtain an expression for the time $t$ taken to reach a given speed $v$.

I wrote
$$a(t)=\frac{P}{v(t)M(n+1)}-\frac{R}{M} \tag{1}$$
Putting $(1)$ into standard differential form:
$$[M(n+1)v]dv+[(Rv(n+1)-P)]dt=0 \tag{2}$$
Since $(2)$ is non-exact, let $$M(n+1)v=f(v) \tag{3}$$
and $$(Rv(n+1)-P)=g(v) \tag{4}$$
Since $$\frac{1}{g}\left(\frac{\partial f}{\partial t}-\frac{\partial g}{\partial v}\right)=\frac{R(n+1)}{P-Rv(n+1)}=h(v) \tag{5}$$ i.e. a function of $v$ only.
The integrating factor to $(2)$ is then given by:
$$I(v)=e^{\int h(v)dv}=e^{-\ln(P-Rv(n+1))}=\frac{1}{P-Rv(n+1)} \tag{6}$$
The final solution then looks something like this $$M(n+1)\left[\frac{-Rv(n+1)-P\ln(P-Rv(n+1))+P\ln(P)}{R^2(n+1)^2}\right]-t=0 \tag{7}$$
But doesn't the argument of $\ln()$ have to be some dimensionless quantities for it to make sense? (I got $\ln(P)$ and $P$ is not dimensionless in this case.)
Can someone please explain where my conceptual errors lie?
 A: 
$$I(v)=e^{\int h(v)dv}=e^{-\ln(P-Rv(n+1))}=\frac{1}{P-Rv(n+1)} \tag{6}$$

If $v$ is has non-trivial dimensions, then $\int \frac{1}{v} dv = \ln\left|\frac{v}{D}\right|$, where $D$ is equivalent to $e^{-C}$ in the dimensionless case: $\int \frac{1}{x} dx = \ln\left|x\right| + C = \ln\left|x\right| - \ln e^{-C}$.
If $v$ is in $\left.\mathrm{m}\middle/\mathrm{s}\right.$, for example, we could write:
$$\int \frac{1}{v} dv = \ln\left|\frac{v}{1\ \left.\mathrm{m}\middle/\mathrm{s}\right.}\right| + C$$
A: In equation (7) you have the expression
$$−P\ln(P−Rv(n+1))+P\ln(P)$$
But since this a difference between two logarithms
you can rewrite the expression 
(remember $\ln a - \ln b = \ln \frac ab$) as
$$P\ln\left(\frac{P}{P−Rv(n+1)}\right)$$
Now you have the logarithm of a dimension-less quantity,
as it should be.
A: The reason behind this problem is that you've not yet simplified the final expression.
For example, let's suppose you get a term $\ln (f(v))$ in your final indefinite integral, where $f(v)$ has dimensions and isn't dimensionless. This is, as you noted, weird as a logarithm's arguments should always be dimensionless. But, now if you apply the limits, you get
$$\ln(f(v))\biggr|_{v_1}^{v_2} = \boxed{\ln\left(\frac{f(v_1)}{f(v_2)}\right)}$$
Now, as you see, the boxed expression is perfectly valid. The argument in the logarithm is, as expected, dimensionless. So, there will never be a case where you'd encounter an expression like $\ln(\text{quantity with dimension})$ if you apply the limits and then analyze the expression.
A: Yes, you can take the logarithm of a dimension.  It's basically the same thing as taking the square of a dimension: it's mathematically valid and makes sense, but, obviously, it's not generally equivalent to the dimension itself.  For example, both $\mathrm{K}^2$ and $\ln{\left(\mathrm{K}\right)}$ make sense, but neither is equivalent to $\mathrm{K} .$
If you get stuck, you can remember that
$$
\ln{\left(ab\right)}
~=~
\ln{\left(a\right)} + \ln{\left(b\right)}
\,,
$$
so you can rewrite any log of a scalar-dimension-having quantity as
$$
\ln{\left(x\right)}
~=~
\underbrace{\ln{\left(\frac{x}{\operatorname{dim}{\left(x\right)}}\right)}}_{\begin{array}{c}\text{dimensionless}\\[-25px]\text{factor}\end{array}}
~+~
\underbrace{\ln{\left(\operatorname{dim}{\left(x\right)}\right)}}_{\begin{array}{c}\text{isolated}\\[-25px]\text{units}\end{array}}
\,.
$$
The resulting math works like always, where the general rule's that both sides of an equation must be equal for the equation to hold.  So if you end up with
$$
1 + \ln{\left(\mathrm{K}\right)}
=
2 + \ln{\left(\mathrm{K}\right)} - 1
\,,
$$
that's perfectly legal, as the $`` \ln{\left(\mathrm{K}\right)} "$ cancels out on both sides, satisfying the equality.  Of course, if the units don't cancel, then there's a dimensional error.
Note that the heuristic against adding terms with differing dimensions no longer holds.  That heuristic only works when valid modes of constructing sums with terms of differing dimensions are avoided, which isn't the case here.  This may lead to confusion in non-technical settings.  For example, probably don't want to present a PowerPoint in a business meeting that refers to $`` 100 + \ln{\left(\mathrm{USD}\right)} ";$ the math can be useful if you're doing calculations, but some folks find it confusing.
A: You can fix this ex post as some answers pointed out, but what you really want to do if you don't want to do fancy stuff with dimensions is to fix it ex ante or rather convince yourself that you could fix it ex ante and then work the simple way.
Let's look at a definition of the logarithm that clearly doesn't allow arguments which carry a dimension, namely $$\ln x\equiv \int^x_1 \frac{du}{u}.$$  It clearly doesn't make sense for an $x$ that is not dimensionless because then the upper and lower limit would have different dimensions.  Imagine writing a Riemann sum for this.
So what happens when we evaluate a logarithmic integral involving dimensions on both limits (dimension $D$, say)?  Let's take our integral to be $\int_{aD}^{bD} du/u$ with $a,b$ real numbers, and the dimension made explicit.  Using straightforward substitution $u\to vD$ we can move the dimension from the limits into the integrand and see that
$$
\int_{a D}^{b D} \frac{d u}{u} = \int_{a}^{b} \frac{D d v}{v D} = \int_a^b \frac{dv}{v},
$$
i.e. the dimension disappears from the integral.  We can continue evaluating
$$
\int_a^b \frac{dv}{v} = \ln\frac{b}{a} = \ln\frac{bD}{aD},
$$
(reinserting the dimension trivially by multiplying by $1=D/D$) and then use the last equality to define
$$ \ln bD - \ln aD =: \ln\frac{b}{a},$$
and then we recover (formally) the usual antiderivative relation, independent on whether $u$ has a dimension or not
$$ \int \frac{du}{u} = \ln u + C.$$
Once we did this, doing the calculation using antiderivatives without first taking care of the dimensions is justified.
I will say that I found this one of the most fascinating properties of logarithms when I first stumbled over this in my undergraduate studies.  You cannot do something similar for the sine function, say.  The logarithm in a way is the ideal power, and its habit of eating up dimensions allows it to appear in places where no other functions can appear out of symmetry reasons.  This is something theoretical particle physicists who are evaluating scattering amplitudes using ever-more complex integrals know all too well.
A: It amazes me that people think that (1) the argument to the log function can't have units and (2) that physical scientist have been playing fast and loose with mathematics for centuries. The Log is the integral of $dx/x$. An integral is an infinite sum so to determine the resulting units we only need to know the units of one term (since all other terms must have the same units to allow for their summation). So the units of log are the units of $dx/x$. $dx$ has the same units as x therefore the ratio is unitless and therefore the log is also unitless. There is absolutely nothing mathematically incorrect about taking the log of a quantity with units, and the result is always unitless. That is intrinsic to the mathematics of a log. However, that means that the Log is a lossy function. There is no way to recover the units once you take the log and, for example, $10^{\log(x)} != x$ if $x$ had units. (There is not all that uncommon in mathematics, that the inverse doesn’t perfectly recover the original value, for example $\sqrt{x^2} != x$ for all $x$.)
