Let $f(x) = 2x$ and $g(x) = \log x$ where the domain of $f(x)$ is $\mathbb R$ and of $g(x)$ is $\mathbb R^+$. Now if we compose the functions to get $$f\circ g(x)= 2\log x = \log x^2$$
So now I know the domain is $\mathbb R^+$ but what if I wanted to define the domain to be $\mathbb R$ if we first evaluate $\log x$ adn then multiply it by $2$ we don't always get a real number. However if we square $x$ first we always do get a real number. My question is why does this happen? Is this logarithm rule defined for positive $x$ only because the proof does not require any constraints on $x$.
Proof $$y = k\log x$$ $$\iff e^y = e^{k\log x}$$ $$\iff e^y = x^k $$ $$\iff y =\log x^k$$
Is there something that I'm missing that would explain why the composite function acts this way?