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.10
SHA1 sum:56797a6a9b3a656d3999bba0cf5df9543f24e6ea
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
Download URL:https://github.com/hargettp/log4p/releases/*.zip
Provides:logger

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
0.0.1056797a6a9b3a656d3999bba0cf5df9543f24e6ea5https://github.com/hargettp/log4p/archive/refs/tags/v0.0.10.zip
0.0.962624b63d46057e76ae85616612801ad707f8b521107https://github.com/hargettp/log4p/archive/refs/tags/v0.0.9.zip
0.0.7909dcee11eb86e1aaa3ccd09effddfbbb932e0253https://github.com/hargettp/log4p/archive/v0.0.7.zip
0.0.59553076da778b8b0fec99bcda59f00523655086c10https://github.com/hargettp/log4p/archive/v0.0.5.zip
0.0.483cc5a08f3d0de14feb73977644eaef83c1bda194https://github.com/hargettp/log4p/archive/v0.0.4.zip
0.0.2a24d40f2cf68bbaeab7221a6ce8c8dd92a46531c137https://github.com/hargettp/log4p/archive/v0.0.2.zip

Log4p

A simple logging library for Prolog, inspired by log4j.

Installation

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

?- pack_install(log4p).

Use

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, informational, notice, warning, error, critical, alert, emergency. These levels follow the RFC 5424 severity levels for syslog compatibility.

    Legacy aliases: For backward compatibility, the following legacy aliases are still available:

    • info → informational
    • warn → warning
    • fatal → emergency

    If the current log level is set to informational, 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: trace/1, debug/1, informational/1, notice/1, warning/1, error/1, critical/1, alert/1, emergency/1, and their `/2` variants for formatted logging. 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. If the currently effective log level for the calling thread is not equal to or "higher" (e.g., more to the right in the above list of log levels), then the message will be filtered out and not delivered to any handlers.

    The legacy aliases (info/1,2, warn/1,2, fatal/1,2) are also available and map to their RFC 5424 equivalents.

The effective log level is a layered per-thread choice, depending on which settings are specified:

  • default_log_level : the log4p library defines info as the log level to assume if no other setting has been specified for the current thread.
  • global_log_level: any configured global level overrides the default for all threads, new or existing. A global setting remains in place until its cleared with clear_global_log_level.
  • local_log_level: if a level has been specified for the current thread, then this value will override any global setting, even if the global value is later changed. Using clear_local_log_level will remove any local setting, thus resetting the thread's level to either the global or default level. The current level can be set using the any of the following techniques:

    Log handlers disseminate messages to an output desintation, such as stdout or stderr or a log file. To add or remove log handlers, use add_log_handler/1 and remove_log_handler/1 respectively. A log handler is a simple function that simply takes 2 arguments: the level of the message, and the message etc. (after formatting).

Contents of pack "log4p"

Pack contains 12 files holding a total of 28.4K bytes.