2017 © Pedro Peláez
 

library lognormalizer

Parses variables and converts them to string so that they can be logged

image

interfasys/lognormalizer

Parses variables and converts them to string so that they can be logged

  • Saturday, August 1, 2015
  • by interfaSys
  • Repository
  • 2 Watchers
  • 1 Stars
  • 102,331 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 11 % Grown

The README.md

Log Normalizer

Scrutinizer Code Quality Code Climate Build Status Code Coverage, (*1)

Parses variables and converts them to string so that they can be logged, (*2)

Based on the Monolog formatter/normalizer., (*3)

How to use

Initialisation in your class

use InterfaSys\LogNormalizer\Normalizer;

$normalizer = new Normalizer();

The constructor supports the following optional arguments, (*4)

  • int $maxRecursionDepth: The maximum depth at which you want to go in objects and arrays
  • int $maxArrayItems: The maximum number of elements you want to show, when parsing an array or an object
  • string $dateFormat: The format to apply to dates

Format variables before logging them

This is what your logging function could look like, (*5)

/**
 * Converts the variables in the received log message to string before
 * sending everything to the real logger
 *
 * @param string $level
 * @param string $message
 * @param array $variables
 *
 * @return mixed
 */
public function log($level, $message, array $variables= []) {
    array_walk($variables, [$this->normalizer, 'format']);

    // Then use your current PSR-3 compatible logging system
    $this->logger->log($level, $message, $variables);
}

And you would call it like this from another class, (*6)

$myLogger->log('debug',
    'Logger test {var1}, {var2}',
    [
        'var1' => $var1,
        'var2' => $var2
        ]
);

Convert a single variable to a string

$normalizedVariable = $this->normalizer->format($variable);

The Versions

01/08 2015

dev-master

9999999-dev https://github.com/interfasys/lognormalizer

Parses variables and converts them to string so that they can be logged

  Sources   Download

AGPL-3.0

The Requires

  • php >=5.4.0

 

The Development Requires

log normalizer

01/08 2015

v1.0

1.0.0.0 https://github.com/interfasys/lognormalizer

Parses variables and converts them to string so that they can be logged

  Sources   Download

AGPL-3.0

The Requires

  • php >=5.4.0

 

The Development Requires

log normalizer