The received wisdom is that pretty well any mathematical statement can in principle be formulated and hence formalised in ZF. I think this is rather an overstatement, but let's bear with it. So in some sense, logic can be viewed as providing a formal foundation for mathematics. However, to do logic rigorously, you need to be able to define and reason about syntax, so a certain amount of mathematics is required to underpin logic. Many people take the view that the finitistic mathematics you need to reason about syntax is sufficiently certain that the apparent circularity is harmless. (Personally, I am agnostic on nearly all such issues.)