- Documentation
- Reference manual
- Packages
- SWI-Prolog HTTP support
- The HTTP server libraries
- Creating an HTTP reply
- library(http/http_dispatch): Dispatch requests in the HTTP server
- library(http/http_dirindex): HTTP directory listings
- library(http/http_files): Serve plain files from a hierarchy
- library(http/http_session): HTTP Session management
- library(http/http_cors): Enable CORS: Cross-Origin Resource Sharing
- library(http/http_authenticate): Authenticate HTTP connections using 401 headers
- library(http/http_digest): HTTP Digest authentication
- library(http/http_dyn_workers): Dynamically schedule HTTP workers.
- Custom Error Pages
- library(http/http_openid): OpenID consumer and server library
- Get parameters from HTML forms
- Request format
- Running the server
- The wrapper library
- library(http/http_host): Obtain public server location
- library(http/http_log): HTTP Logging module
- Debugging HTTP servers
- library(http/http_header): Handling HTTP headers
- The library(http/html_write) library
- library(http/js_write): Utilities for including JavaScript
- library(http/http_path): Abstract specification of HTTP server locations
- library(http/html_head): Automatic inclusion of CSS and scripts links
- library(http/http_pwp): Serve PWP pages through the HTTP server
- The HTTP server libraries
- SWI-Prolog HTTP support
3.17 library(http/http_log): HTTP Logging module
Simple module for logging HTTP requests to a file. Logging is enabled
by loading this file and ensure the setting http:logfile is not the
empty atom. The default file for writing the log is httpd.log
.
See
library(settings)
for details.
The level of logging can be modified using the multifile predicate
http_log:nolog/1 to hide HTTP request
fields from the logfile and
http_log:password_field/1 to hide
passwords from HTTP search specifications (e.g. /topsecret?password=secret
).
- [semidet]http_log_stream(-Stream)
- True when Stream is a stream to the opened HTTP log file.
Opens the log file in
append
mode if the file is not yet open. The log file is determined from the settinghttp:logfile
. If this setting is set to the empty atom (''), this predicate fails.If a file error is encountered, this is reported using print_message/2, after which this predicate silently fails. Opening is retried every minute when a new message arrives.
Before opening the log file, the message
http_log_open(Term)
is broadcasted. This message allows for creating the directory, renaming, deleting or truncating an existing log file. - [det]http_log_close(+Reason)
- If there is a currently open HTTP logfile, close it after adding a term
server(Reason, Time)
. to the logfile. This call is intended for cooperation with the Unix logrotate facility using the following schema:- Move logfile (the HTTP server keeps writing to the moved file)
- Inform the server using an HTTP request that calls http_log_close/1
- Compress the moved logfile
- author
- Suggested by Jacco van Ossenbruggen
- [det]http_log(+Format, +Args)
- Write message from Format and Args to log-stream. See format/2 for details. Succeed without side effects if logging is not enabled.
- [semidet,multifile]password_field(+Field)
- Multifile predicate that can be defined to hide passwords from the logfile.
- [multifile]nolog(+HTTPField)
- Multifile predicate that can be defined to hide request parameters from the request logfile.
- [semidet,multifile]nolog_post_content_type(+Type)
- Multifile hook called with the
Content-type
header. If the hook succeeds, the POST data is not logged. For example, to stop logging anything but application/json messages::- multifile http_log:nolog_post_content_type/1. http_log:nolog_post_content_type(Type) :- Type \= (application/json).
Type is a term MainType/SubType - [det]post_data_encoded(?Bytes:string, ?Encoded:string)
- Encode the POST body for inclusion into the HTTP log file. The POST data is (in/de)flated using zopen/3 and base64 encoded using base64//1. The encoding makes long text messages shorter and keeps readable logfiles if binary data is posted.
- [det]http_logrotate(+Options)
- Rotate the available log files. Note that there are two ways to deal
with the rotation of log files:
- Use the OS log rotation facility. In that case the OS must (1) move
the logfile and (2) have something calling
http_log_close/1 to close
the (moved) file and make this server create a new one on the next log
message. If
library(http/http_unix_daemon)
is used, closing is achieved by sending SIGHUP or SIGUSR1 to the process. - Call this predicate at scheduled intervals. This can be achieved by
calling http_schedule_logrotate/2
in the context of
library(http/http_unix_daemon)
which schedules the maintenance actions.
Options:
- min_size(+Bytes)
- Do not rotate if the log file is smaller than Bytes. The default is 1Mbytes.
- keep_logs(+Count)
- Number of rotated log files to keep (default 10)
- compress_logs(+Format)
- Compress the log files to the given format.
- background(+Boolean)
- If
true
, rotate the log files in the background.
- Use the OS log rotation facility. In that case the OS must (1) move
the logfile and (2) have something calling
http_log_close/1 to close
the (moved) file and make this server create a new one on the next log
message. If
- http_schedule_logrotate(When, Options)
- Schedule log rotation based on maintenance broadcasts. When
is one of:
- daily(Hour:Min)
- Run each day at Hour:Min. Min is rounded to a multitude of 5.
- weekly(Day, Hour:Min)
- Run at the given Day and Time each week. Day is either a number 1..7 (1 is Monday) or a weekday name or abbreviation.
- monthly(DayOfTheMonth, Hour:Min)
- Run each month at the given Day (1..31). Note that not all months have all days.
This must be used with a timer that broadcasts a
maintenance(_,_)
message (see broadcast/1). Such a timer is part oflibrary(http/http_unix_daemon)
.