Logarithmic bounds for Roth's theorem via almost-periodicity