The Erdos-Renyi law of large numbers answers this, in a strong sense and even in a more generalized fashion. More recent work in this direction includes papers by Arratia, Gordon, Waterman (see here) and others.
Let $X_1,X_2,\ldots$ be binary i.i.d. with $Pr[X_i=1]=p.$ Define $$ L_n(\theta)=\max\left\{t:\exists i \in \{0,1,\ldots,n-t\},\theta \leq \frac{1}{t}\sum_{k=1}^t X_{i+k}\right\}. $$ Note that this is the density of $1$'s along sequence windows of length $t$ and you are asking about $L_n(\theta)$ for $\theta=1.$
Then for all $\theta \in (p,1]$ we have $$ L_n(\theta)\rightarrow \frac{\log n}{H(\theta,p)} $$ where the binary relative entropy is given by $$ H(\theta,p)=\theta \log(\theta/p)+(1-\theta)\log((1-\theta)/(1-p)), $$ with $H(1,p)=\log(1/p).$ If you put $\theta=p$$\theta=1$ and $p=1/2,$ the denominator is $\log(2)$ and you recover $\log_2 n$ as you surmised.
References:
Erdos, Renyi: On a New Law of Large Numbers. J. Analyse Math. 22, 103–111 (1970)