Completed
Push — master ( 5fac66...ab2760 )
by cam
01:01
created
ecrire/inc/log.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -11,109 +11,109 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) {
18
-	static $test_repertoire = [];
19
-	static $compteur = [];
20
-	static $debugverb = ''; // pour ne pas le recalculer au reappel
21
-
22
-	if (is_null($logname) or !is_string($logname)) {
23
-		$logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip';
24
-	}
25
-	if (!isset($compteur[$logname])) {
26
-		$compteur[$logname] = 0;
27
-	}
28
-	if (
29
-		$logname != 'maj'
30
-		and defined('_MAX_LOG')
31
-		and (
32
-			$compteur[$logname]++ > _MAX_LOG
33
-			or !$GLOBALS['nombre_de_logs']
34
-			or !$GLOBALS['taille_des_logs']
35
-		)
36
-	) {
37
-		return;
38
-	}
39
-
40
-	// si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies
41
-	$logfile =
42
-		($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES))
43
-		.$logname
44
-		.($logsuf ?? (defined ('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log'));
45
-
46
-	if (!isset($test_repertoire[$d = dirname($logfile)])) {
47
-		$test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
48
-		$test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
49
-			$d,
50
-			'',
51
-			false,
52
-			true
53
-		) : false));
54
-	}
55
-
56
-	// Si le repertoire défini n'existe pas, poser dans tmp/
57
-	if (!$test_repertoire[$d]) {
58
-		$logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
59
-	}
60
-
61
-	$rotate = 0;
62
-	$pid = '(pid ' . @getmypid() . ')';
63
-
64
-	// accepter spip_log( Array )
65
-	if (!is_string($message)) {
66
-		$message = var_export($message, true);
67
-	}
68
-
69
-	if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
70
-		$debug = debug_backtrace();
71
-		$l = $debug[1]['line'];
72
-		$fi = $debug[1]['file'];
73
-		if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
74
-			$fi = substr($fi, strlen(_ROOT_RACINE));
75
-		}
76
-		$fu = $debug[2]['function'] ?? '';
77
-		$debugverb = "$fi:L$l:$fu" . '():';
78
-	}
79
-
80
-	$m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' '
81
-		//distinguer les logs prives et publics dans les grep
82
-		. $debugverb
83
-		. (test_espace_prive() ? ':Pri:' : ':Pub:')
84
-		. preg_replace("/\n*$/", "\n", $message);
85
-
86
-
87
-	if (
88
-		@is_readable($logfile)
89
-		and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
90
-	) {
91
-		$rotate = $GLOBALS['nombre_de_logs'];
92
-		$m .= "[-- rotate --]\n";
93
-	}
94
-
95
-	$f = @fopen($logfile, 'ab');
96
-	if ($f) {
97
-		fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
98
-		fclose($f);
99
-	}
100
-
101
-	if (
102
-		$rotate-- > 0
103
-		and function_exists('spip_unlink')
104
-	) {
105
-		spip_unlink($logfile . '.' . $rotate);
106
-		while ($rotate--) {
107
-			@rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
108
-		}
109
-	}
110
-
111
-	// Dupliquer les erreurs specifiques dans le log general
112
-	if (
113
-		defined('_FILE_LOG')
114
-		and ($logname !== _FILE_LOG)
115
-	) {
116
-		inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
117
-	}
118
-	$debugverb = '';
18
+    static $test_repertoire = [];
19
+    static $compteur = [];
20
+    static $debugverb = ''; // pour ne pas le recalculer au reappel
21
+
22
+    if (is_null($logname) or !is_string($logname)) {
23
+        $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip';
24
+    }
25
+    if (!isset($compteur[$logname])) {
26
+        $compteur[$logname] = 0;
27
+    }
28
+    if (
29
+        $logname != 'maj'
30
+        and defined('_MAX_LOG')
31
+        and (
32
+            $compteur[$logname]++ > _MAX_LOG
33
+            or !$GLOBALS['nombre_de_logs']
34
+            or !$GLOBALS['taille_des_logs']
35
+        )
36
+    ) {
37
+        return;
38
+    }
39
+
40
+    // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies
41
+    $logfile =
42
+        ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES))
43
+        .$logname
44
+        .($logsuf ?? (defined ('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log'));
45
+
46
+    if (!isset($test_repertoire[$d = dirname($logfile)])) {
47
+        $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
48
+        $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
49
+            $d,
50
+            '',
51
+            false,
52
+            true
53
+        ) : false));
54
+    }
55
+
56
+    // Si le repertoire défini n'existe pas, poser dans tmp/
57
+    if (!$test_repertoire[$d]) {
58
+        $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
59
+    }
60
+
61
+    $rotate = 0;
62
+    $pid = '(pid ' . @getmypid() . ')';
63
+
64
+    // accepter spip_log( Array )
65
+    if (!is_string($message)) {
66
+        $message = var_export($message, true);
67
+    }
68
+
69
+    if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
70
+        $debug = debug_backtrace();
71
+        $l = $debug[1]['line'];
72
+        $fi = $debug[1]['file'];
73
+        if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
74
+            $fi = substr($fi, strlen(_ROOT_RACINE));
75
+        }
76
+        $fu = $debug[2]['function'] ?? '';
77
+        $debugverb = "$fi:L$l:$fu" . '():';
78
+    }
79
+
80
+    $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' '
81
+        //distinguer les logs prives et publics dans les grep
82
+        . $debugverb
83
+        . (test_espace_prive() ? ':Pri:' : ':Pub:')
84
+        . preg_replace("/\n*$/", "\n", $message);
85
+
86
+
87
+    if (
88
+        @is_readable($logfile)
89
+        and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
90
+    ) {
91
+        $rotate = $GLOBALS['nombre_de_logs'];
92
+        $m .= "[-- rotate --]\n";
93
+    }
94
+
95
+    $f = @fopen($logfile, 'ab');
96
+    if ($f) {
97
+        fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
98
+        fclose($f);
99
+    }
100
+
101
+    if (
102
+        $rotate-- > 0
103
+        and function_exists('spip_unlink')
104
+    ) {
105
+        spip_unlink($logfile . '.' . $rotate);
106
+        while ($rotate--) {
107
+            @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
108
+        }
109
+    }
110
+
111
+    // Dupliquer les erreurs specifiques dans le log general
112
+    if (
113
+        defined('_FILE_LOG')
114
+        and ($logname !== _FILE_LOG)
115
+    ) {
116
+        inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
117
+    }
118
+    $debugverb = '';
119 119
 }
Please login to merge, or discard this patch.