PHP Classes

XLogger PHP PSR Logger: Log events to browser console, text and XML files

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 104 All time: 9,745 This week: 74Up
Version License PHP version Categories
xlogger 1.0.1Freely Distributable7.4Debug, Console, Logging, PHP 7, PSR
Description 

Author

This package can be used to log events to the current browser console, text and XML files.

It provides support to logging of events with an interface compliant with PSR 3 PHP Standards Recommendation specification.

Currently it can log events using HTTP headers to pass log values to the current browser. The log messages may appear in the console or a separate Window section of the current browser when a specific browser add-on is installed. There are add-ons available for Firefox and Chrome.

It may also output log information to files in plain text or XML formats.

Innovation Award
PHP Programming Innovation award winner
July 2020
Winner


Prize: 1 Year Subscription to NomadPHP Advanced PHP Learning
PSR-3 is a PHP Standards Recommendation that defines an interface for logging application events.

This package implements a PSR-3 compliant logging solution that allows logging PHP application events using HTTP response headers that can be processed by file browser extensions, so PHP developers can see debug information in the browser console.

Manuel Lemos
Picture of Stefan Kientzler
  Performance   Level  
Name: Stefan Kientzler is available for providing paid consulting. Contact Stefan Kientzler .
Classes: 19 packages by
Country: Germany Germany
Age: 57
All time rank: 71946 in Germany Germany
Week rank: 22 Up2 in Germany Germany Up
Innovation award
Innovation award
Nominee: 11x

Winner: 6x

Recommendations

Create a logger to an application
I need a logger class to insert in file or database.

Example

<?php
declare(strict_types=1);

require_once
'autoloader.php';
require_once
'TestClass.php';

use
Psr\Log\LogLevel;
use
Psr\Log\NullLogger;
use
SKien\XLogger\ChromePHPLogger;
use
SKien\XLogger\FileLogger;
use
SKien\XLogger\FirePHPLogger;
use
SKien\XLogger\XLogger;
use
SKien\XLogger\XMLLogger;

$strMessage = '';
$strLink = '';
$logger = new NullLogger();
$strLogger = isset($_GET['logger']) ? strtolower($_GET['logger']) : 'log';
$strLevel = isset($_GET['level']) ? strtolower($_GET['level']) : 'dev';
$level = LogLevel::DEBUG;
switch (
$strLevel) {
    case
'deploy':
       
$level = LogLevel::WARNING;
       
$strMessage = '<br/>Log-Level for Deployment Environment';
        break;
    case
'test':
       
$level = LogLevel::INFO;
       
$strMessage = '<br/>Log-Level for Test Environment';
        break;
    case
'dev':
       
$level = LogLevel::DEBUG;
       
$strMessage = '<br/>Log-Level for Development Environment';
        break;
}
switch (
$strLogger) {
    case
'log':
    case
'csv':
    case
'txt':
       
$logger = new FileLogger($level);
       
$logger->setUser('S./Kien');
       
$logger->setFullpath('test_{date}_{name}.' . $strLogger);
       
$logger->setOptions(XLogger::LOG_BT | XLogger::LOG_USER);
       
$strMessage = 'Logger Output written to ' . $logger->getFilename() . $strMessage;
        break;
    case
'xml':
       
$logger = new XMLLogger($level);
       
$logger->setFullpath('test_{month}.xml');
       
$logger->setXSLFile('XMLLogger.xsl');
       
$logger->setOptions(XLogger::LOG_BT | XLogger::LOG_USER | XLogger::LOG_UA);
       
$logger->setUser('SKien');
       
$strMessage = 'Logger Output written to ' . $logger->getFilename() . $strMessage;
       
$strLink = '<a target="_blank" href="' . $logger->getFilename() . '">View Log</a>';
        break;
    case
'firefox':
       
$logger = new FirePHPLogger($level);
       
$strMessage = 'Logger Output sent to FirePHP Console' . $strMessage;
        break;
    case
'chrome':
       
$logger = new ChromePHPLogger($level);
       
$strMessage = 'Logger Output sent to Chrome Console' . $strMessage;
        break;
}

$logger->error('bad conditions :-(', ['more' => 'just more Information']);
$logger->info('some informations');
$logger->alert('the bell is ringing...' . PHP_EOL . '... its 5 to 12!');
$logger->warning('something gone wrong ;-)');

$oTest = new TestClass();

// nothing will be logged since setLogger() was not called so far... but dont causes any error!');
$oTest->doSomething();

$oTest->setLogger($logger);
$oTest->doSomething();
$oTest->causeException();
?>
<!DOCTYPE html>
<html>
<body>
    <h1>Logger - Example</h1>
    <p><?php echo $strMessage;?></p>
    <p><?php echo $strLink;?></p>
    <form action="XLogTest.php" method="get">
    <label for="logger">Output to:</label>
    <select name="logger" id ="logger">
        <option <?php echo $strLogger == 'log' ? 'selected' : ''; ?> value="log">LOG File</option>
        <option <?php echo $strLogger == 'csv' ? 'selected' : ''; ?> value="csv">CSV File</option>
        <option <?php echo $strLogger == 'txt' ? 'selected' : ''; ?> value="txt">TXT File</option>
        <option <?php echo $strLogger == 'xml' ? 'selected' : ''; ?> value="xml">XML File</option>
        <option <?php echo $strLogger == 'firefox' ? 'selected' : ''; ?> value="firefox">FirePHP-Console</option>
        <option <?php echo $strLogger == 'chrome' ? 'selected' : ''; ?> value="chrome">Chrome-Console</option>
        <option <?php echo $strLogger == 'null' ? 'selected' : ''; ?> value="null">Null-Logger</option>
    </select><br/>
    <label for="level">Environment:</label>
    <select id="level" name="level">
        <option <?php echo $strLevel == 'dev' ? 'selected' : ''; ?> value="dev">Development</option>
        <option <?php echo $strLevel == 'test' ? 'selected' : ''; ?> value="test">Test</option>
        <option <?php echo $strLevel == 'deploy' ? 'selected' : ''; ?> value="deploy">Deploy</option>
    </select><br/>
    <button type="submit">Reload</button>
    </form>
</body>
</html>


Details

XLogger - PSR3 compliant Logging to Browser Console, Text- or XML-File

Latest Stable Version License Minimum PHP Version PHPStan Scrutinizer Code Quality

This package provides PSR-3 compliant Loggers for Output to - Browser Console via FirePHP - Browser Console via Chrome Logger - Plain Text (log, txt, csv) - XML File (can be transformed to HTML with included XSL)

For debugging in particular, it is often very time-saving if the logging output goes directly to the browser console. Since the loggers comply with the PSR-3 specification, they can be used for existing code and there is the possibility to configure the most suitable logger for different scenarios and / or environments (development / test / delpoyment) at runtime.

For more information about the PSR-3 specification visit www.php-fig.org

For logging to the browser console one of the following Add-Ons have to be installed (both are available for Firefox and Chrome): - FirePHP - Chrome Logger

Installation

You can download the Latest Version from PHPClasses.org. The namespaces, class- and filenames meet the PSR-4 autoloader recommendations.

Usage

The use of the available logger classes and the integration of the PSR-3 interfaces / treats can be seen in the examples *XLogTest.phpandTestClass.php*. For XML-HTML Transformation of the XML-Format use Example XSL-Template *XMLLogger.XSL*

FirePHP Add-On

Can be found on www.firephp.org

Chrome Logger Add-On

For Google Chrome can be found on chrome.google.com

For Firefox can be found on addons.mozilla.org


  Files folder image Files (24)  
File Role Description
Files folder imageCCampbell (1 directory)
Files folder imageFirePHP (1 directory)
Files folder imagePsr (1 directory)
Files folder imageSKien (1 directory)
Accessible without login Plain text file autoloader.php Aux. Auxiliary script
Accessible without login Plain text file githubwiki.xml Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation
Accessible without login Plain text file TestClass.php Example Class source
Accessible without login Plain text file XLogTest.php Example Example script
Accessible without login Plain text file XMLLogger.xsl Data Auxiliary data

  Files folder image Files (24)  /  CCampbell  
File Role Description
Files folder imageChromePhp (1 file)

  Files folder image Files (24)  /  CCampbell  /  ChromePhp  
File Role Description
  Plain text file ChromePhp.php Class Class source

  Files folder image Files (24)  /  FirePHP  
File Role Description
Files folder imageCore (2 files)

  Files folder image Files (24)  /  FirePHP  /  Core  
File Role Description
  Plain text file FB.php Class Class source
  Plain text file FirePHP.php Class Class source

  Files folder image Files (24)  /  Psr  
File Role Description
Files folder imageLog (8 files)

  Files folder image Files (24)  /  Psr  /  Log  
File Role Description
  Plain text file AbstractLogger.php Class Class source
  Plain text file InvalidArgumentException.php Class Class source
  Plain text file LoggerAwareInterface.php Class Class source
  Plain text file LoggerAwareTrait.php Class Class source
  Plain text file LoggerInterface.php Class Class source
  Plain text file LoggerTrait.php Class Class source
  Plain text file LogLevel.php Class Class source
  Plain text file NullLogger.php Class Class source

  Files folder image Files (24)  /  SKien  
File Role Description
Files folder imageXLogger (5 files)

  Files folder image Files (24)  /  SKien  /  XLogger  
File Role Description
  Plain text file ChromePHPLogger.php Class Class source
  Plain text file FileLogger.php Class Class source
  Plain text file FirePHPLogger.php Class Class source
  Plain text file XLogger.php Class Class source
  Plain text file XMLLogger.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:104
This week:0
All time:9,745
This week:74Up