Is it possible for a valid equation to have different dimension in both sides? Suppose we have the following equation:
$$
\frac{1}{r}\mathrm{d}r=\frac{1}{T}\mathrm{d}T
$$
where $r$ be the distance and $\dim r=L^1$, and T can be the temperature with $\dim T =\Theta^1$.
In this equation, both the LHS and the RHS are Dimensionless, so the equation is legal in physics.
However, if we integrate it, then we have:
$$
\left.\ln r\right|_i^f=\left.\ln T\right|_i^f
$$
where i and f means initial state and final state. Now comes the problem: any expression appeared in $\ln$ should be dimensionless, but this equation doesn't obey the rule.
If we use $\exp$ to fetch out the expression the problem can be bigger, we get $r=T$ while they have different dimension.
What's the problem here?
 A: The expression is still dimensionless, since special functions generally take dimensionless quantities as arguments. You can rewrite the logarithm as
$$
\ln r\Big|_i^f = \ln r_f - \ln r_i = \ln \left(\frac{r_f}{r_i} \right)
$$
which is dimensionless.
For the record the intermediate step might raise some concerns, but as commented by ZeroTheHero you can make the whole procedure rigorous by picking some length scale ($r_0$ and $[r_0]=$ m) and non dimensionalizing the equation
$$
\bar{r} = \frac{r}{r_0} \quad\Rightarrow \quad \mathrm{d}r = r_0\mathrm{d}\bar{r}
$$
which leads to
$$
\frac{1}{r}\mathrm{d}r = \frac{1}{\bar{r}r_0}r_0\mathrm{d}\bar{r} = \frac{\mathrm{d}\bar{r}}{\bar{r}}
$$
so the solution would look like
$$
\ln \bar{r} \Big|_{i}^{f} = \ln \bar{r}_f - \ln \bar{r}_i = \ln\left(\frac{\bar{r}_f}{\bar{r}_i}\right) = \ln\left(\frac{r_f}{r_0}\frac{r_0}{r_i}\right) = \ln\left(\frac{r_f}{r_i}\right)
$$
A: Interesting question. Two ways to look at it:

*

*$\ln T\Big|_i^f = \ln (T_f)-~ \ln(T_i) = \ln \frac{T_i}{T_f}$, which helps a bit but is still perhaps unsatisfying because units shouldn’t depend on form.


*$\ln(\cdot)$ is an exponent and hence is unitless. $\ln(\cdot)$ reports to us what the exponent was. There can never be an incidence in any system (therefore in any equation) in physics where the $\ln$ or $\log_k$ function appears and equality or inequality depends upon units.
For example, using $\exp(\cdot)$ to fetch it out will give the same result in Rankine or Kelvin, because $$\ln(T_{R,f}) - \ln(T_{R,i}) = \ln(T_{K,f})-\ln(T_{K,i})$$ because the exponents differ by the same amount because $\ln(T_R)=\ln(T_K) + c$, where $c$ is a constant.
A: Yes you have spotted an issue which is an example of something much more widely prevalent in mathematics and physics, but which usually gets noticed with the log function first of all.
First of all, let's be clear: the $\ln(x)$ on its own is only well-defined when $x$ is dimensionless.
Let's now consider $\ln(x/y)$. If both $x$ and $y$ are dimensionless then one can write
$$
\ln(x/y) = \ln(x) - \ln(y).
$$
Now it is quite widespread in physics for people to write this same result even when $x$ and $y$ are dimensional quantities. Strictly speaking one ought not to do that unless one warns the reader that one is employing a shorthand for the sake of clarity, and any logs of dimensioned quantities are going to be combined with further logs such that overall the log function will only need to be evaluated on a dimensionless quantity in the end.
Next the question arises, do we find similar issues with other functions? The answer is yes. For example
$$
x^{a/b} = (x^a)^{1/b}
$$
makes sense if $a$ and $b$ are dimensionless, but becomes problematic when $a$ and $b$ are dimensional (how do you raise anything to the power of one kilogram for example?) It turns out that as long as the algebraic manipulations are correct then all such expressions will retain their validity as one works through a sequence of steps, in the sense that one can always recombine the parts of the expression so that dimensionless quantities appear where they ought to. But writers sometimes fail to do this correctly, for example by dropping a constant term. In thermodynamics discussions you often see things like $\ln(V)$ where $V$ is a volume; in electromagnetism you might encounter $\ln(r)$ where $r$ is a distance. In all such cases there is always some other volume or distance or whatever which has been dropped, and really the expression is $\ln(V/V_0)$ or $\ln(r/r_0)$ or whatever.
Postscript
Let's see now how this issue could go by 'under the radar' and not be noticed by many working scientists. It is because when we evaluate something like
$$
\ln(T_1) - \ln(T_2)
$$
where $T_1$ and $T_2$ are temperatures then as long as we use the same units for both then it will be ok. Here is why. Let $T_0$ be a temperature equal to 1 kelvin. Let $y_1$ and $y_2$ be dimensionless numbers such that
$$
T_1 = y_1 T_0, \;\;\;\;\; T_2 = y_2 T_0
$$
Then
$$
\ln(T_1) - \ln(T_2) = \ln(y_1) + \ln(T_0) - \ln(y_2) - ln(T_0) \\
= \ln(y_1) - \ln(y_2) + \ln(T_0/T_0)
= \ln(y_1) - \ln(y_2).
$$
In this sequence of steps, only the expressions on the second line are strictly legal with all parameters of functions dimensionless. When evaluating the first expression the unsuspecting scientist might think they are evaluating first $\ln(T_1)$ and then $\ln(T_2)$ and then taking the difference. They are not. The numbers they actually enter into their calculator or computer are not $T_1$ and $T_2$ but $y_1$ and $y_2$, and they take the logs of those. It works as long as they have used the same units for both temperatures, since then the final term $\ln(T_0 /T_0) = 0$.
A: (Original answer below the line was more mechanical in how the operations work out.  Edit at the top addresses some theoretical issues.)
Empirically we have identified certain "dimensions" like length, time, and mass that correspond to phenomena in the world.  Historically, we assigned "units" so that we could compare information about those dimensions.  Later we understood that there are fundamental constants of nature that are themselves measurable.  The constants provide relationships between units that, historically, we said belonged to different dimensional quantities.  For example $c = 3 \times 10^8\ \mathrm{m/s}$ (up to some rounding that's beside the point for now).  That's a relationship between one constant and two units.
You could take a different perspective on that equation, however, and think of it as one equation for three unknowns.  That let's us eliminate one unknown, but we're stuck with two that physics doesn't (apparently) uniquely determine.  From this perspective those are real numbers in an equation, they are just not numbers that we can uniquely determine.  So we have to carry them around as appropriate multiplicative factors in expressions.
Now look at something like $\log(5\ \mathrm{m})$.  For a lot of good reasons we usually do NOT want to write a log with a unit like that.  But it's not ill-defined mathematically as 5 is clearly a real number and, as above, we can think of $\mathrm{m}$ as a real (but unknown) number as well.  We also know that it's not zero from the equation and by convention we choose both it and $\mathrm{s}$ to be positive.  So, from that perspective, we don't know what specific numerical value to assign to $\log(5\ \mathrm{m})$ but we should expect that it has some value and that, more importantly for your original question, that it obeys the usual rules of log.
Once we accept that it obeys the usual rules of log, then your problem about inconsistent dimensions on the two sides of your equations goes away via a cancelation. Now follows the original answer that get's specific in how that plays out for a sample calculation of differences of log.

(Original answer)
You need to get consistency of units.  With the logarithm that can happen in two ways.  One way is that the argument is unitless and then the log of that is also unitless.  That can happen with a ratio of two values that have units or because you started with values that had no units somehow.
For simplicity of explanation, we usually say that the arguments to the log must be dimensionless, but that's not quite precise. (Though if you ensure it, then you are always good, which why it's stated as the "rule".)
If you want to be general, the unit, is essentially a constant multiplicative factor, so several of the answers are wrongly stating things about expression of the form $\log (x/y) = \log x - \log y$.  This is well-formed even when the variables represent dimensionful quantities.
For example, assume they are lengths, and pick some numbers for a sample calculation.  Then, e.g.,
$$ \log(5\ \mathrm{m} / 2\ \mathrm{m}) = \left[ \log(5) - \log (2)) \right] + \left[ \log(\mathrm{m}) -  \log(\mathrm{m}) \right] =  \log(5) - \log (2)) $$
So you get the same answer whether you cancel the units in the expression all the way on the left "first" or if you carry them through the middle expression, so long as you are consistent.
Technically this even works if you use different units for length, but then you have some nasty expressions involving logs of units that don't cancel:
$$ \log(5\ \mathrm{m} / 2\ \mathrm{mm}) = \left[ \log(5) - \log (2)) \right] + \left[ \log(\mathrm{m}) -  \log(\mathrm{mm}) \right] \neq  \log(5) - \log (2)) $$
So in practice we usually ensure that this doesn't happen.  It's not wrong per se, but it's practically useless.  Note that you can still work through the mixed-form in a consistent manner though.
You could do it the conventional way:
$$ \log(5\ \mathrm{m} / 2\ \mathrm{mm}) = \log(5000\ \mathrm{mm} / 2 \ \mathrm{mm}) = \log(5000/2) = \log 5000 - \log 2 $$
Or equally well:
$$ \begin{align} 
\left[ \log(5) - \log (2)) \right] + \left[ \log(\mathrm{m}) -  \log(\mathrm{mm}) \right]
& = \left[ \log(5) - \log (2)) \right] + \left[ \log(1000\ \mathrm{mm}) -  \log(\mathrm{mm}) \right] \\
& = \log 5 - \log 2 + \log 1000 = \log 5000 - \log 2 
\end{align} $$
