I guess everyone's experience and approach is different. But from my experience, closer to the hog is safer if you're trying to stab it. Closeness is about control.
Hogs (and particularly boars) like distance. They use it to charge at you. They use it to swing around in a slashing motion. If you're close enough they can't do that easily. The 'safe zone' for a hog is immediately behind it, as close to it as possible, and preferably holding onto it to reduce its ability to move. The dogs are also crowding it, holding onto it, reducing its ability to move. At that point you're about as safe as you can be (obviously nothing in this is 100% safe).
Also, the closer you are, the more accurate you are in stabbing it. The idea isn't to poke it repeatedly all over
. It's to hit a very precise location inside its chest cavity. You want it to bleed out as fast as possible, either from the heart or lungs. The whole basis for a safe kill is a quick kill (and therefore an accurate kill). With a knife, you place the point on the exact location you want, and then push. You can't get more accurate than that.
I feel like a spear would only increase the distance (and therefore danger), and reduce your accuracy (and therefore prolong the procedure of dispatching, which also increases danger).
Having said all that, boar spears must exist for a reason.