The brain builds a predictive model out of its experiences in order to save energy. Logic is the the consciously directed continuation of that process. Using patterns and input to build other patterns of what we might expect. It is all grounded by experience;experience. And the brain notices patterns within experience and tries to predict. We can then test some things empirically/experimentally and update our patterns/model/logic.
I am coming from an empiricist perspective and using some neuroscience that David Eagleman talks about https://youtu.be/5ok2ejw8d8c?t=3144 (need to watch more of the whole talk to see his fuller depiction of the brain). Everything we know about the world comes from senses that feed into the brain.