GithubHelp home page GithubHelp logo

christophwurst / lognormalizer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from interfasys/lognormalizer

0.0 2.0 0.0 32 KB

Converts variables to String for easy logging

License: GNU Affero General Public License v3.0

PHP 100.00%

lognormalizer's Introduction

Log Normalizer

Scrutinizer Code Quality Code Climate Build Status Code Coverage

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

Based on the Monolog formatter/normalizer.

How to use

Initialisation in your class

use InterfaSys\LogNormalizer\Normalizer;

$normalizer = new Normalizer();

The constructor supports the following optional arguments

  • 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

/**
 * 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

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

Convert a single variable to a string

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

lognormalizer's People

Contributors

oparoz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.