Laravel4.2のログ出力

Laravel4.2 のlog設定

環境ごとの設定

  • 環境ごとの判定
    • 私はhostnameを使ってます
    • /bootstrap/start.php
$env = $app->detectEnvironment(array(
    'production' => array('fqdn-prodcution'),
    'staging'    => array('fqdn-dev'),
    'local'      => array('local.*', '*.local', '*.lan', 'localhost.*' ), // vagrant 
));

環境ごとのloglevelの設定方法

私はstagingでもdebug barを出しています

  • debug と loglevel
    • /app/config/local/app.php
      • 'debug' => true,
      • 'log_level' => 'debug',
    • /app/config/staging/app.php
      • 'debug' => true,
      • 'log_level' => 'debug',
    • /app/config/app.php
      • 'debug' => false,
      • 'log_level' => 'warning',

ログを出力

  • log出力方法
    • /app/start/global.php
$logFile = 'laravel.log';
Log::useFiles(storage_path() . '/logs/' . $logFile, Config::get('app.log_level'));
void useFiles( string $path, string $level = 'debug')
  • Laravel側でrotate
void useDailyFiles( string $path, int $days, string $level = 'debug')