The usual error term in this problem is not $O(X^{1/2} \log (qX))$ but $O(X^{1/2} \log^2(X))$. This version of the result is part of Corollary 13.8 in Montgomery-Vaughan: Multiplicative number theory I. For a more general result (also featuring the slightly weaker error term above) see Theorem 5.15 in Iwaniec-Kowalski: Analytic number theory.