I often seem to get caught out when integrating $1/x$ to $\log x$, or similar. Here's an example -- solve $$ \frac{\mathrm{d}z}{\mathrm{d}x} + \frac{1}{2}z = \frac{1}{2}$$
My first attempt was using separation of variables, which proceeds as follows: $$ \frac{\mathrm{d}z}{\mathrm{d}x} = - \frac{1}{2} (z-1)$$ $$ \int \frac{1}{z-1}\mathrm{d}x = - \frac{1}{2} $$ $$ \log |z-1| = - \frac{1}{2}x + c_1$$ $$ |z-1| = c_2 e^{- x/2}$$
but the text I'm following has $z = c_2 e^{- \frac{1}{2}x} + 1$. This is found fairly easily through integration by parts, using an integrating factor of $p = \exp(\int \mathrm{d}x/2) = \exp(x/2)$. $$ \frac{\mathrm{d}z}{\mathrm{d}x}e^{x/2} + \frac{1}{2}ze^{x/2} = \frac{1}{2}e^{x/2}$$ $$ \frac{\mathrm{d}}{\mathrm{d}x} (ze^{x/2}) = \frac{1}{2}e^{x/2} $$ $$ ze^{x/2} = e^{x/2} + c_2 $$ $$ z = c_2 e^{-x/2} + 1 $$
Obviously, if I ignore the modulus signs in the first case, the first and second answers are exactly the same. Alternatively if I proceed using the integrating factor approach the issue doesn't arise. Neither approach seem very satisfactory though. What am I missing, and any advice from experience as to how to minimize the pain in addressing these kinds of problems?