Example #1
0
File: Log.php Project: hubs/yuncms
 public static function &get_instance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 public static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #3
0
 function logger($level, $msg, $method = null)
 {
     static $labels = array(100 => 'DEBUG', 200 => 'INFO', 250 => 'NOTICE', 300 => 'WARNING', 400 => 'ERROR', 500 => 'CRITICAL', 550 => 'ALERT', 600 => 'EMERGENCY', 700 => 'ALL');
     // make sure $level has the correct value
     if (is_int($level) and !isset($labels[$level]) or is_string($level) and !array_search(strtoupper($level), $labels)) {
         throw new \FuelException('Invalid level "' . $level . '" passed to logger()');
     }
     if (is_string($level)) {
         $level = array_search(strtoupper($level), $labels);
     }
     // get the levels defined to be logged
     $loglabels = \Config::get('log_threshold');
     // bail out if we don't need logging at all
     if ($loglabels == \Fuel::L_NONE) {
         return false;
     }
     // if profiling is active log the message to the profile
     if (\Config::get('profiling')) {
         \Console::log($method . ' - ' . $msg);
     }
     // if it's not an array, assume it's an "up to" level
     if (!is_array($loglabels)) {
         $a = array();
         foreach ($labels as $l => $label) {
             $l >= $loglabels and $a[] = $l;
         }
         $loglabels = $a;
     }
     // do we need to log the message with this level?
     if (!in_array($level, $loglabels)) {
         return false;
     }
     return \Log::instance()->log($level, (empty($method) ? '' : $method . ' - ') . $msg);
 }
Example #4
0
 public static function getInstance()
 {
     if (null == self::$instance) {
         self::$instance = new Log();
     }
     return self::$instance;
 }
Example #5
0
 public function action_index()
 {
     $request = $this->request->current();
     if ($request->post('submit')) {
         $login = $request->post('login');
         $password = $request->post('password');
         $ip = Request::$client_ip;
         $user_agent = Request::$user_agent;
         $remember = (bool) $this->request->post('remember');
         $fail_login_checker = new Auth_Admin_Checker($login, $ip);
         if ($fail_login_checker->check()) {
             $admin = ORM::factory('admin')->where('username', '=', $login)->and_where('delete_bit', '=', 0)->and_where('active', '=', 1)->find();
             try {
                 if ($this->acl->auth()->login($admin, $password, $remember)) {
                     $url = Session::instance()->get('BACK_URL');
                     $request->redirect(empty($url) ? Route::url('admin') : $url);
                 } else {
                     // Store fail login attempt
                     $fail_login_checker->add($password, $user_agent);
                     $this->template->set('error', __('Authentication error'));
                 }
             } catch (ORM_Validation_Exception $e) {
                 Log::instance()->add(Log::ERROR, $e->errors('') . '[' . __FILE__ . '::' . __LINE__ . ']');
             }
         } else {
             $this->template->set('error', __('To many failed login attempts. Please, wait :minutes minutes and try again.', array(':minutes' => ceil($fail_login_checker->fail_interval() / 60))));
         }
     }
     $this->template->set('logo', $this->config['logo']);
 }
Example #6
0
 /**
  * Load adittionnal content part
  *
  * @param	string	$parts			part name or list of part names
  * @param	string	$sub_directory	subdirectory name
  *
  * @return	array
  **/
 public function load_parts($parts, $subcategory = NULL)
 {
     $parts = func_get_arg(0);
     $sub_directory = func_get_arg(1);
     $sub_directory = $sub_directory ? $sub_directory . '/' : NULL;
     $result = array();
     if (strpos($parts, ',') === FALSE) {
         // Just one entry
         try {
             $result[] = new Model_Page($sub_directory . $parts);
         } catch (Kohana_exception $e) {
             Log::instance()->add(Log::WARNING, $e->getMessage());
         }
     } else {
         // Multiples entries
         foreach (explode(',', $parts) as $part) {
             try {
                 $result[] = new Model_Page($sub_directory . $part);
             } catch (Kohana_exception $e) {
                 Log::instance()->add(Log::WARNING, $e->getMessage());
             }
         }
     }
     return $result;
 }
Example #7
0
 public function __construct()
 {
     $this->input = new Input();
     $this->config = Config::instance();
     $this->log = Log::instance();
     $this->log->write('debug', 'Library Class Initialized');
 }
Example #8
0
 public static function newInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #9
0
 public static function get_instance($log_level = '', $filename = '')
 {
     if (empty(self::$instance)) {
         self::$instance = new Log($log_level, $filename);
     }
     return self::$instance;
 }
Example #10
0
 /**
  * Runs the function in backgroung
  * Called from our application, kohana is always loaded
  *
  * @param string $call_back function name to be called in background
  * @param array $params parameters that the call_back can recieve in order!
  * @param integer $priority for the system to do such task
  * @return integer PID
  */
 public static function background($call_back, $params = NULL, $priority = NULL)
 {
     if (self::is_callable($call_back)) {
         //if (Kohana::$environment == Kohana::DEVELOPMENT)
         //return self::execute($call_back, base64_encode(serialize($params)) );
         $script = 'cli';
         //preparing the command to execute
         if (is_array($params)) {
             $command = 'php -f ' . APPPATH . $script . EXT . ' ' . $_SERVER['KOHANA_ENV'] . ' ' . $call_back . ' ' . base64_encode(serialize($params)) . '';
         } else {
             //no params the -1 is because ::execute requires a value before the jobid if not in the cli won't work
             $command = 'php -f ' . APPPATH . $script . EXT . ' ' . $_SERVER['KOHANA_ENV'] . ' ' . $call_back . ' -1';
         }
         //priority check
         if ($priority !== NULL) {
             $command = 'nohup nice -n ' . $priority . ' ' . $command;
         } else {
             $command = 'nohup ' . $command;
         }
         //adding output
         //$command = 'su - www-data -c "'.$command.' >/dev/null 2>/dev/null"';
         $command .= ' > /dev/null & echo $!';
         //execute
         //Log::instance()->add(LOG_DEBUG,'Exec->background - command: '.$command);
         //d($command);
         $pid = shell_exec($command);
         //$pid = shell_exec($command.' >/dev/null &');  //another way without priority
         //returning
         //Log::instance()->add(LOG_DEBUG,'Exec->background - Return value PID:'.$pid);
         return (int) $pid;
     } else {
         Log::instance()->add(LOG_ERR, 'Exec->background - call_back not found - ' . print_r($call_back, 1));
         return FALSE;
     }
 }
Example #11
0
 /**
  * @return Log
  */
 static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #12
0
 public function inst()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #13
0
 private function _converting()
 {
     if (!empty($this->conv_func)) {
         foreach ($this->conv_func as $f) {
             $call_p = [];
             if (is_string($f)) {
                 $call_f = [$this, $f];
             } elseif (is_array($f) and is_string($f[0]) and is_array($f[1])) {
                 $call_f = [$this, $f[0]];
                 $call_p = $f[1];
             } else {
                 Log::instance()->error("Incorrect format function parameters.");
                 return FALSE;
             }
             if (!is_callable($call_f, TRUE)) {
                 Log::instance()->error("Function: {$f} may not be called.");
                 return FALSE;
             }
             $ret = call_user_func_array($call_f, $call_p);
             if ($ret === FALSE) {
                 Log::instance()->error("Function: {$call_f[1]} returned FALSE.");
                 return FALSE;
             } elseif ($this->break_conv === TRUE) {
                 break;
             }
         }
     }
     return TRUE;
 }
Example #14
0
 public static function getInstance()
 {
     if (!self::$instance instanceof self) {
         $startTime = defined('PROCESS_START_TIME') ? PROCESS_START_TIME : microtime(true) * 1000;
         self::$instance = new self($GLOBALS['LOG'], $startTime);
     }
     return self::$instance;
 }
Example #15
0
 public static function singleton($_idUser = null)
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c($_idUser);
     }
     return self::$instance;
 }
Example #16
0
 public function action_create_test_message()
 {
     if ($this->logreader_config->is_tester_available()) {
         Log::instance()->add(Log::NOTICE, 'Test message created! Client ' . Request::$client_ip . ' User-agent ' . Request::$user_agent);
     } else {
         array_push($this->data['errors'], array('code' => 600, 'text' => 'Tester is set to off!'));
     }
 }
Example #17
0
 public function __construct()
 {
     $this->input = new Input();
     $this->config = Config::instance();
     $this->log = Log::instance();
     $this->db = Database::instance();
     $this->log->write('debug', 'Model Class Initialized');
 }
Example #18
0
 public function action_callback()
 {
     $post = $this->request->post();
     $post['created'] = date("Y-m-d H:i:s");
     Log::instance()->add(Log::ERROR, json_encode($post));
     $Callback = new Model_Sms_Callback();
     $Callback->add($post);
     exit;
 }
Example #19
0
 public static function Init($handler = null, $level = 15)
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
         self::$instance->__setHandle($handler);
         self::$instance->__setLevel($level);
     }
     return self::$instance;
 }
Example #20
0
File: Core.php Project: korejwo/coc
 public function edit($id, $params)
 {
     try {
         return DB::update($this->table)->set($params)->where('id', '=', $id)->execute() > 0;
     } catch (Exception $e) {
         Log::instance()->add(Log::ERROR, $e->getMessage());
         return false;
     }
 }
Example #21
0
 public function __construct()
 {
     self::$_instance = $this;
     $this->input = new Input();
     $this->config = Config::instance();
     $this->db = Database::instance();
     $this->log = Log::instance();
     $this->log->write('debug', 'Controller Class Initialized');
 }
Example #22
0
File: Engine.php Project: g4z/poop
 /**
  * Initialise the Engine object from user input
  * @throw Exception
  * @private
  */
 private function startup()
 {
     // =================== CONFIGURE LOGFILE ====================
     if ($this->environment->isCli()) {
         // TODO: Pass in debuglog filepath here
         $logfile = './poop.log';
     } else {
         $logfile = sys_get_temp_dir() . '/poop.log';
     }
     Log::instance()->setFilepath($logfile);
     // ================ PROCESS STARTUP OPTIONS =================
     /*  $opt = [0] => file [1] => f 
         [2] => 1 [3] => Path to code file */
     foreach (OptionMap::getInstance() as $opt) {
         switch ($opt[0]) {
             case 'code':
                 // Code was passed as --code argument
                 if ($option = $this->getOption(array($opt[0], $opt[1]))) {
                     if ($option === true) {
                         // empty --code arg passed
                         $this->setBuffer('');
                     } else {
                         $this->setBuffer($option);
                     }
                 }
                 break;
             case 'file':
                 if ($option = $this->getOption(array($opt[0], $opt[1]))) {
                     if (!is_readable($option)) {
                         throw new OptionException('--file not readable: ' . $option);
                     }
                     $this->setBuffer(file_get_contents($option));
                 }
                 break;
             case 'debug':
                 if ($option = $this->getOption(array($opt[0], $opt[1]))) {
                     Log::instance()->enableDebug();
                 }
                 break;
             default:
                 break;
         }
     }
     // $this->dump();
     // ================== INITIAL LOGFILE OUTPUT ======================
     $this->debug(__METHOD__, __LINE__);
     $this->debug(__METHOD__, __LINE__, '======[       O_O     ]======');
     $this->debug(__METHOD__, __LINE__);
     $this->debug(__METHOD__, __LINE__, "Using logfile: {$logfile}");
     if (Log::instance()->debugEnabled()) {
         $this->debug(__METHOD__, __LINE__, "Debugging is ENABLED");
     }
     // ================== LOAD EXTENSIONS ======================
     $total = $this->getExtensionManager()->load();
     $this->debug(__METHOD__, __LINE__, sprintf('Loaded %u extensions', $total));
 }
Example #23
0
 public function before()
 {
     $this->autoRender(FALSE);
     parent::before();
     /**
      * Attach the file write to logging. Multiple writers are supported.
      */
     $postLogFile = 'post-' . date('Ymdh') . '.log';
     $this->_postLog = Log::instance()->attach(new Log_File(DATA_PATH . 'logs/', $postLogFile));
 }
Example #24
0
 public function __construct()
 {
     // Start session if not already started
     if (!session_id()) {
         session_start();
     }
     $this->config = Config::instance();
     $this->log = Log::instance();
     $this->log->write('debug', 'Input Class Initialized');
 }
Example #25
0
 /**
  * 单利模式
  *
  * @date 2014.02.04
  * @author zjk
  */
 public static function get_instance($log_tag = null)
 {
     if (!self::$instance instanceof self) {
         if ($log_tag != null && $log_tag != "") {
             self::$log_tag = $log_tag;
         }
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #26
0
 public static function create()
 {
     if (!is_null(self::$instance)) {
         return self::$instance;
     }
     self::$instance = new self();
     self::$file = self::$dir . DIRECTORY_SEPARATOR . strftime(self::$file_format);
     self::setEnabled(Config::getVar('log_enabled', false));
     self::setLevel(Config::getVar('log_level', self::LEVEL_INFO));
     return self::$instance;
 }
Example #27
0
 protected function element_show($object_name, $element_id)
 {
     $orm = ORM::factory('hided_List')->where('object_name', '=', $object_name)->and_where('site_id', '=', SITE_ID)->and_where('element_id', '=', $element_id)->find();
     if ($orm->loaded()) {
         try {
             $orm->delete();
         } catch (Exception $e) {
             Log::instance()->add(Log::ERROR, $e->getMessage() . '[' . __FILE__ . ':' . __LINE__ . ']');
         }
     }
 }
Example #28
0
 protected function _execute(array $params)
 {
     Minion_CLI::write('Change status videos!');
     $video = Model_Links::updatePublish();
     //
     if ($video) {
         $message = "OK";
     } else {
         $message = "Error";
     }
     Log::instance()->add(Log::INFO, "Update videos task are {$message}");
     Log::instance()->write();
 }
Example #29
0
 public function getWithTokenRequest($path, $parameters = [])
 {
     $parameters = array_merge($parameters, $this->getTokenData());
     $url = $this->net_api_host . $path . '?' . http_build_query($parameters);
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
     $request = curl_exec($curl);
     Log::instance()->logAdd(['Request:', $url]);
     Log::instance()->logAdd(['-- Response:', $request]);
     return $request;
 }
Example #30
0
 protected function redirected_nums()
 {
     $redir_num = $this->cdr->getRaw(14);
     if (empty($redir_num)) {
         return TRUE;
     }
     $this->cdr->isRedirected(TRUE);
     // Исходящий переадресующий номер
     if (strlen($redir_num) != 10) {
         Log::instance()->error("Redirected number: {$redir_num} must be 10 characters. File string number #" . $this->cdr->getNumStr());
         return FALSE;
     }
     $this->cdr->A = $redir_num;
 }