\[ \int (a g+b g x)^2 \left (A+B \log \left (e \left (\frac {a+b x}{c+d x}\right )^n\right )\right ) \, dx \]
Optimal antiderivative \[ \frac {B \left (-a d +b c \right )^{2} g^{2} n x}{3 d^{2}}-\frac {B \left (-a d +b c \right ) g^{2} n \left (b x +a \right )^{2}}{6 b d}+\frac {g^{2} \left (b x +a \right )^{3} \left (A +B \ln \! \left (e \left (\frac {b x +a}{d x +c}\right )^{n}\right )\right )}{3 b}-\frac {B \left (-a d +b c \right )^{3} g^{2} n \ln \! \left (d x +c \right )}{3 b \,d^{3}} \]
command
integrate((b*g*x+a*g)**2*(A+B*ln(e*((b*x+a)/(d*x+c))**n)),x)
Sympy 1.10.1 under Python 3.10.4 output
\[ \text {Timed out} \]
Sympy 1.8 under Python 3.8.8 output
\[ \begin {cases} a^{2} g^{2} x \left (A + B \log {\left (e \left (\frac {a}{c}\right )^{n} \right )}\right ) & \text {for}\: b = 0 \wedge d = 0 \\A a^{2} g^{2} x + A a b g^{2} x^{2} + \frac {A b^{2} g^{2} x^{3}}{3} + \frac {B a^{3} g^{2} n \log {\left (\frac {a}{c} + \frac {b x}{c} \right )}}{3 b} + B a^{2} g^{2} n x \log {\left (\frac {a}{c} + \frac {b x}{c} \right )} - \frac {B a^{2} g^{2} n x}{3} + B a^{2} g^{2} x \log {\left (e \right )} + B a b g^{2} n x^{2} \log {\left (\frac {a}{c} + \frac {b x}{c} \right )} - \frac {B a b g^{2} n x^{2}}{3} + B a b g^{2} x^{2} \log {\left (e \right )} + \frac {B b^{2} g^{2} n x^{3} \log {\left (\frac {a}{c} + \frac {b x}{c} \right )}}{3} - \frac {B b^{2} g^{2} n x^{3}}{9} + \frac {B b^{2} g^{2} x^{3} \log {\left (e \right )}}{3} & \text {for}\: d = 0 \\a^{2} g^{2} \left (A x - \frac {B c n \log {\left (c + d x \right )}}{d} + B n x \log {\left (a \right )} - B n x \log {\left (c + d x \right )} + B n x + B x \log {\left (e \right )}\right ) & \text {for}\: b = 0 \\A a^{2} g^{2} x + A a b g^{2} x^{2} + \frac {A b^{2} g^{2} x^{3}}{3} + \frac {B a^{3} g^{2} n \log {\left (\frac {a}{c + d x} + \frac {b x}{c + d x} \right )}}{3 b} + \frac {B a^{3} g^{2} n \log {\left (\frac {c}{d} + x \right )}}{3 b} - \frac {B a^{2} c g^{2} n \log {\left (\frac {c}{d} + x \right )}}{d} + B a^{2} g^{2} n x \log {\left (\frac {a}{c + d x} + \frac {b x}{c + d x} \right )} + \frac {2 B a^{2} g^{2} n x}{3} + B a^{2} g^{2} x \log {\left (e \right )} + \frac {B a b c^{2} g^{2} n \log {\left (\frac {c}{d} + x \right )}}{d^{2}} - \frac {B a b c g^{2} n x}{d} + B a b g^{2} n x^{2} \log {\left (\frac {a}{c + d x} + \frac {b x}{c + d x} \right )} + \frac {B a b g^{2} n x^{2}}{6} + B a b g^{2} x^{2} \log {\left (e \right )} - \frac {B b^{2} c^{3} g^{2} n \log {\left (\frac {c}{d} + x \right )}}{3 d^{3}} + \frac {B b^{2} c^{2} g^{2} n x}{3 d^{2}} - \frac {B b^{2} c g^{2} n x^{2}}{6 d} + \frac {B b^{2} g^{2} n x^{3} \log {\left (\frac {a}{c + d x} + \frac {b x}{c + d x} \right )}}{3} + \frac {B b^{2} g^{2} x^{3} \log {\left (e \right )}}{3} & \text {otherwise} \end {cases} \]