X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Flog.php;fp=www%2Fecrire%2Finc%2Flog.php;h=33ace37a6ea5a3e9e31d37be25c1b9a1e9272579;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/ecrire/inc/log.php b/www/ecrire/inc/log.php new file mode 100644 index 0000000..33ace37 --- /dev/null +++ b/www/ecrire/inc/log.php @@ -0,0 +1,77 @@ + _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')) + inc_log_dist($logname=='maj' ? 'cf maj.log' : $message); +} + +?>