Subversion Repositories Web Services

Compare Revisions

Ignore whitespace Rev 120063 → Rev 120114

/class_lib/trunk/curl_class.php
160,22 → 160,12
$this->wait_for_connections = PHP_INT_MAX;
 
if (!function_exists('curl_init')) {
if (method_exists('verbose', 'log')) {
verbose::log(FATAL, "PHP was not built with curl, rebuild PHP to use the curl class.");
}
elseif (function_exists('verbose')) {
verbose(FATAL, "PHP was not built with curl, rebuild PHP to use the curl class.");
}
self::local_verbose(FATAL, "PHP was not built with curl, rebuild PHP to use the curl class.");
return FALSE;
}
 
if (!isset($curl_default_options)) {
if (method_exists('verbose', 'log')) {
verbose::log(ERROR, '$curl_default_options is not defined. See the class description for usage');
}
elseif (function_exists('verbose')) {
verbose(ERROR, '$curl_default_options is not defined. See the class description for usage');
}
self::local_verbose(ERROR, '$curl_default_options is not defined. See the class description for usage');
return FALSE;
}
else
639,4 → 629,20
return strlen($header_line);
}
 
/** \brief -
* @param string $level
* @param string $msg
*/
private function local_verbose($level, $msg) {
if (method_exists('VerboseJson', 'log')) {
VerboseJson::log($level, $msg);
}
elseif (method_exists('verbose', 'log')) {
verbose::log($level, $msg);
}
elseif (function_exists('verbose')) {
verbose($level, $msg);
}
}
 
}
/class_lib/trunk/oci_class.php
646,7 → 646,11
* @param $msg string
*/
private function oci_log($log_level, $msg) {
if (method_exists('verbose', 'log'))
verbose::log($log_level, $msg);
if (method_exists('VerboseJson', 'log')) {
VerboseJson::log($level, $msg);
}
elseif (method_exists('verbose', 'log')) {
verbose::log($level, $msg);
}
}
}
/class_lib/trunk/webServiceServer_class.php
27,7 → 27,7
*/
 
require_once('OLS_class_lib/curl_class.php');
require_once('OLS_class_lib/verbose_class.php');
require_once('OLS_class_lib/verbose_json_class.php');
require_once('OLS_class_lib/inifile_class.php');
require_once('OLS_class_lib/timer_class.php');
require_once('OLS_class_lib/aaa_class.php');
90,9 → 90,7
if (self::in_house())
$this->debug = $_REQUEST['debug'];
$this->version = $this->config->get_value('version', 'setup');
verbose::open($this->config->get_value('logfile', 'setup'),
$this->config->get_value('verbose', 'setup'),
str_replace('_VERSION_', $this->version, $this->config->get_value('syslog_id', 'setup')));
VerboseJson::open($this->config->get_section('setup'));
$this->watch = new stopwatch('', ' ', '', '%s:%01.3f');
 
if ($this->config->get_value('xmldir'))
165,7 → 163,7
* @param $xml string
*/
private function soap_request($xml) {
// Debug verbose::log(TRACE, 'Request ' . $xml);
// Debug VerboseJson::log(TRACE, array('request' => $xml));
 
// validate request
$this->validate = $this->config->get_value('validate');
233,8 → 231,9
echo $response_xml;
}
// request done and response send, dump timer
if ($this->dump_timer)
verbose::log(TIMER, sprintf($this->dump_timer, $this->soap_action) . ':: ' . $this->dump_timer_ip . $this->watch->dump());
if ($this->dump_timer) {
VerboseJson::log(TIMER, array_merge(array('action' => $this->soap_action), $this->watch->get_timers()));
}
}
else
self::soap_error('Error in response validation.');
591,6 → 590,8
if ($this->soap_action = array_search($request, $soapActions)) {
$params = $xmlobj->$request->_value;
if (method_exists($this, $this->soap_action)) {
VerboseJson::set_action($this->soap_action);
VerboseJson::set_tracking_id($this->config->get_value('default_namespace_prefix', 'setup'), $params->trackingId->_value);
if (is_object($this->aaa)) {
foreach (array('authentication', 'userIdAut', 'groupIdAut', 'passwordAut') as $par) {
if (!$$par = $this->config->get_value($par, 'aaa')) {
603,7 → 604,6
$auth->$passwordAut->_value,
$_SERVER['REMOTE_ADDR']);
}
verbose::set_tracking_id($this->config->get_value('default_namespace_prefix', 'setup'), $params->trackingId->_value);
self::update_registry($this->soap_action);
return $this->{$this->soap_action}($params);
}
/class_lib/trunk/format_class.php
104,10 → 104,10
for ($no = 0; $no < count($records); $no = $no + $this->record_blocking) {
$cache_key[$curls] = self::make_cache_key($records[$no]->_value->collection->_value->object, $param);
if ($ret[$no] = $this->cache->get($cache_key[$curls])) {
verbose::log(DEBUG, 'format cache hit ' . $cache_key[$curls]);
self::local_verbose(DEBUG, 'format cache hit ' . $cache_key[$curls]);
continue;
}
verbose::log(DEBUG, 'no format cache hit');
self::local_verbose(DEBUG, 'no format cache hit');
$ret_index[$curls] = $no;
$form_req->formatSingleManifestationRequest->_value->originalData = &$records[$tot_curls];
$this->curl->set_option(CURLOPT_TIMEOUT, $this->timeout, $curls);
139,7 → 139,7
}
}
else {
verbose::log(ERROR, 'http code: ' . $curl_status[$i]['http_code'] .
self::local_verbose(ERROR, 'http code: ' . $curl_status[$i]['http_code'] .
' error: "' . $curl_status[$i]['error'] .
'" for: ' . $curl_status[$i]['url'] .
' TId: ' . $param->trackingId->_value);
208,4 → 208,16
$param->outputFormat->_value);
}
 
/** \brief -
* @param string $level
* @param string $msg
*/
private function local_verbose($level, $msg) {
if (method_exists('VerboseJson', 'log')) {
VerboseJson::log($level, $msg);
}
elseif (method_exists('verbose', 'log')) {
verbose::log($level, $msg);
}
}
}
/class_lib/trunk/verbose_json_class.php
0,0 → 1,180
<?php
 
/**
*
* This file is part of Open Library System.
* Copyright © 2018, Dansk Bibliotekscenter a/s,
* Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
*
* Open Library System is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Open Library System is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Open Library System. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \brief Verbose singleton class for loggin to a file or syslog
* Use syslog://[facility] as filename for writing to syslog. facility defaults to LOG_LOCAL0
*
* Usage: \n
* verbose::open(logfile_name, log_mask); \n
* verbose::log(FATAL,'could not find value x')\n
*
* Example:
* verbose::open('syslog://LOG_LOCAL0', log_mask); \n
* verbose::log(FATAL,'could not find value x')\n
*
* Example:
* verbose::open('my_trace_file.log', 'WARNING+FATAL+TIMER'); \n
* verbose::log(FATAL, 'Cannot find database');\n
*
* Example:
* verbose::open('my_trace_file.log', WARNING+FATAL+TIMER); \n
* verbose::log(FATAL, 'Cannot find database');\n
*
* Example (will add process-id to all verbose lines):
* verbose::open('my_trace_file.log', PID+WARNING+FATAL+TIMER); \n
* verbose::log(FATAL, 'Cannot find database');\n
*
* Example:
* verbose::open('my_trace_file.log', 77, 'H:i:s d:m:y'); \n
* verbose::log(TRACE, 'db::look_up_user()');\n
*
* @author Finn Stausgaard - DBC
* */
@ define('WARNING', 0x01);
@ define('ERROR', 0x02);
@ define('FATAL', 0x04);
@ define('STAT', 0x08);
@ define('TIMER', 0x10);
@ define('DEBUG', 0x20);
@ define('TRACE', 0x40);
@ define('Z3950', 0x80);
@ define('OCI', 0x100);
 
@ define('SYSLOG_PREFIX', 'syslog://');
 
/**
* Class verbose
*/
class VerboseJson {
 
static $verbose_file_name; ///< -
static $syslog_facility = NULL; ///< -
static $syslog_id = ''; ///< -
static $style = 'json'; ///< -
static $verbose_mask; ///< -
static $date_format; ///< -
static $ip = ''; ///< -
static $action = ''; ///< -
static $tracking_id = ''; ///< -
 
/**
* verbose constructor.
*/
private function __construct() {
}
 
private function __clone() {
}
 
/**
* \brief Sets loglevel and logfile
* @param array $settings
* */
static public function open($settings) {
self::$tracking_id = date('Y-m-d\TH:i:s:') . substr((string)microtime(), 2, 6) . ':' . getmypid();
if (!self::$date_format = $settings['date_format'])
self::$date_format = 'H:i:s-d/m/y';
self::$verbose_file_name = $settings['logfile'];
if (strtolower(substr(self::$verbose_file_name, 0, strlen(SYSLOG_PREFIX))) == SYSLOG_PREFIX) {
$facility = substr(self::$verbose_file_name, strlen(SYSLOG_PREFIX)); // syslog://[facility]
self::$syslog_facility = defined($facility) ? constant($facility) : LOG_LOCAL0;
self::$syslog_id = $settings['syslog_id'];
}
if (!is_string($settings['verbose'])) {
self::$verbose_mask = (empty($settings['verbose']) ? 0 : $settings['level']);
}
else {
foreach (explode('+', $settings['verbose']) as $vm) {
if (defined(trim($vm)))
self::$verbose_mask |= constant(trim($vm));
}
}
if (strtolower($settings['logstyle']) == 'string') {
self::$style = 'string';
}
self::$ip = $_SERVER['REMOTE_ADDR'];
}
 
/**
* \brief Logs to a file, or prints out log message.
* @param integer $verbose_level Level of verbose output
* @param mixed $mixed List of values to log
*/
static public function log($verbose_level, $mixed) {
$text_level = array(WARNING => 'WARNING', ERROR => 'ERROR', FATAL => 'FATAL', STAT => 'STAT', TIMER => 'TIMER', DEBUG => 'DEBUG', TRACE => 'TRACE', Z3950 => 'Z3950', OCI => 'OCI');
if (self::$verbose_file_name && $verbose_level & self::$verbose_mask) {
if (!$vtext = $text_level[$verbose_level]) $vtext = 'UNKNOWN';
 
$log_arr = array_merge(self::log_defaults($vtext), is_array($mixed) ? $mixed : array('message' => $mixed));
$log_str = (self::$style == 'string') ? self::stringify($log_arr) : json_encode($log_arr);
$json_log = str_replace(PHP_EOL, '', $log_str) . PHP_EOL;
if (self::$syslog_facility) {
openlog(self::$syslog_id, LOG_ODELAY, self::$syslog_facility);
syslog(LOG_INFO, $json_log);
closelog();
}
elseif ($fp = @ fopen(self::$verbose_file_name, 'a')) {
fwrite($fp, $json_log);
fclose($fp);
}
else
die('FATAL: Cannot open ' . self::$verbose_file_name . "getcwd:" . getcwd());
}
}
 
static private function stringify($arr) {
$ret = [];
foreach ($arr as $key => $val) {
$ret[] = $key . ':' . $val;
}
return implode(' ', $ret);
}
 
/**
* \brief Set array with default logging info
* @param string $level loglevel
* @return array
*/
static private function log_defaults($level) {
return array('level' => $level,
'timestamp' => date(self::$date_format),
'trackingId' => self::$tracking_id,
'action' => self::$action,
'ip' => self::$ip);
}
 
static public function set_action($action) {
self::$action = $action;
}
 
/**
* \brief Make a unique tracking id
* @param string $t_service_prefix Service prefix that identifies the service
* @param string $t_id Current tracking_id
* @return string
*/
static public function set_tracking_id($t_service_prefix, $t_id = '') {
self::$tracking_id = $t_service_prefix . ($t_service_prefix ? ':' : '') . self::$tracking_id . ($t_id ? '<' . $t_id : '');
return self::$tracking_id;
}
 
}
/class_lib/trunk/open_agency_v2_class.php
59,8 → 59,8
if (!isset($this->config['timeout'])) {
$this->config['timeout'] = 10;
}
if (class_exists('verbose')) {
$this->tracking_id = verbose::$tracking_id;
if (class_exists('VerboseJson')) {
$this->tracking_id = VerboseJson::$tracking_id;
}
}
 
406,7 → 406,10
* @param string $msg
*/
private function local_verbose($level, $msg) {
if (method_exists('verbose', 'log')) {
if (method_exists('VerboseJson', 'log')) {
VerboseJson::log($level, $msg);
}
elseif (method_exists('verbose', 'log')) {
verbose::log($level, $msg);
}
}
/class_lib/trunk/aaa_class.php
224,7 → 224,7
$this->fors_oci->connect();
}
catch (ociException $e) {
verbose::log(FATAL, 'AAA(' . __LINE__ . '):: OCI connect error: ' . $this->fors_oci->get_error_string());
self::local_verbose(FATAL, 'AAA(' . __LINE__ . '):: OCI connect error: ' . $this->fors_oci->get_error_string());
return FALSE;
}
$long_ip = ip2long($ip);
241,7 → 241,7
}
}
catch (ociException $e) {
verbose::log(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
self::local_verbose(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
$error = $this->fors_oci->get_error();
}
 
259,7 → 259,7
}
}
catch (ociException $e) {
verbose::log(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
self::local_verbose(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
$error = $this->fors_oci->get_error();
}
}
285,7 → 285,7
$this->fors_oci->connect();
}
catch (ociException $e) {
verbose::log(FATAL, 'AAA(' . __LINE__ . '):: OCI connect error: ' . $this->fors_oci->get_error_string());
self::local_verbose(FATAL, 'AAA(' . __LINE__ . '):: OCI connect error: ' . $this->fors_oci->get_error_string());
return FALSE;
}
try {
311,7 → 311,7
$rights = $this->fetch_rights_from_userid($userid, $group);
}
catch (ociException $e) {
verbose::log(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
self::local_verbose(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
$error = $this->fors_oci->get_error();
}
}
332,7 → 332,7
$this->fors_oci->connect();
}
catch (ociException $e) {
verbose::log(FATAL, 'AAA(' . __LINE__ . '):: OCI connect error: ' . $this->fors_oci->get_error_string());
self::local_verbose(FATAL, 'AAA(' . __LINE__ . '):: OCI connect error: ' . $this->fors_oci->get_error_string());
return $rights;
}
try {
355,13 → 355,26
}
}
catch (ociException $e) {
verbose::log(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
self::local_verbose(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
}
}
catch (ociException $e) {
verbose::log(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
self::local_verbose(FATAL, 'AAA(' . __LINE__ . '):: OCI select error: ' . $this->fors_oci->get_error_string());
}
return $rights;
}
 
/** \brief -
* @param string $level
* @param string $msg
*/
private function local_verbose($level, $msg) {
if (method_exists('VerboseJson', 'log')) {
VerboseJson::log($level, $msg);
}
elseif (method_exists('verbose', 'log')) {
verbose::log($level, $msg);
}
}
 
}