Completed
Push — master ( 67c369...e5c422 )
by cam
01:28
created
ecrire/inc/log.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -11,107 +11,107 @@
 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
-	$logfile = ($logdir === null ? _DIR_LOG : $logdir)
41
-		. ($logname)
42
-		. ($logsuf === null ? _FILE_LOG_SUFFIX : $logsuf);
43
-
44
-	if (!isset($test_repertoire[$d = dirname($logfile)])) {
45
-		$test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
46
-		$test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
47
-			$d,
48
-			'',
49
-			false,
50
-			true
51
-		) : false));
52
-	}
53
-
54
-	// si spip_log() dans mes_options, ou repertoire log/ non present, poser dans tmp/
55
-	if (!defined('_DIR_LOG') or !$test_repertoire[$d]) {
56
-		$logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
57
-	}
58
-
59
-	$rotate = 0;
60
-	$pid = '(pid ' . @getmypid() . ')';
61
-
62
-	// accepter spip_log( Array )
63
-	if (!is_string($message)) {
64
-		$message = var_export($message, true);
65
-	}
66
-
67
-	if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
68
-		$debug = debug_backtrace();
69
-		$l = $debug[1]['line'];
70
-		$fi = $debug[1]['file'];
71
-		if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
72
-			$fi = substr($fi, strlen(_ROOT_RACINE));
73
-		}
74
-		$fu = isset($debug[2]['function']) ? $debug[2]['function'] : '';
75
-		$debugverb = "$fi:L$l:$fu" . '():';
76
-	}
77
-
78
-	$m = date('Y-m-d H:i:s') . ' ' . (isset($GLOBALS['ip']) ? $GLOBALS['ip'] : '') . ' ' . $pid . ' '
79
-		//distinguer les logs prives et publics dans les grep
80
-		. $debugverb
81
-		. (test_espace_prive() ? ':Pri:' : ':Pub:')
82
-		. preg_replace("/\n*$/", "\n", $message);
83
-
84
-
85
-	if (
86
-		@is_readable($logfile)
87
-		and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
88
-	) {
89
-		$rotate = $GLOBALS['nombre_de_logs'];
90
-		$m .= "[-- rotate --]\n";
91
-	}
92
-
93
-	$f = @fopen($logfile, 'ab');
94
-	if ($f) {
95
-		fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
96
-		fclose($f);
97
-	}
98
-
99
-	if (
100
-		$rotate-- > 0
101
-		and function_exists('spip_unlink')
102
-	) {
103
-		spip_unlink($logfile . '.' . $rotate);
104
-		while ($rotate--) {
105
-			@rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
106
-		}
107
-	}
108
-
109
-	// Dupliquer les erreurs specifiques dans le log general
110
-	if (
111
-		defined('_FILE_LOG')
112
-		and ($logname !== _FILE_LOG)
113
-	) {
114
-		inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
115
-	}
116
-	$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
+    $logfile = ($logdir === null ? _DIR_LOG : $logdir)
41
+        . ($logname)
42
+        . ($logsuf === null ? _FILE_LOG_SUFFIX : $logsuf);
43
+
44
+    if (!isset($test_repertoire[$d = dirname($logfile)])) {
45
+        $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
46
+        $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
47
+            $d,
48
+            '',
49
+            false,
50
+            true
51
+        ) : false));
52
+    }
53
+
54
+    // si spip_log() dans mes_options, ou repertoire log/ non present, poser dans tmp/
55
+    if (!defined('_DIR_LOG') or !$test_repertoire[$d]) {
56
+        $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
57
+    }
58
+
59
+    $rotate = 0;
60
+    $pid = '(pid ' . @getmypid() . ')';
61
+
62
+    // accepter spip_log( Array )
63
+    if (!is_string($message)) {
64
+        $message = var_export($message, true);
65
+    }
66
+
67
+    if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
68
+        $debug = debug_backtrace();
69
+        $l = $debug[1]['line'];
70
+        $fi = $debug[1]['file'];
71
+        if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
72
+            $fi = substr($fi, strlen(_ROOT_RACINE));
73
+        }
74
+        $fu = isset($debug[2]['function']) ? $debug[2]['function'] : '';
75
+        $debugverb = "$fi:L$l:$fu" . '():';
76
+    }
77
+
78
+    $m = date('Y-m-d H:i:s') . ' ' . (isset($GLOBALS['ip']) ? $GLOBALS['ip'] : '') . ' ' . $pid . ' '
79
+        //distinguer les logs prives et publics dans les grep
80
+        . $debugverb
81
+        . (test_espace_prive() ? ':Pri:' : ':Pub:')
82
+        . preg_replace("/\n*$/", "\n", $message);
83
+
84
+
85
+    if (
86
+        @is_readable($logfile)
87
+        and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
88
+    ) {
89
+        $rotate = $GLOBALS['nombre_de_logs'];
90
+        $m .= "[-- rotate --]\n";
91
+    }
92
+
93
+    $f = @fopen($logfile, 'ab');
94
+    if ($f) {
95
+        fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
96
+        fclose($f);
97
+    }
98
+
99
+    if (
100
+        $rotate-- > 0
101
+        and function_exists('spip_unlink')
102
+    ) {
103
+        spip_unlink($logfile . '.' . $rotate);
104
+        while ($rotate--) {
105
+            @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
106
+        }
107
+    }
108
+
109
+    // Dupliquer les erreurs specifiques dans le log general
110
+    if (
111
+        defined('_FILE_LOG')
112
+        and ($logname !== _FILE_LOG)
113
+    ) {
114
+        inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
115
+    }
116
+    $debugverb = '';
117 117
 }
Please login to merge, or discard this patch.