How does $\int \tan x dx$ equal to $ \log( \sec x)$? How can the integration result in $\sec x$? What operations are done here?
Well, let $u=\cos x$ then $du=-\sin x \,dx$ so that we get
$$\int \tan x dx=\int\frac{\sin x}{\cos x}dx=\int-\frac{1}{u}du=-\ln|u|+C=-\ln|\cos x|+C$$

$$=\ln|(\cos x)^{-1}|+C=\ln|\sec x|+C$$
Nothing too complicated. It's just an integral substitution: $$\int \frac{\sin(x)}{\cos(x)} \, dx =- \int \frac{d( \cos(x))}{\cos(x)} = -\log\, \cos(x)+C = \log\, \sec(x)+C$$