Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "log4p"

Title:Logging for Prolog
Rating:Not rated. Create the first rating!
Latest version:0.0.2
SHA1 sum:a24d40f2cf68bbaeab7221a6ce8c8dd92a46531c
Author:Phil Hargett <phil@haphazardhouse.net>
Maintainer:Phil Hargett <phil@haphazardhouse.net>
Packager:Phil Hargett <phil@haphazardhouse.net>
Home page:https://github.com/hargettp/log4p


No reviews. Create the first review!.

Details by download location



A simple logging library for Prolog, inspired by log4j.


This is a package for SWI-Prolog, installable using the built-in package manager with the package name log4p.

?- pack_install(log4p).


The basic model for logging involves a few simple concepts.

  • Messages - the basic unit of logging, generally from a single line of code and corresponding to a single line in log output
  • Handlers - messages aren't directly written to output logfiles or destinations, but instead are provided to any each log handler (maintained per-thread) which are predicates that accepts a formatted message and emit the message to the log destination specific to each log handler implementation
  • Levels - messages have a level, and this library maintains a concept of current log level (per-thread) such that messages of a lower level than the current log level are not emitted to any handlers. The log levels understood by this library, in ascending order of priority, are: trace, debug, info, warn, error, fatal. If the current log level is set to info, for example, then message of debug or to further left in that list will not be given to a handler.

    Generating messages is usually a matter of using a number of predicates named for each level: info/1, info/2, warn/1, warn/2 etc. The `/1` variant logs a constant string (or term rendered as a string). The `/2` variant takes a format string and an array of arguments, then calls swritef to generate a constant string which is then passed onto log handlers.

    The current level can be set using the set_log_level/2 predicate, which will also return the previous value.

    To add or remove log handlers, use add_log_handler/1 and remove_log_handler/1 respectively.

Contents of pack "log4p"

Pack contains 5 files holding a total of 5.3K bytes.