示例#1
0
 /**
  * {@inheritdoc}
  */
 public function handle(array $record)
 {
     $message = Logger::interpolate($record['message'], $record['context']);
     if ($record['level'] != LogLevel::INFO) {
         $message = '[' . $record['level'] . '] ' . $message;
     }
     if (Logger::compare($record['level'], LogLevel::ERROR) >= 0) {
         $this->shell->error($message);
     } else {
         $this->shell->put($message);
     }
 }
示例#2
0
文件: LoggerTest.php 项目: jivoo/core
 public function testAddHandler()
 {
     $handler = $this->getMockForAbstractClass('Jivoo\\Log\\HandlerBase', [LogLevel::INFO]);
     $handler->expects($this->exactly(3))->method('handle');
     $log = new Logger();
     $log->emergency('foo1');
     $log->alert('foo2');
     $log->debug('foo3');
     $log->addHandler($handler);
     $log->info('foo4');
     $log->debug('foo5');
 }
示例#3
0
文件: example1.php 项目: jivoo/data
<?php

// Example: Using dynamic table definitions
use Jivoo\Data\Database\DatabaseDefinitionBuilder;
use Jivoo\Data\Database\DatabaseSchema;
use Jivoo\Data\Database\Loader;
use Jivoo\Data\DefinitionBuilder;
use Jivoo\Log\CallbackHandler;
use Jivoo\Log\Logger;
// Include Jivoo by using composer:
require '../vendor/autoload.php';
// Initialize database loader
$loader = new Loader();
// Log database queries to output
$logger = new Logger();
$logger->addHandler(new CallbackHandler(function (array $record) {
    if (isset($record['context']['query'])) {
        echo 'query: ' . $record['context']['query'] . PHP_EOL;
    }
}));
$loader->setLogger($logger);
// Initialize definition for User-table
$definition = new DatabaseDefinitionBuilder();
$definition->addDefinition('User', DefinitionBuilder::auto(['username', 'created']));
// Connect to database
$schema = new DatabaseSchema($loader->connect(['driver' => 'PdoMysql', 'server' => 'localhost', 'username' => 'jivoo', 'database' => 'jivoo'], $definition));
echo '<pre>';
// Get data for root user:
print_r($schema->User->where('username = %s', 'root')->first()->getData());
// List names of users created after 2015-01-01
$users = $schema->User->where('created > %d', '2015-01-01')->orderBy('created');
示例#4
0
 /**
  * Format a log message for a log file.
  *
  * @param array $record
  *            Log message array.
  * @return string Formatted log message followed by a line break.
  */
 public static function format(array $record)
 {
     $seconds = (int) $record['time'];
     $millis = floor(($record['time'] - $seconds) * 1000);
     $timestamp = date('Y-m-d H:i:s', $seconds);
     $timestamp .= sprintf('.%03d ', $millis);
     $timestamp .= date('P');
     $level = '[' . $record['level'] . ']';
     $message = '';
     $message .= Logger::interpolate($record['message'], $record['context']);
     if (isset($record['context']['file'])) {
         $message .= ' in ' . $record['context']['file'];
     }
     if (isset($record['context']['line'])) {
         $message .= ' on line ' . $record['context']['line'];
     }
     return $timestamp . ' ' . $level . ' ' . $message . PHP_EOL;
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function accepts($level)
 {
     return Logger::compare($level, $this->level) >= 0;
 }