Tlog implement Psr\Log\LoggerInterface
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
"symfony/console" : "2.1.*",
|
||||
"symfony/event-dispatcher" : "2.1.*",
|
||||
"symfony-cmf/routing" : "1.0.*@dev",
|
||||
"propel/propel1" : "1.6.*"
|
||||
"propel/propel1" : "1.6.*",
|
||||
"psr/log" : "dev-master"
|
||||
},
|
||||
"minimum-stability": "stable"
|
||||
}
|
||||
|
||||
52
core/composer.lock
generated
52
core/composer.lock
generated
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"hash": "2be3cc68d014718aa32d78effb38b917",
|
||||
"hash": "8a668b67ef3c3dd2fe8f426c37b2db5d",
|
||||
"packages": [
|
||||
{
|
||||
"name": "phing/phing",
|
||||
@@ -113,6 +113,44 @@
|
||||
"mapping"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "psr/log",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/log",
|
||||
"reference": "1.0.0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/php-fig/log/archive/1.0.0.zip",
|
||||
"reference": "1.0.0",
|
||||
"shasum": ""
|
||||
},
|
||||
"time": "2012-12-21 11:40:51",
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Psr\\Log\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for logging libraries",
|
||||
"keywords": [
|
||||
"log",
|
||||
"psr",
|
||||
"psr-3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "symfony-cmf/routing",
|
||||
"version": "dev-master",
|
||||
@@ -120,12 +158,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony-cmf/Routing",
|
||||
"reference": "1.0.0-alpha3"
|
||||
"reference": "817b65edad2a4318cffd5017ff7eaabb9f2b65f8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://github.com/symfony-cmf/Routing/archive/1.0.0-alpha3.zip",
|
||||
"reference": "1.0.0-alpha3",
|
||||
"url": "https://github.com/symfony-cmf/Routing/archive/817b65edad2a4318cffd5017ff7eaabb9f2b65f8.zip",
|
||||
"reference": "817b65edad2a4318cffd5017ff7eaabb9f2b65f8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -133,7 +171,7 @@
|
||||
"symfony/routing": ">=2.1,<2.3-dev",
|
||||
"symfony/http-kernel": ">=2.1,<2.3-dev"
|
||||
},
|
||||
"time": "2012-12-16 17:52:57",
|
||||
"time": "2013-01-20 20:39:41",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
@@ -145,6 +183,7 @@
|
||||
"Symfony\\Cmf\\Component\\Routing": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
@@ -554,6 +593,7 @@
|
||||
],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {
|
||||
"symfony-cmf/routing": 20
|
||||
"symfony-cmf/routing": 20,
|
||||
"psr/log": 20
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user