Download the PHP package lucinda/logging without Composer

On this page you can find all versions of the php package lucinda/logging. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package logging

Logging API

Table of contents:

About

This API is a skeleton (requires binding by developers) logging system built on principles of simplicity and flexibility. Unlike Monolog, the industry standard in our days, it brings no tangible performance penalties and has near-zero learning curve just by keeping complexity to a minimum while offering you the ability to extend functionalities.

diagram

The whole idea of logging is reduced to just three steps:

API is fully PSR-4 compliant, only requiring PHP8.1+ interpreter and SimpleXML extension. To quickly see how it works, check:

  • installation: describes how to install API on your computer, in light of steps above
  • UnitTest API instead of PHPUnit for greater flexibility
  • example: shows a deep example of API functionality based on unit test for Wrapper

All classes inside belong to Lucinda\Logging namespace!

Configuration

To configure this API you must have a XML with a loggers tags inside:

Where:

  • loggers: (mandatory) holds global logging policies.
    • {ENVIRONMENT}: name of development environment (to be replaced with "local", "dev", "live", etc)
      • logger: stores configuration settings for a single logger (eg: file logger)
        • class: (mandatory) full class name of AbstractLoggerWrapper implementation, encapsulating respective logger configuration. Available values:
        • {OPTIONS}: a list of extra attributes necessary to configure respective logger identified by class above:
          • application: (mandatory if Driver\SysLog\Wrapper) value that identifies your site against other syslog lines. Eg: "mySite"
          • format: (mandatory if Driver\SysLog\Wrapper or Driver\File\Wrapper) controls what will be displayed in log line (see: How log lines are formatted). Eg: "%d %v %e %f %l %m %u %i %a"
          • path: (mandatory if Driver\File\Wrapper) base name of file in which log is saved. Eg: "messages"
          • rotation: (optional if Driver\File\Wrapper) date algorithm to rotate log above. Eg: "Y-m-d"
          • any other: if a custom logger is used. Their values are available from argument of setLogger method CLASS will need to implement. (see: How to bind a new logger)

Example:

Binding Points

In order to remain flexible and achieve highest performance, API takes no more assumptions than those absolutely required! It offers developers instead an ability to bind to its prototypes via XML:

XML Attribute @ Tag Class Prototype Ability Gained
class @ logger AbstractLoggerWrapper Registers a logger

API already has following AbstractLoggerWrapper implementation embedded:

But developers can bind their own (check: How to Bind a Custom Logger)

Logging

Now that XML is configured, you can get a logger to save and use later on whenever needed by querying Wrapper:

Logger returned is a AbstractLoggerWrapper whose job is to generate it based on info in XML.

NOTE: because XML parsing is somewhat costly, it is recommended to save $logger somewhere and reuse it throughout application lifecycle.

Installation

First choose a folder where API will be installed then write this command there using console:

Then create a configuration.xml file holding configuration settings (see logging above) in project root with following code:

Above has logged a "test" message with LOG_INFO priority in messages__YYYY-MM-DD.log file if same loggers tag as in example above is used.

Unit Tests

For tests and examples, check following files/folders in API sources:

NOTE: on first run only, test.php will fail on syslog tests but from that moment on it will consistently pass

Reference Guide

Interface Logger

Logger interface provides blueprints for level-oriented logging using following methods:

Method Arguments Returns Description
emergency \Throwable $exception void logs a \Throwable using LOG_ALERT priority
alert \Throwable $exception void logs a \Throwable using LOG_CRIT priority
critical \Throwable $exception void logs a \Throwable using LOG_ERR priority
error \Throwable $exception void logs a \Throwable using LOG_WARNING priority
warning string $message void logs a string using LOG_WARNING priority
notice string $message void logs a string using LOG_NOTICE priority
debug string $message void logs a string using LOG_DEBUG priority
info string $message void logs a string using LOG_INFO priority

Usage example:

https://github.com/aherne/php-logging-api/blob/master/drivers/File/Logger.php

Abstract Class LoggerWrapper

AbstractLoggerWrapper abstract class implements conversion of data in XML to a Logger instance via following public methods:

Method Arguments Returns Description
__construct SimpleXMLElement $xml void Reads XML and delegates to setLogger method
getLogger void Logger Gets Logger generated based on XML

and following prototype method that needs to be implemented by developers:

Method Arguments Returns Description
setLogger SimpleXMLElement $xml void Reads XML and generates a Logger object

Usage example:

https://github.com/aherne/php-logging-api/blob/master/drivers/File/Wrapper.php

Specifications

Some guides helping developers to get the best of this API:

  • How Are Log Lines Formatted
  • How to Bind a Custom Logger

How are log lines formatted

As one can see above, Driver\SysLog\Wrapper support a format attribute whose value can be a concatenation of:

  • %d: current date using Y-m-d H:i:s format.
  • %v: syslog priority level constant value matching to Logger method called.
  • %e: name of thrown exception class ()
  • %f: absolute location of file that logged message or threw a Throwable
  • %l: line in file above where message was logged or Throwable/Exception was thrown
  • %m: value of logged message or Throwable message
  • %e: class name of Throwable, if log origin was a Throwable
  • %u: value of URL when logging occurred, if available (value of $_SERVER["REQUEST_URI"])
  • %a: value of USER AGENT header when logging occurred, if available (value of $_SERVER["HTTP_USER_AGENT"])
  • %i: value of IP when logging occurred, if available (value of $_SERVER["REMOTE_ADDR"])

Example:

How to bind a custom logger

Let us assume you want to bind a new SQL logger to this API. First you need to implement the logger itself, which must extend Logger and implement its required log method:

Now you need to bind logger above to XML configuration. To do so you must create another class extending AbstractLoggerWrapper and implement its required setLogger method:

In that case if "psr-4" attribute in composer.json associates "Lucinda\Project\" with "src/" folder then SQLLoggerWrapper must be placed in src/Loggers folder then you finally need to bind it to XML:


All versions of logging with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1|^8.0
ext-simplexml Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lucinda/logging contains the following files

Loading the files please wait ....