When configuring adapters, you may specify one or more priorities for each, using the 'priority' key. This key can be a single priority level (string), or an array of multiple levels. When a log message is written, all adpaters that are configured to accept the priority level with which the message was written will receive the message. {{{ Logger::config(array( 'default' => array('adapter' => 'Syslog'), 'badnews' => array( 'adapter' => 'File', 'priority' => array('emergency', 'alert', 'critical', 'error') ) )); }}} In the above configuration, all messages will be written to the system log (syslogd), but only messages with the priority error or higher will be logged to a file. Messages can then be written to the log(s) using the write() method: {{{ Logger::write('alert', 'This is an alert-level message that will be logged in 2 places'); }}} Messages can also be written using the log priorty as a method name: {{{ Logger::alert('This is an alert-level message that will be logged in 2 places'); }}} This works identically to the above. The message priority levels which Logger supports are as follows: emergency, alert, critical, error, warning, notice, info and debug. Attempting to use any other priority level will raise an exception. See the list of available adapters for more information on what adapters are available, and how to configure them.
See also: lithium\analysis\logger\adapter
Inheritance: extends lithium\core\Adaptable
示例#1
0
 public static function initLogger()
 {
     Logger::applyFilter('write', function ($self, $params, $chain) {
         static::$_data['log'][] = array('priority' => $params['priority'], 'message' => $params['message']);
         return $chain->next($self, $params, $chain);
     });
 }
示例#2
0
 public function generatePassword($entity)
 {
     $newPassword = substr(md5(rand() . rand()), 0, 8);
     $entity->prv_secret = Password::hash($newPassword);
     Logger::debug("New Password for " . $entity->prv_uid . ": {$newPassword} (hash: {$entity->prv_secret})");
     return $newPassword;
 }
示例#3
0
 /**
  * Tests the correct writing to the cache adapter. In this test we use the
  * "Memory" cache adapter so that we can easily verify the written message.
  */
 public function testWrite()
 {
     $message = "CacheLog test message...";
     $result = Logger::write('info', $message, array('name' => 'cachelog'));
     $this->assertNotEmpty($result);
     $result = CacheStorage::read('cachelog', 'cachelog_testkey');
     $this->assertEqual($message, $result);
 }
示例#4
0
 public static function __callStatic($priority = 'debug', $params = array())
 {
     $trace = Debugger::trace(array('format' => 'array', 'depth' => 3, 'includeScope' => false));
     $trace = $trace[2];
     if (empty($trace)) {
         throw UnexpectedValueException('Could not trace method');
     }
     $trace = array('method' => $trace['functionRef'], 'line' => $trace['line'], 'file' => $trace['file']);
     $message = "//////////// {$trace['file']}:{$trace['line']} -> {$trace['method']} ////////////\n";
     foreach ($params as $param) {
         $dump = Debugger::export($param);
         $message = "{$message}{$dump}\n";
     }
     return parent::write($priority, $message);
 }
 /**
  * Tests the writing mechanism. At first, no Response object is bound to the logger, so
  * it queues up the messages. When the Response object finally gets bound, it flushes the
  * needed headers and all messages at once. All messages coming after this point get added
  * to the header immediately.
  */
 public function testWrite()
 {
     $response = new Response();
     $result = Logger::write('debug', 'FirePhp to the rescue!', array('name' => 'firephp'));
     $this->assertTrue($result);
     $this->assertFalse($response->headers());
     $host = 'meta.firephp.org';
     $expected = array("X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2", "X-Wf-1-Plugin-1: http://{$host}/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3", "X-Wf-1-Structure-1: http://{$host}/Wildfire/Structure/FirePHP/FirebugConsole/0.1", "X-Wf-1-1-1-1: 41|[{\"Type\":\"LOG\"},\"FirePhp to the rescue!\"]|");
     Logger::adapter('firephp')->bind($response);
     $this->assertEqual($expected, $response->headers());
     $result = Logger::write('debug', 'Add this immediately.', array('name' => 'firephp'));
     $this->assertTrue($result);
     $expected[] = 'X-Wf-1-1-1-2: 40|[{"Type":"LOG"},"Add this immediately."]|';
     $this->assertEqual($expected, $response->headers());
 }
 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');
 }
示例#8
0
 public function login()
 {
     $result = Auth::check($this->request->adapter, $this->request);
     $redirectUrl = $this->request->env('HTTP_REFERER') ?: '/';
     if ($result) {
         # Convert array to identity object
         if ($this->request->adapter === 'password') {
             $result = Identities::find($result['_id']);
         }
         $session_data = array();
         $new_session = uniqid();
         if (isset($result['session']['id'])) {
             $session_data['id'] = (array) $result['session']['id']->data();
         } else {
             $session_data['id'] = array();
         }
         // Remember users for two weeks
         $session_data['expires'] = time() + \app\util\Config::get('session_length', 7) * 24 * 60 * 60;
         array_push($session_data['id'], $new_session);
         setcookie('session.id', $new_session, $session_data['expires'], '/', $_SERVER['HTTP_HOST']);
         $result->save(array('session' => $session_data));
         Auth::set('any', $result);
     } else {
         $addendum = '';
         // Adapter-specific error messages
         if ($this->request->adapter == 'phpbb') {
             if (Session::read('non_linked_phpbb_login')) {
                 Session::delete('non_linked_phpbb_login');
                 $addendum = 'You are logged into the forums, but there is no leagues account associated with with your forum account.';
             } else {
                 $addendum = 'Please ensure that you are logged into the <a href="http://www.afdc.com/forum/">forums</a>.';
             }
         } else {
             Logger::debug("Failed login for " . $this->request->data['email'] . " with password " . $this->request->data["password"]);
         }
         $error_message = 'Your login was unsuccessful. ';
         if (isset($addendum) and !empty($addendum)) {
             $error_message .= "<br />{$addendum}`<br />";
         }
         $error_message .= 'If you\'re having trouble, checkout the <a href="/help/login">login instructions</a>.';
         $this->flashMessage($error_message, array('alertType' => 'error'));
     }
     return $this->redirect($redirectUrl);
 }
示例#9
0
 public function perform()
 {
     Logger::debug(json_encode($this->args));
     Logger::debug('performed');
 }
示例#10
0
 /**
  * Logs a SQL statement somewhere.
  *
  * @param string $sql The SQL to be executed.
  * @param array $params The SQL parameters.
  * @param float $executionMS The microtime difference it took to execute this query.
  * @return void
  */
 public function logSQL($sql, array $params = null, $executionMS = null)
 {
     Logger::write('debug', $sql);
 }
示例#11
0
 protected function _respond($channels, $responses)
 {
     if (empty($responses)) {
         return;
     }
     foreach ($channels as $channel) {
         Logger::debug('Responding with ' . count($responses) . " message(s) to channel `{$channel}`:");
         foreach ((array) $responses as $response) {
             if ($this->_write('PRIVMSG', $command = "{$channel} :{$response}")) {
                 $this->_process(":{$this->_nick}!@localhost PRIVMSG {$command}\r\n");
             }
         }
     }
 }
示例#12
0
 public function testWrite()
 {
     $result = Logger::write('syslog', 'SyslogTest message...');
     $this->assertTrue($result);
 }
示例#13
0
<?php

use lithium\analysis\Logger;
Logger::config(array('default' => array('adapter' => 'Syslog'), 'badnews' => array('adapter' => 'File', 'priority' => array('emergency', 'alert', 'critical', 'error'))));
示例#14
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']]]);
示例#15
0
文件: Debug.php 项目: alkemann/AL13
 /**
  * Dump
  *
  * @param mixed $var
  * @param array $options
  */
 public function dump($var, $options = array())
 {
     $options += self::$defaults + array('split' => false, 'trace' => false);
     $this->options = $options;
     $this->current_depth = 0;
     $this->object_references = array();
     if (!$options['trace']) {
         $options['trace'] = debug_backtrace();
     }
     extract($options);
     $location = $this->location($trace);
     $dump = array();
     if ($options['split'] && is_array($var)) {
         $this->current_depth = 0;
         foreach ($var as $one) {
             $dump = array_merge($dump, array($this->dump_it($one), ' - '));
         }
         $dump = array_slice($dump, 0, -1);
     } else {
         $dump[] = $this->dump_it($var);
     }
     switch ($mode) {
         case 'FirePHP':
             $locString = \al13_debug\util\adapters\FirePHP::locationString($location);
             require_once LITHIUM_LIBRARY_PATH . '/FirePHPCore/FirePHP.class.php';
             $firephp = \FirePHP::getInstance(true);
             if (!$firephp) {
                 throw new \Exception('FirePHP not installed');
             }
             $firephp->group($locString, array('Collapsed' => false, 'Color' => '#AA0000'));
             $f = function ($o) use($firephp, &$f) {
                 if (is_array($o)) {
                     foreach ($o as $r) {
                         $f($r);
                     }
                 } else {
                     $firephp->log($o);
                 }
             };
             $f($dump);
             $firephp->groupEnd();
             return;
             break;
         case 'Json':
             $locString = \al13_debug\util\adapters\Json::locationString($location);
             $this->output[] = array('location' => $locString, 'dump' => $dump);
             break;
         case 'Log':
             $locString = \al13_debug\util\adapters\Log::locationString($location);
             \lithium\analysis\Logger::debug($locString . "\n" . implode("\n", $dump));
             return;
             break;
         case 'Html':
         default:
             $locString = \al13_debug\util\adapters\Html::locationString($location);
             $this->output[] = '<div class="debug-dump"><div class="debug-location">' . $locString . '</div>' . '<div class="debug-content"> ' . implode("<br>\n", $dump) . '</div></div>';
             break;
     }
     if ($options['echo']) {
         $this->__out();
     }
 }
示例#16
0
 /**
  * allows ajaxified upload of files
  *
  * @see
  * @filter
  * @param array $options [description]
  * @return [type] [description]
  */
 protected function _upload(array $options = array())
 {
     $defaults = array('allowed' => '*', 'path' => Libraries::get(true, 'resources') . '/tmp/cache', 'prefix' => __FUNCTION__, 'chmod' => 0644);
     $options += $defaults;
     if (!$this->request->is('ajax')) {
         return array('error' => 'only ajax upload allowed.');
     }
     if (empty($_GET['qqfile'])) {
         sscanf(str_replace('?', ' ', $this->request->env('REQUEST_URI')), '%s qqfile=%s', $t, $file);
     } else {
         $file = $_GET['qqfile'];
     }
     $pathinfo = pathinfo($file);
     $name = $pathinfo['filename'];
     $type = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';
     if (!in_array($type, (array) $options['allowed']) && $options['allowed'] != '*') {
         $error = 'file-extension not allowed.';
         return compact('error', 'name', 'type');
     }
     $tmp_name = tempnam($options['path'], $options['prefix']);
     $input = fopen('php://input', 'r');
     $temp = fopen($tmp_name, 'w');
     $size = stream_copy_to_stream($input, $temp);
     @chmod($tmp_name, $options['chmod']);
     fclose($input);
     $msg = sprintf('upload of file %s.%s to %s', $name, $type, $tmp_name);
     $complete = (bool) ($size == (int) $_SERVER['CONTENT_LENGTH']);
     if (!$complete) {
         $msg = $error = $msg . ' failed.';
     } else {
         $msg = 'succesful ' . $msg;
         $error = UPLOAD_ERR_OK;
     }
     $data = compact('error', 'name', 'type', 'size', 'tmp_name');
     $priority = $complete ? 'debug' : 'warning';
     Logger::write($priority, $msg);
     return $data;
 }
 public function create()
 {
     // TODO: Use Minerva's access system (li3_access)
     // Bigger todo: update li3_acess (Nate's changes) and redo Minerva's access system completely.
     $user = Auth::check('minerva_user');
     if ($user['role'] != 'administrator' && $user['role'] != 'content_editor') {
         $this->redirect('/');
         return;
     }
     if (!empty($this->request->data['Filedata'])) {
         //Logger::debug(json_encode($this->request->data));
         // IMPORTANT: Use MongoDate() when inside an array/object because $_schema isn't deep
         $now = new MongoDate();
         $data = array();
         // IMPORTANT: The current/target gallery id must be passed in order to associate the item.
         // Otherwise, it'd be stored loose in the system.
         $gallery_id = $this->request->data['gallery_id'];
         // If there was only one file uploaded, stick it into a multi-dimensional array.
         // It's just easier to always run the foreach() and code the processing stuff once and here.
         // For now...while we're saving to disk.
         if (!isset($this->request->data['Filedata'][0]['error'])) {
             $this->request->data['Filedata'] = array($this->request->data['Filedata']);
         }
         foreach ($this->request->data['Filedata'] as $file) {
             // TODO: change. possibly adaptable class
             $source_base = '/minerva_gallery/img/gallery_items/';
             $service = 'file';
             // Create an Item object
             $id = new MongoId();
             $document = Item::create(array('_id' => $id, 'created' => $now, 'modified' => $now, 'service' => $service, 'source' => $source_base . $id . '.jpg', 'title' => $file['name'], '_galleries' => array($gallery_id), 'published' => true));
             // Save file  to disk
             // TODO: Again, change this...maybe use an adaptable class for storage
             if ($file['error'] == UPLOAD_ERR_OK) {
                 $upload_dir = LITHIUM_APP_PATH . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'minerva_gallery' . DIRECTORY_SEPARATOR . 'webroot' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'gallery_items' . DIRECTORY_SEPARATOR;
                 $ext = substr(strrchr($file['name'], '.'), 1);
                 switch (strtolower($ext)) {
                     case 'jpg':
                     case 'jpeg':
                     case 'png':
                     case 'gif':
                     case 'png':
                     case 'doc':
                     case 'txt':
                         if (move_uploaded_file($file['tmp_name'], $upload_dir . $id . '.jpg')) {
                             Logger::debug('saved file to disk successfully.');
                         }
                         break;
                     default:
                         //exit();
                         break;
                 }
             }
             //Logger::debug('document _id: ' . (string)$document->_id);
             if ($document->save($data)) {
                 Logger::debug('saved mongo document successfully.');
             }
         }
     }
     //$this->set(compact('document'));
 }
示例#18
0
 public function testWrite()
 {
     $result = Logger::write('info', 'SyslogTest message...', array('name' => 'syslog'));
     $this->assertNotEmpty($result);
 }
示例#19
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())))
示例#20
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'];
示例#21
0
<?php
use \lithium\data\Connections;
use \lithium\analysis\Logger;

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()))        );  
    }       return $result;
});
?>
示例#22
0
文件: ImageUtil.php 项目: qujian/rwe
 /**
  * @param $img_path 原图路径
  * @param $width 输出宽度
  * @param $height 输出高度
  * 
  * @return 输出图路径。如果转换失败则返回空字符串
  */
 public static function create_thumb_by_width_and_height($img_path, $width, $height, $quality = self::DEFAULT_IMG_THUMB_QUALITY)
 {
     $func_resize = '\\tencent\\best_image\\smart_resize';
     if (!function_exists($func_resize)) {
         \lithium\analysis\Logger::write('debug', ' create_thumb, function smart_resize is undefined. img_path: ' . $img_path . '   ' . PHP_EOL);
         return "";
     }
     $thumb_path = self::get_thumb_name($img_path, $width, $height);
     $func_resize($img_path, $thumb_path, $width, $height, $quality);
     if (is_file($thumb_path)) {
         chmod($thumb_path, FILE_MOD);
         return $thumb_path;
     } else {
         return "";
     }
 }
 public function testRespondsToMagic()
 {
     $this->assertTrue(Logger::respondsTo('emergency'));
     $this->assertTrue(Logger::respondsTo('debug'));
     $this->assertFalse(Logger::respondsTo('foobar'));
 }
示例#24
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);
示例#25
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');
 }
示例#26
0
 public function ipn()
 {
     if ($this->request->data) {
         $paypal_txn_id = $this->request->data['txn_id'];
         $payment = Payments::first(array('conditions' => array(array('txn_id' => $paypal_txn_id))));
         if (!isset($payment)) {
             Logger::debug('New transaction #' . $paypal_txn_id);
             # Put the payment in the DB
             $payment = Payments::create($this->request->data);
             if ($payment->invoice) {
                 # Map invoices to cart_ids, right now this is direct
                 $payment->shopping_cart_id = $payment->invoice;
             }
             $payment->save();
         } else {
             Logger::debug('Transaction play-back (txn #' . $paypal_txn_id . ')');
         }
         Logger::debug('$payment->_id = ' . $payment->_id);
         $cart = ShoppingCarts::find($payment->invoice);
         Logger::debug('$cart->_id = ' . $cart->_id);
         $items = $cart->getItems();
         if (strtolower($payment->payment_status) == 'pending' and strtolower($payment->pending_reason) == 'authorization') {
             $captureAmount = 0;
             $remainder = 0;
             Logger::debug('authorization transaction');
             foreach ($items as $ci) {
                 Logger::debug('.....cart_item ' . $ci->_id);
                 $refObj = $ci->getReference();
                 if ($ci->isValid()) {
                     Logger::debug('..........valid purchase -- auto-capture');
                     $ci->save(array('status' => CartItems::STATUS_CAPT));
                     // Pass payment status down to referenced object
                     $conditions = array('_id' => $refObj->_id);
                     $query = array('$set' => array('payment_status' => CartItems::STATUS_CAPT, 'payment_timestamps.pending' => $payment->payment_date), '$push' => array('payments' => $payment->_id));
                     Registrations::update($query, $conditions);
                     $captureAmount += $ci->price;
                 } else {
                     Logger::debug('..........not valid, hold as pending');
                     $ci->save(array('status' => CartItems::STATUS_AUTH));
                     // Pass payment status down to referenced object
                     $conditions = array('_id' => $refObj->_id);
                     $query = array('$set' => array('payment_status' => CartItems::STATUS_AUTH, 'payment_timestamps.pending' => $payment->payment_date), '$push' => array('payments' => $payment->_id));
                     Registrations::update($query, $conditions);
                     $remainder += $ci->price;
                 }
                 $cart->save(array('is_authorized' => true));
             }
             if ($captureAmount > 0) {
                 Logger::debug('Capturing $' . $captureAmount);
                 $result = Paypal::doCapture($payment->auth_id, $captureAmount, $payment->mc_currency, $remainder == 0);
                 Logger::debug(print_r($result, true));
                 // Log NVP transaction result to the payment
                 $query = array('$push' => array('nvp' => $result));
                 $conditions = array('_id' => $payment->_id);
                 Payments::update($query, $conditions);
                 Logger::debug('Captured!');
             }
         } else {
             if (strtolower($payment->payment_status) == 'completed') {
                 $unpaid_items = 0;
                 foreach ($items as $ci) {
                     Logger::debug('.....cart_item ' . $ci->_id);
                     $refObj = $ci->getReference();
                     if ($ci->status == CartItems::STATUS_CAPT) {
                         Logger::debug('..........PAID!');
                         $ci->save(array('status' => CartItems::STATUS_PAID));
                         // Pass payment status down to referenced object
                         // TODO: this stuff should really be handled by the registration object
                         $conditions = array('_id' => $refObj->_id);
                         $query = array('$set' => array('paid' => true, 'payment_status' => CartItems::STATUS_PAID, 'status' => 'active', 'payment_timestamps.completed' => $payment->payment_date), '$push' => array('payments' => $payment->_id));
                         Registrations::update($query, $conditions);
                     } else {
                         if ($ci->status != CartItems::STATUS_PAID) {
                             $unpaid_items++;
                         }
                     }
                 }
                 if ($unpaid_items == 0) {
                     $cart->save(array('status' => 'closed'));
                 }
             } else {
                 if (strtolower($payment->payment_status) == 'refunded') {
                     foreach ($items as $ci) {
                         Logger::debug('.....cart_item ' . $ci->_id);
                         $refObj = $ci->getReference();
                         $conditions = array('_id' => $refObj->_id);
                         $query = array('$set' => array('paid' => false, 'payment_status' => CartItems::STATUS_RFND, 'payment_timestamps.refunded' => $payment->payment_date), '$push' => array('payments' => $payment->_id));
                         Registrations::update($query, $conditions);
                         Logger::debug('..........refunded.');
                     }
                 }
             }
         }
     }
     return $this->render(array('layout' => false));
 }
示例#27
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');
 }
示例#28
0
<?php

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