Changeset 31102
- Timestamp:
- Apr 24, 2015, 4:00:50 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/i.php
r28587 r31102 31 31 @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'config/database.inc.php'); 32 32 33 include(PHPWG_ROOT_PATH . 'include/Logger.class.php'); 34 35 $logger = new Logger(array( 36 'directory' => PHPWG_ROOT_PATH . $conf['data_location'] . $conf['log_dir'], 37 'severity' => $conf['log_level'], 38 // we use an hashed filename to prevent direct file access, and we salt with 39 // the db_password instead of secret_key because the log must be usable in i.php 40 // (secret_key is in the database) 41 'filename' => 'log_' . date('Y-m-d') . '_' . sha1(date('Y-m-d') . $conf['db_password']) . '.txt', 42 )); 43 33 44 34 45 function trigger_notify() {} … … 67 78 // end fast bootstrap 68 79 69 function ilog()70 {71 global $conf;72 if (!$conf['enable_i_log']) return;73 74 $line = date("c");75 foreach( func_get_args() as $arg)76 {77 $line .= ' ';78 if (is_array($arg))79 {80 $line .= implode(' ', $arg);81 }82 else83 {84 $line .= $arg;85 }86 }87 $file=PHPWG_ROOT_PATH.$conf['data_location'].'tmp/i.log';88 if (false == file_put_contents($file, $line."\n", FILE_APPEND))89 {90 mkgetdir(dirname($file));91 }92 }93 94 80 function ierror($msg, $code) 95 81 { 82 global $logger; 96 83 if ($code==301 || $code==302) 97 84 { … … 102 89 // default url is on html format 103 90 $url = html_entity_decode($msg); 91 $logger->warning($code . ' ' . $url, 'i.php', array( 92 'url' => $_SERVER['REQUEST_URI'], 93 )); 104 94 header('Request-URI: '.$url); 105 95 header('Content-Location: '.$url); 106 96 header('Location: '.$url); 107 ilog('WARN', $code, $url, $_SERVER['REQUEST_URI']);108 97 exit; 109 98 } … … 118 107 //todo improve 119 108 echo $msg; 120 ilog('ERROR', $code, $msg, $_SERVER['REQUEST_URI']); 109 $logger->error($code . ' ' . $msg, 'i.php', array( 110 'url' => $_SERVER['REQUEST_URI'], 111 )); 121 112 exit; 122 113 } … … 405 396 catch (Exception $e) 406 397 { 407 ilog("db error", $e->getMessage());398 $logger->error($e->getMessage(), 'i.php'); 408 399 } 409 400 pwg_db_check_charset(); … … 502 493 catch (Exception $e) 503 494 { 504 ilog("db error", $e->getMessage());495 $logger->error($e->getMessage(), 'i.php'); 505 496 } 506 497 } … … 622 613 $timing['send'] = time_step($step); 623 614 624 ilog('perf', 625 basename($page['src_path']), $o_size, $o_size[0]*$o_size[1], 626 basename($page['derivative_path']), $d_size, $d_size[0]*$d_size[1], 627 function_exists('memory_get_peak_usage') ? round( memory_get_peak_usage()/(1024*1024), 1) : '', 628 time_step($begin), 629 '|', $timing); 630 ?> 615 $timing['total'] = time_step($begin); 616 617 if ($logger->severity() >= Logger::INFO) 618 { 619 $logger->info('perf', 'i.php', array( 620 'src_path' => basename($page['src_path']), 621 'derivative_path' => basename($page['derivative_path']), 622 'o_size' => $o_size[0] . ' ' . $o_size[1] . ' ' . ($o_size[0]*$o_size[1]), 623 'd_size' => $d_size[0] . ' ' . $d_size[1] . ' ' . ($d_size[0]*$d_size[1]), 624 'mem_usage' => function_exists('memory_get_peak_usage') ? round( memory_get_peak_usage()/(1024*1024), 1) : '', 625 'timing' => $timing, 626 )); 627 } -
trunk/include/common.inc.php
r29904 r31102 105 105 include(PHPWG_ROOT_PATH . 'include/constants.php'); 106 106 include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); 107 include(PHPWG_ROOT_PATH . 'include/template.class.php'); 108 include(PHPWG_ROOT_PATH . 'include/cache.class.php'); 109 include(PHPWG_ROOT_PATH . 'include/Logger.class.php'); 107 110 108 111 $persistent_cache = new PersistentFileCache(); … … 122 125 123 126 load_conf_from_db(); 127 128 $logger = new Logger(array( 129 'directory' => PHPWG_ROOT_PATH . $conf['data_location'] . $conf['log_dir'], 130 'severity' => $conf['log_level'], 131 // we use an hashed filename to prevent direct file access, and we salt with 132 // the db_password instead of secret_key because the log must be usable in i.php 133 // (secret_key is in the database) 134 'filename' => 'log_' . date('Y-m-d') . '_' . sha1(date('Y-m-d') . $conf['db_password']) . '.txt', 135 'globPattern' => 'log_*.txt', 136 'archiveDays' => $conf['log_archive_days'], 137 )); 124 138 125 139 if (!$conf['check_upgrade_feed']) -
trunk/include/config_default.inc.php
r31097 r31102 463 463 $conf['show_php_errors'] = E_ALL; 464 464 465 // enable log for i derivative script466 $conf['enable_i_log'] = false;467 465 468 466 // +-----------------------------------------------------------------------+ … … 653 651 // Web services are allowed (true) or completely forbidden (false) 654 652 $conf['allow_web_services'] = true; 655 656 // enable log for web services657 $conf['ws_enable_log'] = false;658 659 // web services log file path660 $conf['ws_log_filepath'] = '/tmp/piwigo_ws.log';661 653 662 654 // Maximum number of images to be returned foreach call to the web service … … 813 805 // the directory where "ffmpeg" executable is. 814 806 $conf['ffmpeg_dir'] = ''; 815 ?> 807 808 // +-----------------------------------------------------------------------+ 809 // | log | 810 // +-----------------------------------------------------------------------+ 811 // Logs directory, relative to $conf['data_location'] 812 $conf['log_dir'] = '/logs'; 813 814 // Log level (OFF, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG) 815 // development = DEBUG, production = ERROR 816 $conf['log_level'] = 'DEBUG'; 817 818 // Keep logs file during X days 819 $conf['log_archive_days'] = 30; -
trunk/include/functions.inc.php
r30864 r31102 37 37 include_once( PHPWG_ROOT_PATH .'include/derivative_std_params.inc.php'); 38 38 include_once( PHPWG_ROOT_PATH .'include/derivative.inc.php'); 39 include_once( PHPWG_ROOT_PATH .'include/template.class.php');40 include_once( PHPWG_ROOT_PATH .'include/cache.class.php');41 39 42 40 -
trunk/include/ws_functions.inc.php
r26461 r31102 206 206 207 207 /** 208 * Writes info to the log file209 */210 function ws_logfile($string)211 {212 global $conf;213 214 if (!$conf['ws_enable_log'])215 {216 return true;217 }218 219 file_put_contents(220 $conf['ws_log_filepath'],221 '['.date('c').'] '.$string."\n",222 FILE_APPEND223 );224 }225 226 /**227 208 * create a tree from a flat list of categories, no recursivity for high speed 228 209 */ -
trunk/include/ws_functions/pwg.images.php
r31031 r31102 183 183 function merge_chunks($output_filepath, $original_sum, $type) 184 184 { 185 global $conf ;186 187 ws_logfile('[merge_chunks] input parameter $output_filepath : '.$output_filepath);185 global $conf, $logger; 186 187 $logger->debug('[merge_chunks] input parameter $output_filepath : '.$output_filepath, 'WS'); 188 188 189 189 if (is_file($output_filepath)) … … 207 207 if (preg_match($pattern, $file)) 208 208 { 209 ws_logfile($file);209 $logger->debug($file, 'WS'); 210 210 $chunks[] = $upload_dir.'/'.$file; 211 211 } … … 217 217 218 218 if (function_exists('memory_get_usage')) { 219 ws_logfile('[merge_chunks] memory_get_usage before loading chunks: '.memory_get_usage());219 $logger->debug('[merge_chunks] memory_get_usage before loading chunks: '.memory_get_usage(), 'WS'); 220 220 } 221 221 … … 227 227 228 228 if (function_exists('memory_get_usage')) { 229 ws_logfile('[merge_chunks] memory_get_usage on chunk '.++$i.': '.memory_get_usage());229 $logger->debug('[merge_chunks] memory_get_usage on chunk '.++$i.': '.memory_get_usage(), 'WS'); 230 230 } 231 231 … … 239 239 240 240 if (function_exists('memory_get_usage')) { 241 ws_logfile('[merge_chunks] memory_get_usage after loading chunks: '.memory_get_usage());241 $logger->debug('[merge_chunks] memory_get_usage after loading chunks: '.memory_get_usage(), 'WS'); 242 242 } 243 243 } … … 825 825 function ws_images_add_chunk($params, $service) 826 826 { 827 global $conf ;827 global $conf, $logger; 828 828 829 829 foreach ($params as $param_key => $param_value) … … 833 833 continue; 834 834 } 835 ws_logfile( 836 sprintf( 837 '[ws_images_add_chunk] input param "%s" : "%s"', 838 $param_key, 839 is_null($param_value) ? 'NULL' : $param_value 840 ) 841 ); 835 836 $logger->debug(sprintf( 837 '[ws_images_add_chunk] input param "%s" : "%s"', 838 $param_key, 839 is_null($param_value) ? 'NULL' : $param_value 840 ), 'WS'); 842 841 } 843 842 … … 857 856 ); 858 857 859 ws_logfile('[ws_images_add_chunk] data length : '.strlen($params['data']));858 $logger->debug('[ws_images_add_chunk] data length : '.strlen($params['data']), 'WS'); 860 859 861 860 $bytes_written = file_put_contents( … … 882 881 function ws_images_addFile($params, $service) 883 882 { 884 ws_logfile(__FUNCTION__.', input : '.var_export($params, true));885 886 global $conf;883 global $conf, $logger; 884 885 $logger->debug(__FUNCTION__, 'WS', $params); 887 886 888 887 // what is the path and other infos about the photo? … … 975 974 function ws_images_add($params, $service) 976 975 { 977 global $conf, $user ;976 global $conf, $user, $logger; 978 977 979 978 foreach ($params as $param_key => $param_value) 980 979 { 981 ws_logfile( 982 sprintf( 983 '[pwg.images.add] input param "%s" : "%s"', 984 $param_key, 985 is_null($param_value) ? 'NULL' : $param_value 986 ) 987 ); 980 $logger->debug(sprintf( 981 '[pwg.images.add] input param "%s" : "%s"', 982 $param_key, 983 is_null($param_value) ? 'NULL' : $param_value 984 ), 'WS'); 988 985 } 989 986 … … 1399 1396 function ws_images_exist($params, $service) 1400 1397 { 1401 ws_logfile(__FUNCTION__.' '.var_export($params, true));1402 1403 global $conf;1398 global $conf, $logger; 1399 1400 $logger->debug(__FUNCTION__, 'WS', $params); 1404 1401 1405 1402 $split_pattern = '/[\s,;\|]/'; … … 1472 1469 function ws_images_checkFiles($params, $service) 1473 1470 { 1474 ws_logfile(__FUNCTION__.', input : '.var_export($params, true)); 1471 global $logger; 1472 1473 $logger->debug(__FUNCTION__, 'WS', $params); 1475 1474 1476 1475 $query = ' … … 1510 1509 if (isset($compare_type)) 1511 1510 { 1512 ws_logfile(__FUNCTION__.', md5_file($path) = '.md5_file($path));1511 $logger->debug(__FUNCTION__.', md5_file($path) = '.md5_file($path), 'WS'); 1513 1512 if (md5_file($path) != $params[$compare_type.'_sum']) 1514 1513 { … … 1521 1520 } 1522 1521 1523 ws_logfile(__FUNCTION__.', output : '.var_export($ret, true));1522 $logger->debug(__FUNCTION__, 'WS', $ret); 1524 1523 1525 1524 return $ret;
Note: See TracChangeset
for help on using the changeset viewer.