It's a classical exercise to show that a finite group $G$ has a minimal number of generators $\leq \log_2(|G|)$.
Clearly this bound is attained for $(\mathbb{Z}/2\mathbb{Z})^k$ ($k\geq 0$).
Moreover using the structure theorem for abelian groups, one can show that these are the only abelian groups for which this minimal number is exactly $\log_2(|G|)$.
Hence there are two natural questions:
What happens for non-abelian groups ?
And what happens if we loosen the constraint to $\lfloor \log_2(|G|)\rfloor$ in the abelian and non-abelian settings ?
If we stick to $\log_2(|G|)$ it is clear that we're only dealing with $2$-groups. I don't know what more can be said...
I have even less ideas for the second question, because even for abelian groups it seems complicated, let alone nonabelian ones (For instance whenever $G$ is a $2$-group solution to the first question, I think $G\times \mathbb{Z}/3\mathbb{Z}$ is a solution to the second one - EDIT : no this isn't true, as Derek Holt pointed out)
Ideas ?
The minimal number of generators of a finite $p$-group $G$ is $k$, where $p^k$ is the order of the $G/\Phi(G)$, and $\Phi(G)$ is the Frattini subgroup of $G$. Since $\Phi(G)=1 \Leftrightarrow G \cong C_p^k$ for some $k$, it follows that the minimal number is exactly $\log_2 |G|$ if and only if $G \cong C_2^k$. That answers your first question.
I haven't thought about your second question, but I would guess that $C_2^k$ is still the only possibility with $\lfloor \log_2|G|\rfloor$ generators. Your other example does not work because $C_2^k \times C_3 \cong C_2^{k-1} \times C_6$ is $k$-generated.
There is one exception to my guess: the nonabelian group $D_6 \cong S_3$ of order $6$ needs $2$ generators. But I am conjecturing that any other group of order $2^k\times 3$ is $k$-generated.