Using a Gaussian randomization technique, we prove that a random variable $X$ with values in a Banach space $B$ satisfies the (compact) law of the iterated logarithm if and only if (i) $E(\|X\|^2/LL\|X\|) < \infty$, (ii) $\{|\langle x^\ast, X \rangle |^2; x^\ast \in B^\ast, \|x^\ast\| \leq 1\}$ is uniformly integrable and (iii) $S_n(x)/a_n\rightarrow 0$ in probability. In particular, if $B$ is of type 2, in order that $X$ satisfy the law of the iterated logarithm it is necessary and sufficient that $X$ have mean zero and satisfy (i) and (ii). The proof uses tools of the theory of Gaussian random vectors as well as by now classical arguments of probability in Banach spaces. It also sheds some light on the usual law of the iterated logarithm on the line.