Complex integral - winding number 
i want to find $$\frac{1}{2\pi i}\int _\gamma \frac{1}{z}dz$$
well $0$'s winding number is $2$, so $\frac{1}{2\pi i}\int _\gamma \frac{1}{z}dz=2$
but when I explicity calculate the integral I get
$$\frac{1}{2\pi i}\int _\gamma \frac{1}{z}dz=\frac{1}{2\pi i}(\log(z)\lvert ^{z=-1}_{z=3}+\log(z)\lvert ^{z=\sqrt 2}_{z=-1}+\log(z)\lvert ^{z=-\sqrt 5}_{z=\sqrt 2}+\log(z)\lvert ^{z=3}_{z=-\sqrt 5})=\\ \frac{1}{2\pi i}(\log |-1|+i\pi-\log 3+\log \sqrt 2 -\log |-1|-i\pi+\log |-\sqrt 5|+i\pi-\log \sqrt 2  +\\+\log 3-\log |-\sqrt 5|-i\pi)=0$$
whats going on here?
 A: The imaginary part of logarithm increases as you go around the origin.
It is the angle between z and the positive real axis.
As you go around from 3 to -1 to $\sqrt{2}$, that angle increases from 0 to $\pi$ to $2\pi$.  So the imaginary part of $\log(\sqrt{2})$ is $2\pi$.
$\log x$ has lots of complex values, in the same way that $\sqrt{x}$ has two values.  By following the path $\gamma$, you can follow which value is relevant to your problem.
Think of it like a multistory car-part.  Going around the origin puts you on a different level.
A: An exaggerated idea to try to understand a little more that branch cut thingy of the logarithmic function: let us try to divide the given path in several semicircles, say
$$\begin{align*}\gamma_1&:=\{z\in\Bbb C\;;\;|z-1|=2\;,\;\;\text{Im}\,(z)\ge 0\}\\
\gamma_2:&=\left\{z\in\Bbb C\;;\;\left|z-\frac{\sqrt2 -1}2\right|=(\sqrt2-1)^2\;,\;\;\text{Im}\,(z)\le 0\right\}\\
\gamma_3&:=\left\{z\in\Bbb C\;;\;\left|z-\frac{\sqrt2-\sqrt5}2\right|=(\sqrt2-\sqrt5)^2\;,\;\;\text{Im}\,(z)\ge 0\right\}\\
\gamma_3&:=\left\{z\in\Bbb C\;;\;\left|z-\frac{3-\sqrt5}2\right|=(3-\sqrt5)^2\;,\;\;\text{Im}\,(z)\le 0\right\}\end{align*}$$
Now, in each and every case we get
$$\int\frac{dz}z=\text{Log}\,z$$
which makies things pretty simple...but with a catch, as you've been already explained: every time the (complex) logarithm completes a whole "spin" around zero we must add (or substract, depending on the spinning direction) $\,2\pi\,$ to its argument, so (Note: Log denotes the complex logaithm, log the real one):
$$\begin{align*}\int\limits_{\gamma_1}\frac{dz}z&=\text{Log}\,(-1)-\text{Log}\,3=\pi i-\color{red}{\log 3}\\
\int\limits_{\gamma_2}\frac{dz}z&=\text{Log}\,\sqrt2-\text{Log}\,(-1)=\frac12\log2+2\pi i-\pi i=\color{green}{\frac12\log2}+\pi i\\
\int\limits_{\gamma_3}\frac{dz}z&=\text{Log}\,(-\sqrt5)-\text{Log}\,\sqrt2=\frac12\log5+3\pi i-\frac12\log2-2\pi i=\color{blue}{\frac12\log5}-\color{green}{\frac12\log2}+\pi i\\
\int\limits_{\gamma_4}\frac{dz}z&=\text{Log}\,3-\text{Log}\,(-\sqrt5)=\log3+4\pi i-\frac12\log5-3\pi i=\color{red}{\log3}-\color{blue}{\frac12\log5}+\pi i\end{align*}$$
Now add all the above and you get, of course, $\,4\pi i\,$ ...
A: There are a couple of problems.
One problem is in the use of $\log(z)$ for $z\in\mathbb{C}$. $\log(z)$ cannot be defined as a continuous function on all of $\mathbb{C}$. This is part of the reason for the introduction of Riemann Surfaces. Integrating $\frac1z$ along a path that circles the origin once, counter-clockwise gives $2\pi i$; e.g. a unit circle:
$$
\begin{align}
\oint\frac{\mathrm{d}z}{z}
&=\int_0^{2\pi}\frac{\mathrm{d}e^{it}}{e^{it}}\\
&=\int_0^{2\pi}\frac{i\,e^{it}\,\mathrm{d}t}{e^{it}}\\
&=\int_0^{2\pi}i\,\mathrm{d}t\\
&=2\pi i
\end{align}
$$
Another problem is that the contour circles the origin twice in a counter-clockwise direction, so the integral should be $4\pi i$.
A: A related problem. Just note this, we parametrize gamma as $z=re^{i\theta}$
$$\frac{1}{2\pi i}\int_{\gamma}\frac{1}{z}dz = \frac{1}{2\pi i}\int_{0}^{2\pi}e^{-i\theta}ie^{i\theta}d\theta = 1. $$
Added: What's left is just to multiply the answer by 2 to get the desired answer, since your curve encircles the origin twice counter clockwise.
