A generalized shadowing lemma