What am I doing wrong with message_hook/3?

message_hook/3 is supposed to intercept calls to print_message/2, thus making it possible to do something before executing print_message. That is how I understand it.

But this did not work with me. I have defined a message_hook for “information” type messages. But the are not intercepted, i.e. if I trace programm execution, message_hook is never called.

Where am I going wrong? What is my misconception? Or is there a bug in my prolog (SWI-Prolog version (threaded, 64 bits, version 8.2.4)?

Indeed, you cannot trace the hook because print_message/2 disables the tracer. Keeping it enabled typically leads to incomprehensible output or non-terminating recursion. Otherwise it should work in just about any version except for the very early ones :slight_smile: Note that the hook must be defined in the user module. If that doesn’t help, please send some code that shows exactly what you are doing.

While checking if message_hook/3 captured certain events I started the following Wiki article for those with same/similar questions.

Using message_hook/3


Thanks for providing all this information. Things do work now as expected. I am happy.