I am talking here about war crimes committed by individuals or units (i.e., not representing a deliberate government/military policy), such as, e.g., the My Lai Massacre during the Vietnam war. One could argue that such things inevitably happen in war, where one's perception of reality is affected by fear, witnessing murder, losing friends, etc. Shooting of a captured Germany soldier in "Fury" gives a fictional but vivid account of how committing a war crime can seem justified and necessary, with the risk of prosecution seeming too remote to be seriously taken into account (especially as compared to other risks).
Moreover, as My Lai Massacre has shown, the army environment gives fertile ground to such behavior: via attitudes like "shoot first, ask later", difficulty of reporting crimes over the heads of hierarchy, and the secrecy and military hierarchy easing cover-up attempts.
What are the measures put in place by modern militaries to reduce the risk of such events taking place and/or ensuring that they are properly reported and prosecuted? Have there been specific changes implemented in the wake of Vietnam, or similar (though smaller scale) events in Afghanistan or Iraq (see Kandahar massacre, Haditha massacre, as well as United States war crimes)?
Naively, one could imagine observer units, not directly subject to the local chain of command - but I cannot see how one could guarantee their security and thus independence on the very troops/officers that they are supposed to observe and report on.