2017 © Pedro Peláez
 

library logging

Logging for the XP Framework

image

xp-framework/logging

Logging for the XP Framework

  • Saturday, January 20, 2018
  • by thekid
  • Repository
  • 2 Watchers
  • 0 Stars
  • 41,697 Installations
  • PHP
  • 15 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 10 Versions
  • 9 % Grown

The README.md

Logging

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.0+ Supports PHP 8.0+ Latest Stable Version, (*1)

Logging for the XP Framework., (*2)

Example

use util\log\Logging;
use lang\Throwable;
use peer\ConnectException;

$logger= Logging::named('service')->toConsole();
$logger->info('Starting application');

try {
  $service->operation();
} catch (ConnectException $e) {
  $logger->warn('Service not available', $e);
} catch (Throwable $t) {
  $logger->error('Error during service invocation', $t);
}

Levels

This library supports the following levels: DEBUG, INFO, WARN and ERROR. As seen above, messages can be logged using methods named after these levels. All methods have a printf-style variant:, (*3)

  • debug(var... $args) and debugf(string $format, var... $args).
  • info(var... $args) and infof(string $format, var... $args).
  • warn(var... $args) and warnf(string $format, var... $args).
  • error(var... $args) and errorf(string $format, var... $args).

Appenders

The following appenders are available:, (*4)

  • util.log.FileAppender(string $filename) - Logs to a local file
  • util.log.ConsoleAppender() - Logs to console
  • util.log.ColoredConsoleAppender() - Logs to console using colors depending on log level
  • util.log.SmtpAppender(string $email, string $prefix= "", bool $sync= true) - Logs by email to a given email address
  • util.log.StreamAppender(io.streams.OutputStream $out) - Logs to any output stream from io.streams.
  • util.log.SyslogAppender(string $identifier, int $facility= LOG_USER) - Logs using syslog facility
  • util.log.SyslogUdpAppender(string $ip= '127.0.0.1', int $port= 514, string $identifier= null, int $facility= LOG_USER, string $hostname= null) - Logs using syslog protocol over UDP
  • util.log.BufferedAppender() - Logs to a memory buffer

Layout

The default log layout includes time, pid, level and message implemented by the util.log.layout.DefaultLayout class. It renders as follows:, (*5)

[13:43:39  4368  info] Starting application

The log layout can be changed by instantiating the util.log.layout.PatternLayout, passing a format string and using the appenders setLayout() method to use it. The format string consists of format tokens preceded by a percent sign (%) and any other character. The following format tokens are supported:, (*6)

  • %m - Message
  • %c - Category name
  • %l - Log level - lowercase
  • %L - Log level - uppercase
  • %d - Date in YYYY-MM-DD
  • %t - Time in HH:MM:SS
  • %p - Process ID
  • %% - A literal percent sign (%)
  • %n - A line break
  • %x - Context information, if available

Configuration

Instead of using the Logging DSL to create your log setup programmatically, you can use the configuration API, which works with INI files:, (*7)

[default]
uses=console|syslog|files

[console]
class=util.log.ConsoleAppender
level=ALL

[files]
class=util.log.FileAppender
args="/var/log/server.log"
level=ALL

[syslog]
class=util.log.SyslogUdpAppender
args=127.0.0.1|514|server
level=WARN|ERROR

Further reading

The Versions

20/01 2018

dev-master

9999999-dev http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

20/01 2018

v8.1.0

8.1.0.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

29/05 2017

v8.0.0

8.0.0.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

28/08 2016

v7.1.0

7.1.0.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

21/02 2016

v7.0.0

7.0.0.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

11/01 2016

v6.6.0

6.6.0.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

20/12 2015

v6.5.1

6.5.1.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

27/09 2015

v6.5.0

6.5.0.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

22/08 2015

v6.4.3

6.4.3.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

22/08 2015

v6.4.2

6.4.2.0 http://xp-framework.net/

Logging for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp