Completed
Push — master ( 36ab2f...2db399 )
by cam
01:47
created
ecrire/bootstrap/inc/logging.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -26,85 +26,85 @@  discard block
 block discarded – undo
26 26
  * ```
27 27
  */
28 28
 function spip_logger(?string $name = null): LoggerInterface {
29
-	/* @var array<string,LoggerInterface> */
30
-	static $loggers = [];
31
-	/* @var ?Factory */
32
-	static $loggerFactory = null;
33
-
34
-	$name ??= 'spip';
35
-
36
-	if ($loggerFactory === null) {
37
-		$spipToMonologLevels = [
38
-			Level::Emergency, // _LOG_HS
39
-			Level::Alert,     // _LOG_ALERTE_ROUGE
40
-			Level::Critical,  // _LOG_CRITIQUE
41
-			Level::Error,     // _LOG_ERREUR
42
-			Level::Warning,   // _LOG_AVERTISSEMENT
43
-			Level::Notice,    // _LOG_INFO_IMPORTANTE
44
-			Level::Info,      // _LOG_INFO
45
-			Level::Debug,     // _LOG_DEBUG
46
-		];
47
-
48
-		$config = [
49
-			'siteDir' => _ROOT_RACINE,
50
-			'filesystem' => new Filesystem(),
51
-			// max log par hit
52
-			'max_log' => defined('_MAX_LOG') ? constant('_MAX_LOG') : null,
53
-			// pour indiquer le chemin du fichier qui envoie le log
54
-			'fileline' => defined('_LOG_FILELINE') ? constant('_LOG_FILELINE') : null,
55
-			// échappement des log
56
-			'brut' => defined('_LOG_BRUT') ? constant('_LOG_BRUT') : null,
57
-			// à quel level on commence à logguer
58
-			'max_level' => (function() use ($spipToMonologLevels): Level {
59
-				if (!defined('_LOG_FILTRE_GRAVITE')) {
60
-					return Level::Notice;
61
-				}
62
-				$level = constant('_LOG_FILTRE_GRAVITE');
63
-				if ($level instanceof Level) {
64
-					return $level;
65
-				}
66
-				if (isset($spipToMonologLevels[$level])) {
67
-					return $spipToMonologLevels[$level];
68
-				}
69
-				return match($level) {
70
-					LogLevel::EMERGENCY => Level::Emergency,
71
-					LogLevel::ALERT => Level::Alert,
72
-					LogLevel::CRITICAL => Level::Critical,
73
-					LogLevel::ERROR => Level::Error,
74
-					LogLevel::WARNING => Level::Warning,
75
-					LogLevel::NOTICE => Level::Notice,
76
-					LogLevel::INFO => Level::Info,
77
-					LogLevel::DEBUG => Level::Debug,
78
-					default => Level::Notice,
79
-				};
80
-			})(),
81
-			// rotation: nombre de fichiers
82
-			'max_files' => $GLOBALS['nombre_de_logs'] ??= 4,
83
-			// rotation: taille max d’un fichier
84
-			'max_size' => ($GLOBALS['taille_des_logs'] ??= 100) * 1024,
85
-			// chemin du fichier de log
86
-			'log_path' => (function() {
87
-				$log_dir = defined('_DIR_LOG') ? str_replace(_DIR_RACINE, '', constant('_DIR_LOG')) : 'tmp/log/';
88
-				$log_file = defined('_FILE_LOG') ? constant('_FILE_LOG') : 'spip';
89
-				$log_suffix = defined('_FILE_LOG_SUFFIX') ? constant('_FILE_LOG_SUFFIX') : '.log';
90
-
91
-				$log_file = str_replace('spip', '%s', $log_file);
92
-				return sprintf('%s%s%s', $log_dir, $log_file, $log_suffix);
93
-			})(),
94
-		];
95
-		$env = getenv('APP_ENV') ?? 'prod';
96
-		if ($env === 'dev') {
97
-			$config = [
98
-				...$config,
99
-				'fileline' => true,
100
-				'max_level' => Level::Debug,
101
-			];
102
-		}
103
-		$config = array_filter($config);
104
-
105
-		$loggerFactory = new Factory(new Config(...$config), new LineFormatter());
106
-		unset($args, $env, $spipToMonologLevels);
107
-	}
29
+    /* @var array<string,LoggerInterface> */
30
+    static $loggers = [];
31
+    /* @var ?Factory */
32
+    static $loggerFactory = null;
33
+
34
+    $name ??= 'spip';
35
+
36
+    if ($loggerFactory === null) {
37
+        $spipToMonologLevels = [
38
+            Level::Emergency, // _LOG_HS
39
+            Level::Alert,     // _LOG_ALERTE_ROUGE
40
+            Level::Critical,  // _LOG_CRITIQUE
41
+            Level::Error,     // _LOG_ERREUR
42
+            Level::Warning,   // _LOG_AVERTISSEMENT
43
+            Level::Notice,    // _LOG_INFO_IMPORTANTE
44
+            Level::Info,      // _LOG_INFO
45
+            Level::Debug,     // _LOG_DEBUG
46
+        ];
47
+
48
+        $config = [
49
+            'siteDir' => _ROOT_RACINE,
50
+            'filesystem' => new Filesystem(),
51
+            // max log par hit
52
+            'max_log' => defined('_MAX_LOG') ? constant('_MAX_LOG') : null,
53
+            // pour indiquer le chemin du fichier qui envoie le log
54
+            'fileline' => defined('_LOG_FILELINE') ? constant('_LOG_FILELINE') : null,
55
+            // échappement des log
56
+            'brut' => defined('_LOG_BRUT') ? constant('_LOG_BRUT') : null,
57
+            // à quel level on commence à logguer
58
+            'max_level' => (function() use ($spipToMonologLevels): Level {
59
+                if (!defined('_LOG_FILTRE_GRAVITE')) {
60
+                    return Level::Notice;
61
+                }
62
+                $level = constant('_LOG_FILTRE_GRAVITE');
63
+                if ($level instanceof Level) {
64
+                    return $level;
65
+                }
66
+                if (isset($spipToMonologLevels[$level])) {
67
+                    return $spipToMonologLevels[$level];
68
+                }
69
+                return match($level) {
70
+                    LogLevel::EMERGENCY => Level::Emergency,
71
+                    LogLevel::ALERT => Level::Alert,
72
+                    LogLevel::CRITICAL => Level::Critical,
73
+                    LogLevel::ERROR => Level::Error,
74
+                    LogLevel::WARNING => Level::Warning,
75
+                    LogLevel::NOTICE => Level::Notice,
76
+                    LogLevel::INFO => Level::Info,
77
+                    LogLevel::DEBUG => Level::Debug,
78
+                    default => Level::Notice,
79
+                };
80
+            })(),
81
+            // rotation: nombre de fichiers
82
+            'max_files' => $GLOBALS['nombre_de_logs'] ??= 4,
83
+            // rotation: taille max d’un fichier
84
+            'max_size' => ($GLOBALS['taille_des_logs'] ??= 100) * 1024,
85
+            // chemin du fichier de log
86
+            'log_path' => (function() {
87
+                $log_dir = defined('_DIR_LOG') ? str_replace(_DIR_RACINE, '', constant('_DIR_LOG')) : 'tmp/log/';
88
+                $log_file = defined('_FILE_LOG') ? constant('_FILE_LOG') : 'spip';
89
+                $log_suffix = defined('_FILE_LOG_SUFFIX') ? constant('_FILE_LOG_SUFFIX') : '.log';
90
+
91
+                $log_file = str_replace('spip', '%s', $log_file);
92
+                return sprintf('%s%s%s', $log_dir, $log_file, $log_suffix);
93
+            })(),
94
+        ];
95
+        $env = getenv('APP_ENV') ?? 'prod';
96
+        if ($env === 'dev') {
97
+            $config = [
98
+                ...$config,
99
+                'fileline' => true,
100
+                'max_level' => Level::Debug,
101
+            ];
102
+        }
103
+        $config = array_filter($config);
104
+
105
+        $loggerFactory = new Factory(new Config(...$config), new LineFormatter());
106
+        unset($args, $env, $spipToMonologLevels);
107
+    }
108 108
 
109 109
     return $loggers[$name] ??= $loggerFactory->createFromFilename($name);
110 110
 }
@@ -135,18 +135,18 @@  discard block
 block discarded – undo
135 135
 function spip_log($message, $name = null): void
136 136
 {
137 137
     static $spipToMonologLevels = [
138
-		Level::Emergency, // _LOG_HS
139
-		Level::Alert,     // _LOG_ALERTE_ROUGE
140
-		Level::Critical,  // _LOG_CRITIQUE
141
-		Level::Error,     // _LOG_ERREUR
142
-		Level::Warning,   // _LOG_AVERTISSEMENT
143
-		Level::Notice,    // _LOG_INFO_IMPORTANTE
144
-		Level::Info,      // _LOG_INFO
145
-		Level::Debug,     // _LOG_DEBUG
138
+        Level::Emergency, // _LOG_HS
139
+        Level::Alert,     // _LOG_ALERTE_ROUGE
140
+        Level::Critical,  // _LOG_CRITIQUE
141
+        Level::Error,     // _LOG_ERREUR
142
+        Level::Warning,   // _LOG_AVERTISSEMENT
143
+        Level::Notice,    // _LOG_INFO_IMPORTANTE
144
+        Level::Info,      // _LOG_INFO
145
+        Level::Debug,     // _LOG_DEBUG
146 146
     ];
147 147
 
148
-	# Éviter de trop polluer les logs de dépréciation
149
-	static $deprecated = [];
148
+    # Éviter de trop polluer les logs de dépréciation
149
+    static $deprecated = [];
150 150
 
151 151
     preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs);
152 152
     $logFile = 'spip';
@@ -154,46 +154,46 @@  discard block
 block discarded – undo
154 154
         $logFile = $regs[1];
155 155
     }
156 156
 
157
-	if (!isset($regs[2])) {
158
-		$level = Level::Info;
159
-	} else {
160
-		$level = $spipToMonologLevels[intval($regs[2])] ?? Level::Info;
161
-	}
157
+    if (!isset($regs[2])) {
158
+        $level = Level::Info;
159
+    } else {
160
+        $level = $spipToMonologLevels[intval($regs[2])] ?? Level::Info;
161
+    }
162 162
 
163
-	$logger = spip_logger($logFile);
164
-	$logger->log($level, preg_replace(
163
+    $logger = spip_logger($logFile);
164
+    $logger->log($level, preg_replace(
165 165
         "/\n*$/",
166 166
         "\n",
167 167
         is_string($message) ? $message : print_r($message, true)
168 168
     ));
169 169
 
170 170
 
171
-	if (!array_key_exists($logFile, $deprecated)) {
172
-		$deprecated[$logFile] = true;
173
-		if ($logFile === 'spip') {
174
-			trigger_deprecation(
175
-				'spip',
176
-				'5.0',
177
-				sprintf(
178
-					'spip_log(\'message\') function is deprecated ; use spip_logger().'
179
-					. ' Example: spip_logger()->info(\'message\').',
180
-					$logFile,
181
-					$logFile,
182
-				)
183
-			);
184
-		} else {
185
-			trigger_deprecation(
186
-				'spip',
187
-				'5.0',
188
-				sprintf(
189
-					'spip_log(\'message\', \'%s\') function is deprecated ; use spip_logger().'
190
-					. ' Example: spip_logger(\'%s\')->info(\'message\').',
191
-					$logFile,
192
-					$logFile,
193
-				)
194
-			);
195
-		}
196
-	}
171
+    if (!array_key_exists($logFile, $deprecated)) {
172
+        $deprecated[$logFile] = true;
173
+        if ($logFile === 'spip') {
174
+            trigger_deprecation(
175
+                'spip',
176
+                '5.0',
177
+                sprintf(
178
+                    'spip_log(\'message\') function is deprecated ; use spip_logger().'
179
+                    . ' Example: spip_logger()->info(\'message\').',
180
+                    $logFile,
181
+                    $logFile,
182
+                )
183
+            );
184
+        } else {
185
+            trigger_deprecation(
186
+                'spip',
187
+                '5.0',
188
+                sprintf(
189
+                    'spip_log(\'message\', \'%s\') function is deprecated ; use spip_logger().'
190
+                    . ' Example: spip_logger(\'%s\')->info(\'message\').',
191
+                    $logFile,
192
+                    $logFile,
193
+                )
194
+            );
195
+        }
196
+    }
197 197
 }
198 198
 
199 199
 
@@ -205,6 +205,6 @@  discard block
 block discarded – undo
205 205
  * @param array $opt Tableau d'options
206 206
  **/
207 207
 function journal($phrase, $opt = []) {
208
-	$journal = charger_fonction('journal', 'inc');
209
-	$journal($phrase, $opt);
208
+    $journal = charger_fonction('journal', 'inc');
209
+    $journal($phrase, $opt);
210 210
 }
Please login to merge, or discard this patch.