generalize trace logging mechanism