public static function getInstance($name, $level = 1) { if (is_null(self::$instance)) { self::$instance = new Logger($name, $level); } return self::$instance; }
/** * Returns a logger identified by the given name. * * If the logger does not exist it is created. * * @param string $name Name of the logger * * @return object Logger */ function logger($name = null) { if (null === $name) { return Logger::instance(); } return Logger::instance()->get_logger($name); }
/** * returns the instance created by its first invoke. * * @return Logger */ public static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Method getInstance * @access static * @return mixed * @since 1.1.12 */ public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }
/** * * Return logger instance or create new instance * * @return object (PDO) * * @access public * */ public static function getInstance() { if (!self::$instance) { self::$instance = new Logger(); } return self::$instance; }
public static function getInstance($filepath = 0, $priority = 0) { if (!isset(self::$instance)) { self::$instance = new Logger($filepath, $priority); } return self::$instance; }
public static function &getInstance() { if (self::$instance === false) { self::$instance = new self(); } return self::$instance; }
static function getLogger() { if (self::$instance == null) { self::$instance = new Logger("logger"); } return self::$instance; }
public static function get() { if (self::$instance == null) { self::$instance = new self(); } return self::$instance; }
public static function getSingleton($pathData, $pathSep, $file = 'cron.log') { if (self::$instance == null) { self::$instance = new Logger($pathData, $pathSep, $file); } return self::$instance; }
/** * Singleton, returns class if stored, attemps to call constructor and initilize if not stored * * @param PDO|null $loggingDB connection to logging database * @param string $transactionID unique identifier created at application startup */ public static function get_instance(PDO $loggingDB = null, $transactionID = null) { if (self::$instance === null) { self::$instance = new self($loggingDB, $transactionID); return self::$instance; } return self::$instance; }
/** * * * @param LoggerInterface $value Specify a new value to set the logger to. */ public static function setLogger(LoggerInterface $value = null) { if ($value !== null) { self::$instance = $value; } else { self::$instance = new BaseLogger(); } }
public function getInstance() { // Instantiate itself if not instantiated if (self::$instance === NULL) { self::$instance = new Logger(); } return self::$instance; }
protected static function getInstance() { if (self::$instance === NULL) { $class = __CLASS__; self::$instance = new $class(); } return self::$instance; }
/** * Simple static method to log lines to the logfile. * * @param string $value message * @param string $path relative path to temporary directory * @param boolean $success * @author sl */ public static function logfile($value) { if (self::$instance == null) { self::$instance = new Logger(); } $value = preg_replace('/\\n|\\s{2,}/i', '', $value); self::$instance->log($value); }
public static function getInstance() { if (self::$instance === NULL) { $argv = func_get_args(); $class = __CLASS__; self::$instance = new $class($argv[0], $argv[1]); } return self::$instance; }
public static function getLogger() { if (!self::$instance instanceof Logger) { $filepath = Configuration::get(Configuration::LOG_FILE); $priority = Configuration::get(Configuration::LOG_LEVEL); self::$instance = new Logger($filepath, $priority); } return self::$instance; }
public static function getInstance() { if (is_null(self::$instance)) { $class = __CLASS__; //获取本对象的类名 self::$instance = new $class(); } return self::$instance; }
public function test_constructor_Monolog() { $log = new Logger(); $this->assertTrue($log instanceof Logger); $this->assertEquals(Logger::DEFAULT_LOGGER_NAME, $log->getName()); $this->assertTrue($log->isMonologLogger()); $logTest = Logger::instance('test'); $this->assertEquals('test', $logTest->getName()); $this->assertTrue($log->isMonologLogger()); $logMage = Logger::instance('magento', 'some/file/that/is/not/exist'); $this->assertEquals('magento', $logMage->getName()); $this->assertFalse($logMage->isMonologLogger()); }
protected function setUp() { require BASE . '/config/database.inc.php'; if (!is_array($db) || !array_key_exists("test", $db)) { die("\n'test' DB is not defined in config/database.inc.php\n\n"); } $test_db = $db['test']; $dsn = sprintf("%s://%s:%s@%s:%d/%s", "mysql", $test_db['user'], $test_db['password'], $test_db['host'], $test_db['port'], $test_db['database']); //setup our log $logger =& Logger::instance(BASE . '/tests/logs/test.log'); $this->adapter = new MySQLAdapter($dsn, $logger); $this->adapter->logger->log("Test run started: " . date('Y-m-d g:ia T')); }
public function __construct() { $class = get_called_class(); $exp = explode("\\", $class); $entityName = substr(array_pop($exp), 0, strlen("Repository") * -1); $exp[] = $entityName . "Entity"; $this->entity = implode("\\", $exp); $this->table = substr(preg_replace_callback("/([A-Z])/", function ($matches) { return "_" . strtolower($matches[1]); }, $entityName), 1); $this->db = Database::instance(); $this->logger = Logger::instance(); $this->cache = Cache::instance(); }
/** * Handle on shutdown * * @param void * @return null */ function system_handle_on_shutdown() { ProjectObjectViews::save(); // Lets kill a transaction if we have something open $database =& DBConnection::instance(); if (instance_of($database, 'DBConnection') && $database->transaction_level > 0) { $database->rollback(); } // if if (DEBUG >= DEBUG_DEVELOPMENT) { $logger =& Logger::instance(); $logger->logToFile(ENVIRONMENT_PATH . '/logs/' . date('Y-m-d') . '.txt'); } // if }
/** * Attempts to log a user in * * @param array $credentials * @return Ethanol\Model_User The newly logged in user */ public function log_in($credentials) { $user = Auth::instance()->validate_user($credentials); if ($user == false) { //Could not validate for some reasion so make things explode $email = \Arr::get($credentials, 'email', null); Logger::instance()->log_log_in_attempt(Model_Log_In_Attempt::$ATTEMPT_BAD_CRIDENTIALS, $email); \Event::has_events('ethanol_log_in_failed') and \Event::trigger('ethanol_log_in_failed'); } else { //Nothing exploded up to this point so assume that the user has logged //in ok. Logger::instance()->log_log_in_attempt(Model_Log_In_Attempt::$ATTEMPT_GOOD, $user->email); Session::instance()->get_instance()->set(static::$session_key, $user->id); \Event::has_events('ethanol_logged_in') and \Event::trigger('ethanol_logged_in', $user); } return $user; }
public static function getTimezone() { if (($timezone = self::getEnv("envTimezone")) === null) { try { $mmdb = array_reverse(glob(Config::$geoip . "GeoLite2-City*.mmdb"))[0]; $reader = new \GeoIp2\Database\Reader($mmdb); $ip = Request::getIp(); $record = $reader->city($ip); $timezone = $record->location->timeZone; self::setTimezone($timezone); } catch (\Exception $e) { Logger::instance()->logError($e->getMessage()); self::setTimezone(Config::$defaultTimezone); } } return new \DateTimeZone($timezone); }
public function validate_user($userdata) { $email = \Arr::get($userdata, 'email'); if (!$this->has_user($email)) { Logger::instance()->log_log_in_attempt(Model_Log_In_Attempt::$ATTEMPT_NO_SUCH_USER, $email); throw new LogInFailed(\Lang::get('ethanol.errors.loginInvalid')); } $user = Model_User::find('first', array('related' => array('security', 'meta', 'groups'), 'where' => array(array('email', $email)))); $password = \Arr::get($userdata, 'password'); //Hash the given password and check that against the user $hashedPassword = Hasher::instance()->hash($password, $user->security->salt); if ($hashedPassword == $user->security->password) { $user->clean_security(); return $user; } return false; }
/** * Handle fatal error * * @param Error $error * @return null */ function handle_fatal_error($error) { if (DEBUG >= DEBUG_DEVELOPMENT) { dump_error($error); } else { if (instance_of($error, 'RoutingError') || instance_of($error, 'RouteNotDefinedError')) { header("HTTP/1.1 404 Not Found"); print '<h1>Not Found</h1>'; if (instance_of($error, 'RoutingError')) { print '<p>Page "<em>' . clean($error->getRequestString()) . '</em>" not found.</p>'; } else { print '<p>Route "<em>' . clean($error->getRouteName()) . '</em>" not mapped.</p>'; } // if print '<p><a href="' . assemble_url('homepage') . '">« Back to homepage</a></p>'; die; } // if // Send email to administrator if (defined('ADMIN_EMAIL') && is_valid_email(ADMIN_EMAIL)) { $content = '<p>Hi,</p><p>activeCollab setup at ' . clean(ROOT_URL) . ' experienced fatal error. Info:</p>'; ob_start(); dump_error($error, false); $content .= ob_get_clean(); @mail(ADMIN_EMAIL, 'activeCollab Crash Report', $content, "Content-Type: text/html; charset=utf-8"); } // if // log... if (defined('ENVIRONMENT_PATH') && class_exists('Logger')) { $logger =& Logger::instance(); $logger->logToFile(ENVIRONMENT_PATH . '/logs/' . date('Y-m-d') . '.txt'); } // if } // if $error_message = '<div style="text-align: left; background: white; color: red; padding: 7px 15px; border: 1px solid red; font: 12px Verdana; font-weight: normal;">'; $error_message .= '<p>Fatal error: activeCollab has failed to executed your request (reason: ' . clean(get_class($error)) . '). Information about this error has been logged and sent to administrator.</p>'; if (is_valid_url(ROOT_URL)) { $error_message .= '<p><a href="' . ROOT_URL . '">« Back to homepage</a></p>'; } // if $error_message .= '</div>'; print $error_message; die; }
public function send($from, $to, $subject, $body, $headers = '') { if (is_array($from) && count($from) == 2) { $from = $from[0] . ' <' . $from[1] . '>'; } else { if (is_array($from)) { $from = implode('/', $from); } } $reporting = error_reporting(0); if ($this->triggerError) { trigger_error($this->triggerError); $result = false; } else { \Logger::instance(static::$_logger)->log("Message from '{$from}' to '{$to}' with subject '{$subject}', headers:{$headers}\n\n{$body}"); $result = true; } error_reporting($reporting); return $result; }
public function __construct() { $this->logger = Logger::instance(__CLASS__); if (!defined('WSDL_URL')) { $this->logger->crit('constant WSDL_URL is not set. Check config/soap.inc.php'); exit; } if (!defined('SOAP_OUTPUT_BASE_DIR')) { $this->logger->crit('constant SOAP_OUTPUT_BASE_DIR is not set. Check config/soap.inc.php'); exit; } if (!defined('SOAP_MODEL_DIR')) { $this->logger->crit('constant SOAP_MODEL_DIR is not set. Check config/soap.inc.php'); exit; } if (!is_dir(SOAP_OUTPUT_BASE_DIR . '/' . SOAP_MODEL_DIR)) { mkdir(SOAP_OUTPUT_BASE_DIR . '/' . SOAP_MODEL_DIR, 0755, true); } $this->soapClient = new SoapClient(WSDL_URL); }
/** * Handle PHP error * * @param integer $errno * @param integer $errstr * @param string $errfile * @param integer $errline * @return null */ function angie_error_handler($errno, $errstr, $errfile, $errline) { static $instance = null; if ($errno == 2048) { return; // Kill E_STRICT... Yeah, yeah, they have the best intentions... } // if if (!defined('E_STRICT')) { define('E_STRICT', 2048); } // if if (!defined('E_RECOVERABLE_ERROR')) { define('E_RECOVERABLE_ERROR', 4096); } // if $error_types = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice', E_RECOVERABLE_ERROR => 'Catchable Fatal Error'); // array $error_type = isset($error_types[$errno]) ? $error_types[$errno] : 'Unknown error'; if ($instance === null) { $logger =& Logger::instance(); } // if switch ($errno) { case E_USER_ERROR: $logger->logMessage("[{$error_type}] {$errstr} (in {$errfile} on {$errline})", LOG_LEVEL_ERROR); break; case E_USER_WARNING: $logger->logMessage("[{$error_type}] {$errstr} (in {$errfile} on {$errline})", LOG_LEVEL_WARNING); break; case E_USER_NOTICE: $logger->logMessage("[{$errno}] {$errstr} (in {$errfile} on {$errline})", LOG_LEVEL_INFO); break; default: $logger->logMessage("[{$error_type}] {$errstr} (in {$errfile} on {$errline})", LOG_LEVEL_ERROR); break; } // switch }
/** * Logs a user in and makes sure there's an assocated Ethanol user as well */ public function validate_user($userdata) { //User wants to log in so make sure there's an Ethanol user as well if ($userdata['state'] != Session::instance()->get_instance()->get('ethanol.driver.facebook.csrf')) { Logger::instance()->log_log_in_attempt(Model_Log_In_Attempt::$ATTEMPT_BAD_CRIDENTIALS, null); throw new LogInFailed(\Lang::get('ethanol.errors.loginInvalid')); } //Remove the csrf token now that it has been validated Session::instance()->get_instance()->set('ethanol.driver.facebook.csrf', ''); $app_id = \Config::get('ethanol.facebook.app_id'); $app_secret = \Config::get('ethanol.facebook.app_secret'); $code = \Arr::get($userdata, 'code'); $redirect_url = urlencode(parent::get_login_controller_path('facebook')); //Get an access token from FB $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&redirect_uri=" . $redirect_url . "&client_secret=" . $app_secret . "&code=" . $code; $params = parent::get_access_token($token_url, 'facebook'); //Now we have an access token lets get the email and finally create/check //the ethanol user. $graph_url = "https://graph.facebook.com/me?access_token=" . $params['access_token']; $facebookUser = json_decode(file_get_contents($graph_url)); $email = $facebookUser->email; //Got a user so log in now return parent::perform_login($email, 'facebook'); }