Really hope I'm right coz this took me forever. Also sorry for bad LaTeX.
Let
where
This is easily evaluated depending on the different cases:
If

or

, we have

, if

then

and

, and if

then

and

.
Case 1:

hence

for some constant

.
Evaluating the integral for

, we obtain that:

when

.
Case

or

.
+a^2)\mathrm{d}x = \int_0^{\pi} \mathrm{ln}(1+2\frac{1}{a}\mathrm{cos}(x)+\frac{1}{a^2})\mathrm{d}x + \int_0^{\pi} 2\mathrm{ln}a\mathrm{d}x = 0 + 2\pi \mathrm{ln}(a))
(which follows from Case 1).
)
when

or

.
Case 3:
Let
By symmetry,
Let
By symmetry,
Therefore
 + L)
, so
)
.
Subbing the values back in, we obtain

.
Case 4:
This can be done by the same method as case 3, and so

.
Hence, when

,

, and
)
otherwise.