4.11 Printing messages
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Printing messages
          • print_message/2
          • print_message_lines/3
          • message_hook/3
          • thread_message_hook/3
          • message_property/2
          • message_line_element/2
          • message_prefix_hook/2
          • message_to_string/2
          • version/0
          • version/1
          • Printing from libraries
    • Packages
Availability:built-in
Sourceprint_message(+Kind, +Term)
The predicate print_message/2 is used by the system and libraries to print messages. Kind describes the nature of the message, while Term is a Prolog term that describes the content. Printing messages through this indirection instead of using format/3 to the stream user_error allows displaying the message appropriate to the application (terminal, logfile, graphics), acting on messages based on their content instead of a string (see message_hook/3) and creating language specific versions of the messages. See also section 4.11.1. The following message kinds are known:
banner
The system banner message. Banner messages can be suppressed by setting the Prolog flag verbose to silent.
debug(Topic)
Message from library(debug). See debug/3.
error
The message indicates an erroneous situation. This kind is used to print uncaught exceptions of type error(Formal, Context). See section introduction (section 4.11). An error message causes the process to halt with status 1 if the Prolog flag on_error is set to halt and the message is not intercepted by message_hook/3. Not intercepted error messages increment the errors key for statistics/2.
help
User requested help message, for example after entering‘h' or‘?' to a prompt.
information
Information that is requested by the user. An example is statistics/0.
informational
Typically messages of events and progress that are considered useful to a developer. Such messages can be suppressed by setting the Prolog flag verbose to silent.
silent
Message that is normally not printed. Applications may define message_hook/3 to act upon such messages.
trace
Messages from the (command line) tracer.
warning
The message indicates something dubious that is not considered fatal. For example, discontiguous predicates (see discontiguous/1). A warning message causes the process to halt with status 1 if the Prolog flag on_warning is set to halt and the message is not intercepted by message_hook/3. Not intercepted warning messages increment the warnings key for statistics/2.

The predicate print_message/2 first translates the Term into a list of‘message lines' (see print_message_lines/3 for details). Next, it calls the hook message_hook/3 to allow the user to intercept the message. If message_hook/3 fails it prints the message unless Kind is silent.

The print_message/2 predicate and its rules are in the file <plhome>/boot/messages.pl, which may be inspected for more information on the error messages and related error terms. If you need to write messages from your own predicates, it is recommended to reuse the existing message terms if applicable. If no existing message term is applicable, invent a fairly unique term that represents the event and define a rule for the multifile predicate prolog:message//1. See section 4.11.1 for a deeper discussion and examples.

See also message_to_string/2.