I was looking at Devel::Messenger this morning. It looks like it does this. You can have debug levels and print certain messages only if debugging is on or above that level. It will print to files\filehandles as well. I haven't tried it yet though.
Error: Keyboard not attached. Press F1 to continue.