Пример #1
0
 public function testWriteByName()
 {
     $base = LITHIUM_APP_PATH . '/resources/tmp/logs';
     $this->skipIf(!is_writable($base), "{$base} is not writable.");
     Logger::config(array('default' => array('adapter' => 'File', 'timestamp' => false, 'priority' => false)));
     $this->assertFalse(file_exists($base . '/info.log'));
     $this->assertFalse(Logger::write('info', 'Message line 1'));
     $this->assertFalse(file_exists($base . '/info.log'));
     $this->assertTrue(Logger::write(null, 'Message line 1', array('name' => 'default')));
     $expected = "Message line 1\n";
     $result = file_get_contents($base . '/.log');
     $this->assertEqual($expected, $result);
     unlink($base . '/.log');
 }
Пример #2
0
 public function testIntegrationWriteFile()
 {
     $config = array('default' => array('adapter' => 'File'));
     Logger::config($config);
     $result = Logger::write('default', 'Message line 1');
     $this->assertTrue(file_exists(LITHIUM_APP_PATH . '/resources/tmp/logs/default.log'));
     $expected = "Message line 1\n";
     $result = file_get_contents(LITHIUM_APP_PATH . '/resources/tmp/logs/default.log');
     $this->assertEqual($expected, $result);
     $result = Logger::write('default', 'Message line 2');
     $this->assertTrue($result);
     $expected = "Message line 1\nMessage line 2\n";
     $result = file_get_contents(LITHIUM_APP_PATH . '/resources/tmp/logs/default.log');
     $this->assertEqual($expected, $result);
     unlink(LITHIUM_APP_PATH . '/resources/tmp/logs/default.log');
 }
 public function testWriteFilter()
 {
     $base = Libraries::get(true, 'resources') . '/tmp/logs';
     $this->skipIf(!is_writable($base), "Path `{$base}` is not writable.");
     Filters::apply('lithium\\analysis\\Logger', 'write', function ($self, $params, $chain) {
         $params['message'] = 'Filtered Message';
         return $chain->next($self, $params, $chain);
     });
     $config = array('default' => array('adapter' => 'File', 'timestamp' => false, 'format' => "{:message}\n"));
     Logger::config($config);
     $result = Logger::write('info', 'Original Message');
     $this->assertTrue(file_exists($base . '/info.log'));
     $expected = "Filtered Message\n";
     $result = file_get_contents($base . '/info.log');
     $this->assertEqual($expected, $result);
     unlink($base . '/info.log');
 }
Пример #4
0
 public function testMultipleAdaptersWriteByNameSecondary()
 {
     $base = Libraries::get(true, 'resources') . '/tmp/logs';
     $this->skipIf(!is_writable($base), "Path `{$base}` is not writable.");
     Logger::config(array('default' => array('adapter' => 'File', 'file' => function ($data, $config) {
         return "{$data['priority']}_default.log";
     }, 'timestamp' => false, 'format' => "{:message}\n"), 'secondary' => array('adapter' => 'File', 'file' => function ($data, $config) {
         return "{$data['priority']}_secondary.log";
     }, 'timestamp' => false, 'format' => "{:message}\n")));
     $this->assertFalse(file_exists($base . '/info_secondary.log'));
     $this->assertTrue(Logger::write('info', 'Secondary Message line 1', array('name' => 'secondary')));
     $this->assertTrue(file_exists($base . '/info_secondary.log'));
     $expected = "Secondary Message line 1\n";
     $result = file_get_contents($base . '/info_secondary.log');
     $this->assertEqual($expected, $result);
     unlink($base . '/info_secondary.log');
 }
Пример #5
0
 public function testConfiguration()
 {
     $loggers = Logger::config();
     $result = isset($loggers['syslog']);
     $this->assertTrue($result);
 }
Пример #6
0
<?php
/**
 * Filter to log queries and trace back information to your browser console.
 * You will need the Firefox plugin "Firebug" or Google Chrome.
 *
 */

use \lithium\data\Connections;
use \lithium\analysis\Logger;
use \lithium\template\View;

Logger::config(array(
    'default' => array('adapter' => 'File')
));

/**
 * Log all queries passed to the MongoDB adapter.
 */
$MongoDb = Connections::get('default');
$MongoDb->applyFilter('read', function($self, $params, $chain) use (&$MongoDb) {
    $result = $chain->next($self, $params, $chain);

    if (method_exists($result, 'data')) {
        /*Logger::write('info',
            json_encode($params['query']->export($MongoDb) + array('result' => $result->data()))        );  
            */
            //var_dump($params['query']->export($MongoDb) + array('result' => $result->data()));
       
  		$view = new View(array('loader' => 'Simple', 'renderer' => 'Simple'));
  		echo $view->render(array('element' => '<script type="text/javascript">console.dir({:data});</script>'), array(
      		'data' => json_encode(array_filter($params['query']->export($MongoDb)) + array_filter(array('result' => $result->data())))
Пример #7
0
<?php

use lithium\analysis\Logger;
Logger::config(array('default' => array('adapter' => 'Syslog'), 'badnews' => array('adapter' => 'File', 'priority' => array('emergency', 'alert', 'critical', 'error'))));
Пример #8
0
<?php

/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2013, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */
use lithium\core\Libraries;
use lithium\core\ErrorHandler;
use lithium\action\Response;
use lithium\net\http\Media;
use lithium\analysis\Logger;
ErrorHandler::apply('lithium\\action\\Dispatcher::run', array(), function ($info, $params) {
    if (preg_match('/not found/i', $info['exception']->getMessage())) {
        $code = 404;
    } else {
        $code = $info['exception']->getCode() == 404 ? 404 : 500;
    }
    $response = new Response(array('request' => $params['request'], 'status' => $code));
    Media::render($response, compact('info', 'params'), array('library' => true, 'controller' => '_errors', 'template' => $code == 404 ? 'fourohfour' : 'fiveohoh', 'layout' => 'default', 'request' => $params['request']));
    return $response;
});
Logger::config(['default' => ['adapter' => 'File', 'path' => dirname(Libraries::get(true, 'path')) . '/log', 'timestamp' => '[Y-m-d H:i:s]', 'file' => function ($data, $config) {
    return 'app.log';
}, 'priority' => ['debug', 'error', 'notice', 'warning']]]);
Пример #9
0
 /**
  * Test if the configuration is correctly set in the logger.
  */
 public function testConfiguration()
 {
     $loggers = Logger::config();
     $this->assertArrayHasKey('firephp', $loggers);
 }
Пример #10
0
<?php

use lithium\analysis\Logger;
use lithium\core\Libraries;
// Again, like sessions.php this will allow other libraries to
// set Logger confiurations without them being overwritten here.
$config = Logger::config();
$config += array('default' => array('adapter' => 'File', 'priority' => array('debug', 'alert', 'error')));
Logger::config($config);
Пример #11
0
<?php

/**
 * First, import the relevant Lithium core classes.
 */
use lithium\core\ErrorHandler;
use lithium\core\Environment;
use lithium\action\Response;
use lithium\net\http\Media;
use lithium\analysis\Logger;
use lithium\analysis\Debugger;
use lithium\analysis\Inspector;
/**
 * Then, set up a basic logging configuration that will write to a file.
 */
Logger::config(array('error' => array('adapter' => 'File')));
/**
 * Error handling for twig templates. The same code is not used on every template because the
 * lithium templates can contain view related php code (like the ini_set-s)
 */
ErrorHandler::apply('lithium\\action\\Dispatcher::run', array(), function ($info, $params) {
    if ($params['request']->type() != "html") {
        return;
    }
    $response = new Response(array('request' => $params['request']));
    ini_set('highlight.string', '#4DDB4A');
    ini_set('highlight.comment', '#D42AAE');
    ini_set('highlight.keyword', '#D42AAE');
    ini_set('highlight.default', '#3C96FF');
    ini_set('highlight.htm', '#FFFFFF');
    $exception = $info['exception'];
Пример #12
0
<?php

use lithium\analysis\Logger;
Logger::config(array('default' => array('adapter' => 'File', 'priority' => array('debug', 'alert', 'error'))));