Http_log: how to limit the contents of log entries

I want to create log entries for a http server, but limit what the log entry contains. However, http_log/2 seems to always dump the entire text of every Request into the log entry in addition to the specific entry text that I want. I’m obviously doing something wrong, but I’m not sure what that is. Any suggestions?

Here’s the code I use (swipl version 8.0.3):

%... other preamble code, and then...
:- use_module(library(http/http_log)).

% ...later, the handler declaration...
:- http_handler(root(.), frontpage,[prefix]).

%...later still, the handler code...
    frontpage(Request):-
      get_time(T), format_time(atom(D),'%a %F %T %z (%Z)',T),
      member(peer(IP),Request),
      http_log('~w   "/index.html accessed from ~w"',[D,IP]),
      http_reply_file(content('index.html'),[],Request),!.

If you want something completely different I guess you should roll your own log facility. As is, the log infrastructure is based on library(broadcast), a publish/subscribe library. The http_log.pl library listens to HTTP messages and stores them into a file as Prolog terms. If you look in this library you’ll see it defines a couple of multifile predicates that allows you to control which fields of the request are ignored. They are just Prolog rules, so you can easily invert this and only include certain header fields.

If you just want to change the format I guess copying and editing http_log.pl to suit your wishes is the simplest approach.

Personally I’d not merge logging into the HTTP handlers. All you need to know is in the HTTP core broadcast messages and using that information keeps your handlers clean.

1 Like

Thanks, Jan. I’ll have a look at the http_log.pl library (and broadcast, since I don’t understand that yet).

In the meantime, I’m using the debug library for the fine-grained logging at the moment. During development, I actually use the log mostly for debugging anyway, so using debug seems appropriate at this stage.