Example #1
0
 function __construct($filePath, $fileName = null)
 {
     if (!$filePath) {
         $filePath = dirname(__DIR__) . '/_logs/';
     }
     $filePath = rtrim($filePath, '/') . '/';
     $date = @strftime('%Y-%m-%d');
     $hour = @strftime('%H');
     $filePath .= $date;
     $tmp = $filePath . '/';
     $idx = 1;
     while (file_exists($tmp) && !is_writeable($tmp) && $idx < 10) {
         $tmp = $filePath . '-' . $idx . '/';
         $idx++;
     }
     $filePath = $tmp;
     if (br()->isConsoleMode()) {
         $filePath .= br()->scriptName();
         if ($arguments = br()->getCommandLineArguments()) {
             if ($arguments = br()->fs()->normalizeFileName(br($arguments)->join('_'))) {
                 $filePath .= '_' . $arguments;
             }
         }
     } else {
         $filePath .= br()->request()->clientIP();
     }
     $tmp = $filePath . '/';
     $idx = 1;
     while (file_exists($tmp) && !is_writeable($tmp) && $idx < 10) {
         $tmp = $filePath . '-' . $idx . '/';
         $idx++;
     }
     $filePath = $tmp;
     if (!$fileName) {
         $fileName = $date . '-';
         if (br()->isConsoleMode()) {
         } else {
             $fileName .= br()->request()->clientIP() . '-';
         }
         $fileName .= $hour . '.log';
     }
     parent::__construct($filePath, $fileName);
     $this->on('log.initialized', function ($logger) {
         $logger->writeAppInfo();
     });
     register_shutdown_function(array(&$this, "end"));
 }
 function writeMessage($message, $group = 'MSG')
 {
     if ($group == 'ERR') {
         parent::writeMessage($message, $group);
     }
 }