Ejemplo n.º 1
0
 public function __construct(DI $di, $aggregate = true, $formatter = 'line')
 {
     $this->_di = $di;
     $this->_debugbar = $this->_di['debugbar'];
     $this->_formatter = strtolower($formatter);
     if ($di->has('log') && ($log = $di->get('log'))) {
         $debugbar_loger = new Debugbar($di['debugbar']);
         if ($log instanceof Adapter) {
             $di->remove('log');
             $multiple = new Multiple();
             $multiple->push(clone $log);
             $multiple->push($debugbar_loger);
             /** @var DI\Service $service */
             $di->set('log', $multiple);
         } elseif ($log instanceof Multiple) {
             $log->push($debugbar_loger);
         }
         $this->_aggregate = $this->isAggregate($aggregate);
     }
 }
Ejemplo n.º 2
0
 private function loadAdapters(Yaml $config, $level)
 {
     if (self::$Console) {
         $adapters = $this->getAdaptersConsole($config);
     } else {
         $adapters = $this->getAdaptersWeb($config);
     }
     if ($adapters) {
         foreach ($adapters->toArray() as $adapter => $param) {
             $this->logger->push($this->getAdapter($adapter, $param));
         }
     } else {
         //dafault adapters
         $this->logger->push(new FileAdapter('/tmp/ngApp.log'));
         $this->logger->push(new StreamAdapter('php://stdout'));
     }
     foreach ($this->logger->getLoggers() as $logger) {
         $logger->setLogLevel($level);
     }
 }
Ejemplo n.º 3
0
 public static function injectTo(Di $di)
 {
     $di->setShared('logger', function () use($di) {
         $logger = new Multiple();
         $config = $di->get('config')['loggers'];
         foreach ($config as $logConfig) {
             $adapter = $logConfig['adapter'];
             $options = isset($logConfig['options']) ? $logConfig['options'] : null;
             $logger->push(new $adapter($logConfig['name'], $options));
         }
         return $logger;
     });
 }
Ejemplo n.º 4
0
 /**
  * Tests multiple loggers
  *
  * @issue  2798
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2016-01-28
  */
 public function testMultipleLoggers()
 {
     $this->specify("Multiple logging does not works correctly", function () {
         $I = $this->tester;
         $file1 = $I->getNewFileName('log', 'log');
         $file2 = $I->getNewFileName('log', 'log');
         $logger = new Multiple();
         $logger->push(new File($this->logPath . $file1));
         $logger->push(new File($this->logPath . $file2));
         $logger->setFormatter(new Json());
         $logger->log('This is a message');
         $logger->log("This is an error", Logger::ERROR);
         $logger->error("This is another error");
         $expected = sprintf('{"type":"DEBUG","message":"This is a message","timestamp":%s}' . PHP_EOL . '{"type":"ERROR","message":"This is an error","timestamp":%s}' . PHP_EOL . '{"type":"ERROR","message":"This is another error","timestamp":%s}' . PHP_EOL, time(), time(), time());
         $I->amInPath($this->logPath);
         $I->openFile($file1);
         $I->seeFileContentsEqual($expected);
         $I->deleteFile($file1);
         $I->openFile($file2);
         $I->seeFileContentsEqual($expected);
         $I->deleteFile($file2);
     });
 }
Ejemplo n.º 5
0
            $compileAlways = true;
            break;
    }
    $gettext = new Gettext();
    $gettext->setOptions(['compileAlways' => $compileAlways, 'locale' => $locale->getBestLocale(), 'supported' => $locale->getSupportedLocales(), 'domains' => $config->locale->domains, 'localeDir' => $config->path->localeDir, 'localeCacheDir' => $config->path->localeCacheDir]);
    return $gettext;
});
/**
 *
 */
$di->setShared('debug', function () use($di) {
    $config = $di->getConfig();
    $logger = new MultipleStreamLogger();
    switch (ENV) {
        case DEV_ENV:
            $logger->push(new ErrorLogger());
            if ('cli' != php_sapi_name()) {
                $debugLogFile = str_replace('{{name}}', $config->site->domains[0], $config->dev->path->debugLog);
                $fileLogger = new FileLogger($debugLogFile);
                $fileLogger->getFormatter()->setFormat('%message%');
                $logger->push($fileLogger);
                $logger->push(new Firelogger());
                $logger->push(new FirephpLogger(''));
            }
            break;
    }
    return $logger;
});
/**
 * Mail service
 */
Ejemplo n.º 6
0
<?php

use Phalcon\Logger, Phalcon\Logger\Multiple as MultipleStream, Phalcon\Logger\Adapter\File as FileAdapter, Phalcon\Logger\Adapter\Stream as StreamAdapter;
$logger = new MultipleStream();
$logger->push(new FileAdapter('test.log'));
$logger->push(new StreamAdapter('php://stdout'));
$logger->log("This is a message");
$logger->log("This is an error", Logger::ERROR);
$logger->error("This is another error");
Ejemplo n.º 7
0
use PhalconX\Util\Reflection;
use PhalconX\Util\ObjectMapper;
use Phalcon\Mvc\Model\Metadata\Apc as MetadataApc;
use PhalconX\Mvc\Metadata\Memory as MetadataMemory;
use PhalconX\Annotations;
$di = new FactoryDefault();
$di['config'] = $config;
$di['registry'] = new Config();
$di['loader'] = $loader;
$di['logger'] = function () use($config) {
    $isCli = PHP_SAPI == 'cli';
    $prefix = $config->application->logsDir . ($isCli ? 'cli-' : '');
    $logger = new MultipleStream();
    $appender = new FileAppender($prefix . 'error.log');
    $appender->setLogLevel(Logger::ERROR);
    $logger->push($appender);
    $appender = new FileAppender($prefix . 'default.log');
    $appender->setLogLevel(Logger::INFO);
    $logger->push($appender);
    if ($isCli) {
        $appender = new ConsoleAppender('php://stderr');
        $formatter = new LineFormatter("%date% [%type%] %message%\n");
        $appender->setFormatter($formatter);
        $appender->setLogLevel(Logger::ERROR);
        $logger->push($appender);
    }
    return $logger;
};
$di['db'] = function () use($di, $config) {
    Model::setup(['notNullValidations' => false]);
    $conn = new DbAdapter($config->database->toArray());
Ejemplo n.º 8
0
 public function push(AdapterInterface $logger)
 {
     parent::push($logger);
 }