Tlog implement Psr\Log\LoggerInterface

This commit is contained in:
Manuel Raynaud
2013-01-20 23:55:18 +01:00
parent 88a82c69d1
commit ad17c5d99e
5 changed files with 175 additions and 126 deletions

View File

@@ -1,44 +0,0 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use \Propel;
class PropelBundle extends Bundle
{
/**
*
* Construct the depency injection builder
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function build(ContainerBuilder $container)
{
Propel::init(THELIA_CONF_DIR . "/config_thelia.php");
}
}

View File

@@ -34,10 +34,25 @@ namespace Thelia\Core;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Thelia\Core\Bundle;
use Propel;
class Thelia extends Kernel
{
public function init()
{
parent::init();
$this->initPropel();
}
protected function initPropel()
{
Propel::init(THELIA_CONF_DIR . "/config_thelia.php");
}
/**
* Initializes the service container.
*
@@ -46,12 +61,27 @@ class Thelia extends Kernel
* The cached version of the service container is used when fresh, otherwise the
* container is built.
*/
protected function initializeContainer()
{
$this->container = $this->buildContainer();
//$this->container->set('kernel', $this);
}
// protected function initializeContainer()
// {
// $class = $this->getContainerClass();
// $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
// $fresh = true;
// if (!$cache->isFresh()) {
// $container = $this->buildContainer();
// $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
//
// $fresh = false;
// }
//
// require_once $cache;
//
// $this->container = new $class();
//
// if (!$fresh && $this->container->has('cache_warmer')) {
// $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
// }
//
// }
/**
* Gets the cache directory.
@@ -91,17 +121,17 @@ class Thelia extends Kernel
*
* @return ContainerBuilder The compiled service container
*/
protected function buildContainer()
{
$container = $this->getContainerBuilder();
$container->set('kernel', $this);
foreach ($this->bundles as $bundle) {
$bundle->build($container);
}
return $container;
}
// protected function buildContainer()
// {
// $container = $this->getContainerBuilder();
// $container->set('kernel', $this);
//
// foreach ($this->bundles as $bundle) {
// $bundle->build($container);
// }
//
// return $container;
// }
/**
* return available bundle
@@ -115,8 +145,7 @@ class Thelia extends Kernel
{
$bundles = array(
/* TheliaBundle contain all the dependency injection description */
new Bundle\TheliaBundle(),
new Bundle\PropelBundle()
new Bundle\TheliaBundle()
);
/**

View File

@@ -23,6 +23,7 @@
namespace Thelia\Log;
use Thelia\Model\ConfigQuery;
use Psr\Log\LoggerInterface;
/**
*
@@ -33,7 +34,7 @@ use Thelia\Model\ConfigQuery;
* @author Franck Allimant <franck@cqfdev.fr>
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class Tlog Implements TlogInterface
class Tlog Implements LoggerInterface
{
// Nom des variables de configuration
const VAR_LEVEL = "tlog_level";
@@ -44,13 +45,26 @@ class Tlog Implements TlogInterface
const VAR_SHOW_REDIRECT = "tlog_show_redirect";
// all level of trace
const TRACE = 100;
const DEBUG = 200;
const WARNING = 300;
const INFO = 400;
const DEBUG = 100;
const INFO = 200;
const NOTICE = 300;
const WARNING = 400;
const ERROR = 500;
const FATAL = 600;
const CRITICAL = 600;
const ALERT = 700;
const EMERGENCY = 800;
const MUET = PHP_INT_MAX;
protected $levels = array(
100 => "DEBUG",
200 => "INFO",
300 => "NOTICE",
400 => "WARNING",
500 => "ERROR",
600 => "CRITICAL",
700 => "ALERT",
800 => "EMERGENCY"
);
// default values
const DEFAULT_LEVEL = self::DEBUG;
@@ -187,65 +201,54 @@ class Tlog Implements TlogInterface
// Methodes d'accès aux traces
// ---------------------------
public function trace()
public function debug($message, array $context = array())
{
if ($this->level > self::TRACE)
return;
$args = func_get_args();
$this->out("TRACE", $args);
$this->log(self::DEBUG, $message, $context);
}
public function debug()
public function info($message, array $context = array())
{
if ($this->level > self::DEBUG)
return;
$args = func_get_args();
$this->out("DEBUG", $args);
$this->log(self::INFO, $message, $context);
}
public function notice($message, array $context = array())
{
$this->log(self::NOTICE, $message, $context);
}
public function info()
public function warning($message, array $context = array())
{
if ($this->level > self::INFO)
return;
$args = func_get_args();
$this->out("INFO", $args);
$this->log(self::WARNING, $message, $context);
}
public function warning()
public function error($message, array $context = array())
{
if ($this->level > self::WARNING)
$this->log(self::ERROR, $message, $context);
}
public function critical($message, array $context = array())
{
$this->log(self::CRITICAL, $message, $context);
}
public function alert($message, array $context = array())
{
$this->log(self::ALERT, $message, $context);
}
public function emergency($message, array $context = array())
{
$this->log(self::EMERGENCY, $message, $context);
}
public function log($level, $message, array $context = array()) {
if($this->level > $level && array_key_exists($level, $this->levels) === false)
return;
$args = func_get_args();
$this->out("WARNING", $args);
$this->out($this->levels[$level], $message, $context);
}
public function error()
{
if ($this->level > self::ERROR)
return;
$args = func_get_args();
$this->out("ERREUR", $args);
}
public function fatal()
{
if ($this->level > self::FATAL)
return;
$args = func_get_args();
$this->out("FATAL", $args);
}
// Mode back office
public static function SetBackOfficeMode($booleen)
@@ -368,14 +371,34 @@ class Tlog Implements TlogInterface
return $origine;
}
protected function interpolate($message, array $context = array())
{
// build a replacement array with braces around the context keys
$replace = array();
foreach ($context as $key => $val) {
$replace['{' . $key . '}'] = $val;
}
private function out($level, $tabargs)
// interpolate replacement values into the message and return
return strtr($message, $replace);
}
private function out($level, $message, array $context = array())
{
$text = '';
foreach ($tabargs as $arg) {
$text .= is_scalar($arg) ? $arg : print_r($arg, true);
/*if (is_array($message)) {
foreach ($message as $arg) {
$text .= is_scalar($arg) ? $arg : print_r($arg, true);
}
} else */ if (is_scalar($message) === false) {
$text = print_r($message, true);
} else {
$text = $message;
}
$text = $this->interpolate($text, $context);
$origine = $this->findOrigin();