aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Utils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-24 11:37:29 +0200
committerGitHub <noreply@github.com>2020-10-24 11:37:29 +0200
commit820cae27cfcc94af552818f3f1e5342e00478f6c (patch)
tree20eb1cd95987088a7afc3602e8b712448ef05a93 /application/Utils.php
parent8f6e3d51ccb2df513aadeabafbc5bfffe38b8608 (diff)
parentb38a1b0209f546d4824a0db81a34c4e30fcdebaf (diff)
downloadShaarli-820cae27cfcc94af552818f3f1e5342e00478f6c.tar.gz
Shaarli-820cae27cfcc94af552818f3f1e5342e00478f6c.tar.zst
Shaarli-820cae27cfcc94af552818f3f1e5342e00478f6c.zip
Merge pull request #1601 from ArthurHoaro/feature/psr3
Diffstat (limited to 'application/Utils.php')
-rw-r--r--application/Utils.php24
1 files changed, 13 insertions, 11 deletions
diff --git a/application/Utils.php b/application/Utils.php
index 37be9a13..bc1c9f5d 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -4,21 +4,23 @@
4 */ 4 */
5 5
6/** 6/**
7 * Logs a message to a text file 7 * Format log using provided data.
8 * 8 *
9 * The log format is compatible with fail2ban. 9 * @param string $message the message to log
10 * @param string|null $clientIp the client's remote IPv4/IPv6 address
10 * 11 *
11 * @param string $logFile where to write the logs 12 * @return string Formatted message to log
12 * @param string $clientIp the client's remote IPv4/IPv6 address
13 * @param string $message the message to log
14 */ 13 */
15function logm($logFile, $clientIp, $message) 14function format_log(string $message, string $clientIp = null): string
16{ 15{
17 file_put_contents( 16 $out = $message;
18 $logFile, 17
19 date('Y/m/d H:i:s').' - '.$clientIp.' - '.strval($message).PHP_EOL, 18 if (!empty($clientIp)) {
20 FILE_APPEND 19 // Note: we keep the first dash to avoid breaking fail2ban configs
21 ); 20 $out = '- ' . $clientIp . ' - ' . $out;
21 }
22
23 return $out;
22} 24}
23 25
24/** 26/**