Intergrals: how to determine what part of the integrand to substitute $u$ into? Take the example: 

Integrate the following:
  $\frac{\ln (x)}{x} dx$

The correct way I've found is to substitute $u$ for $\ln (x)$  and $\frac{1}{ x} dx$ with $du$, therefore:
$\frac{u^2}{ 2}$ or $\frac{(\ln x)^2}{ 2}$ is the answer. 
However, if I try to substitute $x$ with $u$ I can't solve it correctly.
What is a general rule to determine which part of the equation to substitute for $u$ when integrating? 
 A: DonAntonio already posted a fine answer, but I'd like to add the suggestion that you carefully study the substitution rule because understanding what is does can often help to make the right choice:
$$\boxed{\int f\left(g(x)\right)g'(x)\,\mbox{d}x = \int f(u)\,\mbox{d}u}$$
where $u=g(x)$. Now notice:


*

*a (possible) composition of functions $f\left(g(x)\right)$;

*the occurrence of the derivative of the inner function $g'(x)$.


Left to right
Let's emphasize what happens in color, with $\color{blue}{u=g(x)}$ and thus $\color{red}{\mbox{d}u=g'(x)\,\mbox{d}x}$, this reads:
$$\int f\left(\color{blue}{g(x)}\right)\color{red}{g'(x)\,\mbox{d}x} = \int f(\color{blue}{u})\,\color{red}{\mbox{d}u}$$
The substitution rule is often used from left to right, meaning that you have to identify a (good) choice for $u=g(x)$. But the rule tells you what will work out nicely: if you find a composition of functions ($\color{green}{f(g(x))}$) and you have the derivative of the inner function as a factor ($\color{green}{g'(x)}$), then this "inner function" $g(x)$ is a good choice for $u$.
Example
$$\int\frac{\cos x}{\sqrt{\sin x}}\,\mbox{d}x$$
Notice you have a composition of functions $x \mapsto \sin x \mapsto \tfrac{1}{\sqrt{\sin x}}$ where you also have the derivative of the inner function present as a factor: $(\sin x)' = \cos x$.
Looking at the substitution rule, we have $g(x) = \sin x$ and $f(x)=\tfrac{1}{\sqrt{x}}$. A good choice will thus be $\color{blue}{u=\sin x}$, so $\color{red}{\mbox{d}u=\cos x \,\mbox{d}x}$ and the integral becomes:
$$\int\frac{\color{red}{\cos x}}{\sqrt{\color{blue}{\sin x}}}\,\color{red}{\mbox{d}x} \to \int\frac{1}{\sqrt{\color{blue}{u}}}\,\color{red}{\mbox{d}u} = \ldots$$
Your example is a bit simpler in the sense that you don't really see a composition of functions, but of course $f(x)=x$ can be the simplest composition. You still have the derivative of $\ln x$ present as a factor, so picking $u = \ln x$ will work out nicely.

Right to left
The reasoning above works when you apply the rule from left to right with the intent of immediately simplifying the integral. You can be more creative with the substitution rule and sometimes it can be useful to apply it from right to left, thus introducing a new function. A common example is what is called a trig(onometric) substitution for integrals such as:
$$\int \sqrt{1-x^2} \,\mbox{d}x$$
Introducing $x=\sin u$ will allow the use of identities to get rid of the square root.
A: By practice, practice and more practice you get experience and thus you shall be able to recognize patterns. Observe that
$$\frac{\log x}x=\frac1x\cdot\log x=\frac{d}{dx}(\log x)\cdot\log x$$
and now remember that
$$\int f'(x)\cdot f(x)^n\,dx=\frac{f(x)^{n+1}}{n+1}+C$$
so in our case we can see we have an (almost) immediate integral:
$$\int\frac{\log x}xdx=\int(\log x)'\cdot\log x\,dx=\frac{\log^2x}2+C$$
If I can avoid substitutions then I do. This will pay off both in speed and when working with Riemann Integrals, as then we won't have to calculate the new upper and lower limits of the integral.
