Ejemplo n.º 1
0
 public static function getInstance($name, $level = 1)
 {
     if (is_null(self::$instance)) {
         self::$instance = new Logger($name, $level);
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
/**
 * 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);
}
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 /**
  *
  * 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;
 }
Ejemplo n.º 6
0
 public static function getInstance($filepath = 0, $priority = 0)
 {
     if (!isset(self::$instance)) {
         self::$instance = new Logger($filepath, $priority);
     }
     return self::$instance;
 }
Ejemplo n.º 7
0
 public static function &getInstance()
 {
     if (self::$instance === false) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 8
0
 static function getLogger()
 {
     if (self::$instance == null) {
         self::$instance = new Logger("logger");
     }
     return self::$instance;
 }
Ejemplo n.º 9
0
 public static function get()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 10
0
 public static function getSingleton($pathData, $pathSep, $file = 'cron.log')
 {
     if (self::$instance == null) {
         self::$instance = new Logger($pathData, $pathSep, $file);
     }
     return self::$instance;
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
 /**
  *
  *
  * @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();
     }
 }
Ejemplo n.º 13
0
 public function getInstance()
 {
     // Instantiate itself if not instantiated
     if (self::$instance === NULL) {
         self::$instance = new Logger();
     }
     return self::$instance;
 }
Ejemplo n.º 14
0
 protected static function getInstance()
 {
     if (self::$instance === NULL) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }
Ejemplo n.º 15
0
 /**
  * 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);
 }
Ejemplo n.º 16
0
 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;
 }
Ejemplo n.º 17
0
 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;
 }
Ejemplo n.º 18
0
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         $class = __CLASS__;
         //获取本对象的类名
         self::$instance = new $class();
     }
     return self::$instance;
 }
Ejemplo n.º 19
0
 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());
 }
Ejemplo n.º 20
0
 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'));
 }
Ejemplo n.º 21
0
 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();
 }
Ejemplo n.º 22
0
/**
 * 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
}
Ejemplo n.º 23
0
 /**
  * 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;
 }
Ejemplo n.º 24
0
 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);
 }
Ejemplo n.º 25
0
 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;
 }
Ejemplo n.º 26
0
 /**
  * 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') . '">&laquo; 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 . '">&laquo; Back to homepage</a></p>';
     }
     // if
     $error_message .= '</div>';
     print $error_message;
     die;
 }
Ejemplo n.º 27
0
 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);
 }
Ejemplo n.º 29
0
/**
 * 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
}
Ejemplo n.º 30
0
 /**
  * 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');
 }