Suppose I have a variable $x$ and a constant $a$, each having the dimension of length. That is $[x]=[a]=[L]$ where square brackets denote the dimension of the physical quantity contained within them. 

Now, we wish to take the derivative of $u = log (\frac{x^2}{a^2})-log (\frac{a^2}{x^2})$. Here, we have taken the natural logarithm. It is clear that $u$ is a dimensionless function. 
$$\frac{du}{dx} = \frac{a^2}{x^2}.\frac{2x}{a^2} - \frac{x^2}{a^2}.(-2a^2).\frac{2x}{x^3} \\
= \frac{1}{x} - 4. $$

Here, the dimensions of the two terms on the right do not match. The dimension of the first term is what I expected. Where am I going wrong?