3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2017 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) {
17 function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) {
18 static $test_repertoire = array();
19 static $compteur = array();
20 static $debugverb = ''; // pour ne pas le recalculer au reappel
22 if (is_null($logname) or !is_string($logname)) {
23 $logname = defined('_FILE_LOG') ? _FILE_LOG
: 'spip';
25 if (!isset($compteur[$logname])) {
26 $compteur[$logname] = 0;
29 and defined('_MAX_LOG')
31 $compteur[$logname]++
> _MAX_LOG
32 or !$GLOBALS['nombre_de_logs']
33 or !$GLOBALS['taille_des_logs']
39 $logfile = ($logdir === null ? _DIR_LOG
: $logdir)
41 . ($logsuf === null ? _FILE_LOG_SUFFIX
: $logsuf);
43 if (!isset($test_repertoire[$d = dirname($logfile)])) {
44 $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
45 $test_repertoire[$d] = (@is_dir
($d) ?
true : (function_exists('sous_repertoire') ?
sous_repertoire(
53 // si spip_log() dans mes_options, ou repertoire log/ non present, poser dans tmp/
54 if (!defined('_DIR_LOG') or !$test_repertoire[$d]) {
55 $logfile = _DIR_RACINE
. _NOM_TEMPORAIRES_INACCESSIBLES
. $logname . '.log';
59 $pid = '(pid ' . @getmypid
() . ')';
61 // accepter spip_log( Array )
62 if (!is_string($message)) {
63 $message = var_export($message, true);
66 if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE
) {
67 $debug = debug_backtrace();
68 $l = $debug[1]['line'];
69 $fi = $debug[1]['file'];
70 if (strncmp($fi, _ROOT_RACINE
, strlen(_ROOT_RACINE
)) == 0) {
71 $fi = substr($fi, strlen(_ROOT_RACINE
));
73 $fu = isset($debug[2]['function']) ?
$debug[2]['function'] : '';
74 $debugverb = "$fi:L$l:$fu" . '():';
77 $m = date('Y-m-d H:i:s') . ' ' . (isset($GLOBALS['ip']) ?
$GLOBALS['ip'] : '') . ' ' . $pid . ' '
78 //distinguer les logs prives et publics dans les grep
80 . (test_espace_prive() ?
':Pri:' : ':Pub:')
81 . preg_replace("/\n*$/", "\n", $message);
84 if (@is_readable
($logfile)
85 and (!$s = @filesize
($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
87 $rotate = $GLOBALS['nombre_de_logs'];
88 $m .= "[-- rotate --]\n";
91 $f = @fopen
($logfile, 'ab');
93 fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT
) ?
$m : str_replace('<', '<', $m));
98 and function_exists('spip_unlink')
100 spip_unlink($logfile . '.' . $rotate);
102 @rename
($logfile . ($rotate ?
'.' . $rotate : ''), $logfile . '.' . ($rotate +
1));
106 // Dupliquer les erreurs specifiques dans le log general
107 if ($logname !== _FILE_LOG
108 and defined('_FILE_LOG')
110 inc_log_dist($logname == 'maj' ?
'cf maj.log' : $message);