TITLE: integration by parts $\int \frac{x^{2}+4x}{x+2}\,dx$
QUESTION [5 upvotes]: $$\int \frac{x^{2}+4x}{x+2}\,dx$$
I have written it in this form:
$$\int \frac{(x+2)^{2}-4}{x+2}\,dx$$: on this stage I try to do integration by parts, which gets me to :
$$\frac{x^{2}}{2}+2x-4\ln\left | {x+2} \right |$$
but it's wrong for some reason. The right answer is : $$\frac{x^{2}+4x+4}{2}-4\ln\left | x+2 \right |$$
Where am I wrong?

REPLY [2 votes]: Also, it should be $$\frac{x^{2}+4x+4}{2}-4\ln\left | x+2 \right |+C_1=\frac{x^{2}+4x+4}{2}-4\ln(x+2)+C_1$$ for $x>-2$ and
$$\frac{x^{2}+4x+4}{2}-4\ln\left | x+2 \right |+C_2=\frac{x^{2}+4x+4}{2}-4\ln(-x-2)+C_2$$ for $x<-2$.