/** * @runInSeparateProcess */ public function testColorize() { $msg = 'Test message'; JAXLLogger::$colorize = false; $this->assertEquals($msg, JAXLLogger::colorize($msg, JAXLLogger::ERROR)); JAXLLogger::$colorize = true; $this->assertNotEquals($msg, JAXLLogger::colorize($msg, JAXLLogger::ERROR)); $color = 123; JAXLLogger::setColors(array(JAXLLogger::ERROR => $color)); $this->assertEquals("[" . $color . "m" . $msg . "[0m", JAXLLogger::colorize($msg, JAXLLogger::ERROR)); }
function _colorize($msg, $verbosity) { error_log(JAXLLogger::colorize($msg, $verbosity)); }
/** * @param array $config */ public function __construct(array $config) { $cfg_defaults = array('auth_type' => 'PLAIN', 'bosh_hold' => null, 'bosh_rid' => null, 'bosh_url' => null, 'bosh_wait' => null, 'domain' => null, 'force_tls' => false, 'host' => null, 'jid' => null, 'log_colorize' => $this->log_colorize, 'log_level' => $this->log_level, 'log_path' => JAXLLogger::$path, 'multi_client' => false, 'pass' => false, 'port' => null, 'priv_dir' => getcwd() . '/.jaxl', 'protocol' => null, 'resource' => null, 'stream_context' => null, 'strict' => true); $this->cfg = array_merge($cfg_defaults, $config); // setup logger JAXLLogger::$path = $this->cfg['log_path']; JAXLLogger::$level = $this->log_level = $this->cfg['log_level']; JAXLLogger::$colorize = $this->log_colorize = $this->cfg['log_colorize']; // env if ($this->cfg['strict']) { JAXLLogger::info("strict mode enabled, adding exception handlers. ' .\n 'Set 'strict' => false inside JAXL config to disable this"); JAXLException::addHandlers(); } $this->mode = PHP_SAPI; $this->local_ip = gethostbyname(php_uname('n')); $this->pid = getmypid(); // jid object $jid = $this->cfg['jid'] !== null ? new XMPPJid($this->cfg['jid']) : null; // handle signals if (extension_loaded('pcntl')) { pcntl_signal(SIGHUP, array($this, 'signal_handler')); pcntl_signal(SIGINT, array($this, 'signal_handler')); pcntl_signal(SIGTERM, array($this, 'signal_handler')); } // Create .jaxl directory for our /tmp, /run and /log folders // overwrite these using jaxl config array $this->priv_dir = $this->cfg['priv_dir']; $this->tmp_dir = $this->priv_dir . "/tmp"; $this->pid_dir = $this->priv_dir . "/run"; $this->log_dir = $this->priv_dir . "/log"; $this->sock_dir = $this->priv_dir . "/sock"; if (!is_dir($this->priv_dir)) { mkdir($this->priv_dir); } if (!is_dir($this->tmp_dir)) { mkdir($this->tmp_dir); } if (!is_dir($this->pid_dir)) { mkdir($this->pid_dir); } if (!is_dir($this->log_dir)) { mkdir($this->log_dir); } if (!is_dir($this->sock_dir)) { mkdir($this->sock_dir); } // touch pid file if ($this->mode == "cli") { touch($this->get_pid_file_path()); JAXLLogger::info("created pid file " . $this->get_pid_file_path()); } // include mandatory xmpp xeps // service discovery and entity caps // are recommended for every xmpp entity $this->require_xep(array('0030', '0115')); // do dns lookup, update $cfg['host'] and $cfg['port'] if not already specified if (($this->cfg['host'] === null || $this->cfg['port'] === null) && $jid) { // this dns lookup is blocking JAXLLogger::info("dns srv lookup for " . $jid->domain); list($host, $port) = JAXLUtil::get_dns_srv($jid->domain); if ($this->cfg['host'] === null) { $this->cfg['host'] = $host; } if ($this->cfg['port'] === null) { $this->cfg['port'] = $port; } } // choose appropriate transport // if 'bosh_url' cfg is defined include 0206 if (isset($this->cfg['bosh_url'])) { JAXLLogger::debug("including bosh xep"); $this->require_xep('0206'); $transport = $this->xeps['0206']; } else { $transport = new JAXLSocketClient($this->cfg['stream_context']); } // lifecycle events callback $this->ev = new JAXLEvent($this->cfg['multi_client'] ? array(&$this) : array()); // initialize xmpp stream with configured transport parent::__construct($transport, $jid, $this->cfg['pass'], $this->cfg['resource'] !== null ? 'jaxl#' . $this->cfg['resource'] : 'jaxl#' . md5(time()), $this->cfg['force_tls']); }