From dac42aa68501382bd487df88da9ba373edf50a25 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Sat, 15 Aug 2009 11:15:43 +0000 Subject: [PATCH] =?UTF-8?q?La=20fonction=20{{{spip=5Flog}}}=C2=A0se=20r?= =?UTF-8?q?=C3=A9duit=20=C3=A0=20pr=C3=A9sent=20=C3=A0=20appeller=20la=20f?= =?UTF-8?q?onction=20surchargeable=20{{{inc=5Flog=5Fdist}}},=20qui=20fait?= =?UTF-8?q?=20la=20m=C3=AAme=20chose=20qu'avant=20=20en=20standard.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 1 + ecrire/inc/log.php | 77 ++++++++++++++++++++++++++++++++++++++++++++ ecrire/inc/utils.php | 60 ++-------------------------------- 3 files changed, 80 insertions(+), 58 deletions(-) create mode 100644 ecrire/inc/log.php diff --git a/.gitattributes b/.gitattributes index 7fcfc90e4e..c303d268fb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -248,6 +248,7 @@ ecrire/inc/json.php -text ecrire/inc/lang_liste.php -text ecrire/inc/legender.php -text ecrire/inc/lien.php -text +ecrire/inc/log.php -text ecrire/inc/mail.php -text ecrire/inc/meme_rubrique.php -text ecrire/inc/message_select.php -text diff --git a/ecrire/inc/log.php b/ecrire/inc/log.php new file mode 100644 index 0000000000..5fd42b8ec2 --- /dev/null +++ b/ecrire/inc/log.php @@ -0,0 +1,77 @@ +<?php + +/***************************************************************************\ + * SPIP, Systeme de publication pour l'internet * + * * + * Copyright (c) 2001-2009 * + * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * + * * + * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * + * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * +\***************************************************************************/ + +if (!defined("_ECRIRE_INC_VERSION")) return; + +function inc_log_dist($message, $logname=NULL, $logdir=NULL, $logsuf=NULL) { + + static $compteur = array(); + global $nombre_de_logs, $taille_des_logs; + + if (is_null($logname)) + $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; + if (!isset($compteur[$logname])) $compteur[$logname] = 0; + if ($logname != 'maj' + AND defined('_MAX_LOG') + AND ( + $compteur[$logname]++ > _MAX_LOG + OR !$nombre_de_logs + OR !$taille_des_logs + )) + return; + + $logfile = ($logdir===NULL ? _DIR_LOG : $logdir) + . (test_espace_prive()?'prive_':'') //distinguer les logs prives et publics + . ($logname) + . ($logsuf===NULL ? _FILE_LOG_SUFFIX : $logsuf); + + // si spip_log() dans mes_options, poser dans spip.log + if (!defined('_DIR_LOG')) + $logfile = _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES.$logname.'.log'; + + $rotate = 0; + $pid = '(pid '.@getmypid().')'; + + // accepter spip_log( Array ) + if (!is_string($message)) $message = var_export($message, true); + + $m = date("M d H:i:s").' '.$GLOBALS['ip'].' '.$pid.' ' + .preg_replace("/\n*$/", "\n", $message); + + + if (@is_readable($logfile) + AND (!$s = @filesize($logfile) OR $s > $taille_des_logs * 1024)) { + $rotate = $nombre_de_logs; + $m .= "[-- rotate --]\n"; + } + + $f = @fopen($logfile, "ab"); + if ($f) { + fputs($f, ($logname!==NULL) ? $m : str_replace('<','<',$m)); + fclose($f); + } + + if ($rotate-- > 0 + AND function_exists('spip_unlink')) { + spip_unlink($logfile . '.' . $rotate); + while ($rotate--) { + @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); + } + } + + // Dupliquer les erreurs specifiques dans le log general + if ($logname !== _FILE_LOG + AND defined('_FILE_LOG')) + spip_log($logname=='maj' ? 'cf maj.log' : $message); +} + +?> diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php index 808405e65e..5aee8eb3b8 100644 --- a/ecrire/inc/utils.php +++ b/ecrire/inc/utils.php @@ -149,64 +149,8 @@ function pipeline($action, $val=null) { // // http://doc.spip.org/@spip_log function spip_log($message, $logname=NULL, $logdir=NULL, $logsuf=NULL) { - static $compteur = array(); - global $nombre_de_logs, $taille_des_logs; - - if (is_null($logname)) - $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; - if (!isset($compteur[$logname])) $compteur[$logname] = 0; - if ($logname != 'maj' - AND defined('_MAX_LOG') - AND ( - $compteur[$logname]++ > _MAX_LOG - OR !$nombre_de_logs - OR !$taille_des_logs - )) - return; - - $logfile = ($logdir===NULL ? _DIR_LOG : $logdir) - . (test_espace_prive()?'prive_':'') //distinguer les logs prives et publics - . ($logname) - . ($logsuf===NULL ? _FILE_LOG_SUFFIX : $logsuf); - - // si spip_log() dans mes_options, poser dans spip.log - if (!defined('_DIR_LOG')) - $logfile = _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES.$logname.'.log'; - - $rotate = 0; - $pid = '(pid '.@getmypid().')'; - - // accepter spip_log( Array ) - if (!is_string($message)) $message = var_export($message, true); - - $m = date("M d H:i:s").' '.$GLOBALS['ip'].' '.$pid.' ' - .preg_replace("/\n*$/", "\n", $message); - - - if (@is_readable($logfile) - AND (!$s = @filesize($logfile) OR $s > $taille_des_logs * 1024)) { - $rotate = $nombre_de_logs; - $m .= "[-- rotate --]\n"; - } - - $f = @fopen($logfile, "ab"); - if ($f) { - fputs($f, ($logname!==NULL) ? $m : str_replace('<','<',$m)); - fclose($f); - } - - if ($rotate-- > 0 - AND function_exists('spip_unlink')) { - spip_unlink($logfile . '.' . $rotate); - while ($rotate--) { - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); - } - } - - // Dupliquer les erreurs specifiques dans le log general - if ($logname !== _FILE_LOG - AND defined('_FILE_LOG')) - spip_log($logname=='maj' ? 'cf maj.log' : $message); + $log = charger_fonction('log', 'inc'); + $log( $message, $logname, $logdir, $logsuf); } // Renvoie le _GET ou le _POST emis par l'utilisateur -- GitLab