Output @warn/@debug messages only when traversing (#14047)

Change-Id: I19e0ab9f0e87c23f7eddded317b806dda015e41f