Laravel 5 ã®ãããã°åºå
Laravel 5 ã§ãããã°åºåããï¼ã¤ã®ããæ¹ã«ã¤ãã¦ã¾ã¨ããã
ãã°ãã¡ã¤ã«ã«æ¸ãã ã
ï¼éãã®æ¸ãæ¹ãããã
ãã«ãã¼é¢æ° logger(), info()
<?php Route::get('/', function() { $message = ['a' => 1, 'b' => 2, 'c' => 3]; logger($message); info($message); // logger()->notice($message, $context); // logger()->warning($message, $context); // logger()->error($message, $context); // logger()->critical($message, $context); // logger()->alert($message, $context); // logger()->emergency($message, $context); return 'OK'; });
storage/logs/laravel.log ã«æ¸ãåºãããã
[2015-07-31 13:40:35] local.DEBUG: array ( 'a' => 1, 'b' => 2, 'c' => 3, ) [2015-07-31 13:40:35] local.INFO: array ( 'a' => 1, 'b' => 2, 'c' => 3, )
é åã©ã¤ã¯ã¯ var_export() ã§ã Jsonable ãªã¯ã©ã¹ã¤ã³ã¹ã¿ã³ã¹ã¯ JSON æååã«å é¨ã§è¦ãããæ´å½¢ãã¦ãããããªã®ã§ãä½ãèããã«å¼æ°ã«æ¸¡ãã¦ããã
Log ãã¡ãµã¼ã
<?php namespace App\Http\Controllers; use Log; // ... class MyController extends Controller { public function index() { $message = ['a' => 1, 'b' => 2, 'c' => 3]; Log::debug($message); Log::info($message); // Log::notice($message, $context); // Log::warning($message, $context); // Log::error($message, $context); // Log::critical($message, $context); // Log::alert($message, $context); // Log::emergency($message, $context); return 'OK'; } }
ãã«ãã¼é¢æ°ã¨ Log ãã¡ãµã¼ãã®ãã£ã¦ããã¨ã¯ã¾ã£ããåãããã ã Log ãã¡ãµã¼ãã¯ãã¡ã¤ã«ã®å
é 㧠use Log; ããªãã¨ãããªãã£ããã use Log; ã§ããªã php ãã¡ã¤ã«ãããï¼ã®ã§ãã«ãã¼é¢æ°ã® logger() ã®ã»ãã便å©ãã°ãã¼ãã«é¢æ°ã¯æå¼·ã ãªã
ãã©ã¦ã¶ã«è¡¨ç¤ºãã var_export()
<?php Route::get('/', function() { $message = ['a' => 1, 'b' => 2, 'c' => 3]; echo '<pre>' . var_export($message, true) . '</pre>'; return 'OK'; });
Laravel ã¨é¢ä¿ãªã PHP ããªãã¿ã®ããæ¹ãä¸å¿èª¬æãã㨠var_export() ã§è¦ãããæ´å½¢ã㦠pre ã¿ã°ã§æ¹è¡ãå¯è¦åãã¦ããã
ãã©ã¦ã¶ã«ãªããã«è¡¨ç¤ºãã dd()
<?php Route::get('/', function() { $message = view(); dd($message); return 'OK'; });
dump and die ã®ç¥ãä¸è¿°ã®ï¼ã¤ã¨éã£ã¦ã¯ã©ã¹ã¤ã³ã¹ã¿ã³ã¹ã¨ãè¤éãªãã®ã表示ã§ããã die ã¨åã®ã¤ãéãã¢ããªã±ã¼ã·ã§ã³ã®å®è¡ãåæ¢ããï¼ OK ã表示ããã¦ãªãããï¼ããªãããããã
ã¾ã¨ã
logger($message, $context);
ãã°ãã¡ã¤ã«ã«æ¸ãã ãã®ã§æ®ãã
echo '<pre>' . var_export($message, true) . '</pre>';
ãã©ã¦ã¶ã«è¡¨ç¤ºããã
dd($message);
ãã©ã¦ã¶ã«ãªããã«è¡¨ç¤ºãããã¯ã©ã¹ã¤ã³ã¹ã¿ã³ã¹ã¨ãè¤éãªãã®ã表示ã§ãããã¢ããªã±ã¼ã·ã§ã³ã®å®è¡ãåæ¢ããã
以ä¸ã§ããããã§ã¯ Laravel ã®ãããããã°ã©ã¤ããã