Exemplo n.º 1
0
Arquivo: log.php Projeto: wushian/MDD
 /**
  * Initialize the class
  */
 public static function _init()
 {
     // load the file config
     \Config::load('file', true);
     // determine the name and location of the logfile
     $filepath = \Config::get('log_path') . date('Y/m') . '/';
     if (!is_dir($filepath)) {
         @mkdir($filepath, \Config::get('file.chmod.folders', 0777), true);
     }
     $filename = $filepath . date('d') . '.php';
     if (!($handle = @fopen($filename, 'a'))) {
         die('Fatal error: could not create or access the log file (' . $filename . ')<br />check your file system permissions!');
     }
     if (!filesize($filename)) {
         fwrite($handle, "<?php defined('COREPATH') or exit('No direct script access allowed'); ?>" . PHP_EOL . PHP_EOL);
         chmod($filename, \Config::get('file.chmod.files', 0666));
     }
     fclose($handle);
     // create the monolog instance
     static::$monolog = new \Monolog\Logger('fuelphp');
     // create the streamhandler, and activate the handler
     $stream = new \Monolog\Handler\StreamHandler($filename, \Monolog\Logger::DEBUG);
     $formatter = new \Monolog\Formatter\LineFormatter("%level_name% - %datetime% --> %message%" . PHP_EOL, "Y-m-d H:i:s");
     $stream->setFormatter($formatter);
     static::$monolog->pushHandler($stream);
 }
Exemplo n.º 2
0
 /**
  * init
  * @param string $name
  * @param resource|string $stream
  * @return MonologLogger
  */
 public static function init($stream, string $name = 'app', int $level = MonologLogger::DEBUG, int $maxFiles = 0) : MonologLogger
 {
     if (static::$monolog == null) {
         $monolog = new MonologLogger($name);
         $monolog->pushHandler(new RotatingFileHandler($stream, $maxFiles, $level));
         static::$monolog = $monolog;
     }
     return static::$monolog;
 }
Exemplo n.º 3
0
 /**
  * Initialize the class
  */
 public static function _init()
 {
     // load the file config
     \Config::load('file', true);
     // make sure the log directories exist
     try {
         // determine the name and location of the logfile
         $path = \Config::get('log_path', APPPATH . 'logs' . DS);
         $filename = \Config::get('log_file', null);
         if (empty($filename)) {
             $rootpath = $path . date('Y') . DS;
             $filepath = $path . date('Y/m') . DS;
             $filename = $filepath . date('d') . '.php';
         } else {
             $rootpath = $path;
             $filepath = $path;
             $filename = $path . $filename;
         }
         // get the required folder permissions
         $permission = \Config::get('file.chmod.folders', 0777);
         if (!is_dir($rootpath)) {
             mkdir($rootpath, 0777, true);
             chmod($rootpath, $permission);
         }
         if (!is_dir($filepath)) {
             mkdir($filepath, 0777, true);
             chmod($filepath, $permission);
         }
         $handle = fopen($filename, 'a');
     } catch (\Exception $e) {
         \Config::set('log_threshold', \Fuel::L_NONE);
         throw new \FuelException('Unable to create or write to the log file. Please check the permissions on ' . \Config::get('log_path') . '. (' . $e->getMessage() . ')');
     }
     if (!filesize($filename)) {
         fwrite($handle, "<?php defined('COREPATH') or exit('No direct script access allowed'); ?>" . PHP_EOL . PHP_EOL);
         chmod($filename, \Config::get('file.chmod.files', 0666));
     }
     fclose($handle);
     // create the monolog instance
     static::$monolog = new \Monolog\Logger('fuelphp');
     // create the streamhandler, and activate the handler
     $stream = new \Monolog\Handler\StreamHandler($filename, \Monolog\Logger::DEBUG);
     $formatter = new \Monolog\Formatter\LineFormatter("%level_name% - %datetime% --> %message%" . PHP_EOL, "Y-m-d H:i:s");
     $stream->setFormatter($formatter);
     static::$monolog->pushHandler($stream);
 }
Exemplo n.º 4
0
 /**
  * Initialize the class
  */
 public static function _init()
 {
     // load the file config
     \Config::load('file', true);
     // determine the name and location of the logfile
     $filepath = \Config::get('log_path') . date('Y/m') . '/';
     if (!is_dir($filepath)) {
         $old = umask(0);
         mkdir($filepath, \Config::get('file.chmod.folders', 0777), true);
         umask($old);
     }
     $filename = $filepath . date('d') . '.php';
     if (!file_exists($filename)) {
         file_put_contents($filename, "<" . "?php defined('COREPATH') or exit('No direct script access allowed'); ?" . ">" . PHP_EOL . PHP_EOL);
     }
     // create the monolog instance
     static::$monolog = new \Monolog\Logger('fuelphp');
     // create the streamhandler, and activate the handler
     $stream = new \Monolog\Handler\StreamHandler($filename, \Monolog\Logger::DEBUG);
     $formatter = new \Monolog\Formatter\LineFormatter("%level_name% - %datetime% --> %message%" . PHP_EOL, "Y-m-d H:i:s");
     $stream->setFormatter($formatter);
     static::$monolog->pushHandler($stream);
 }
Exemplo n.º 5
0
 /**
  * create the monolog instance
  */
 public static function _init()
 {
     static::$monolog = new \Monolog\Logger('fuelphp');
     static::initialize();
 }
Exemplo n.º 6
0
 /**
  * create the monolog instance
  */
 public static function _init()
 {
     static::$monolog = new \Monolog\Logger(\Config::get("log.package_name", "fuelPHP") . ":" . Input::real_ip());
     static::initialize();
 }