The problem is this: you know that for $n \neq -1$, the indefinite integral of $x^n$ is equal to $\frac{x^{n+1}}{n+1}$. But this formula can't possibly be valid for $n = -1$ because the denominator vanishes. So instead you have to take the limit. It's easiest to see how this works with the definite integral
$$\int_a^b x^n \, dx = \frac{a^{n+1} - b^{n+1}}{n+1}.$$
If you want to see what happens at $n = -1$, what you do is to take the limit as $n \to -1$. By l'Hopital's rule, remembering that $x^k = e^{k \ln x}$, we find that
$$\lim_{n \to -1} \frac{a^{n+1} - b^{n+1}}{n+1} = \lim_{n \to -1} \frac{a^{n+1} \ln a - b^{n+1} \ln b}{1} = \ln a - \ln b.$$
So that's where the logarithm appears: it naturally comes out of the value of this limit, and in fact this limit can be used to define the logarithm.
More generally speaking, if you have a collection of functions closed under differentiation, you are in no way guaranteed that that collection of functions is also closed under integration. In fact given a class of functions, integration generally gives you new functions not in that class.