aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2016-01-17 20:11:42 +0100
committerVirtualTam <virtualtam@flibidi.net>2016-01-17 20:11:42 +0100
commit122d90ef8d83c6702a8b47f81c32fa3ba7a53c31 (patch)
tree6858a1d21267f504ddad6c40af616127cb4110b4
parent73151d95469b6aee727f3c1f55c07bb91346f9d3 (diff)
parent478ce8afb467d59eb3dce5ec4a9e9446b134aecf (diff)
downloadShaarli-122d90ef8d83c6702a8b47f81c32fa3ba7a53c31.tar.gz
Shaarli-122d90ef8d83c6702a8b47f81c32fa3ba7a53c31.tar.zst
Shaarli-122d90ef8d83c6702a8b47f81c32fa3ba7a53c31.zip
Merge pull request #438 from virtualtam/utils/logm/date-format
Logging: improve formatting to enable fail2ban parsing
-rw-r--r--application/Utils.php9
-rw-r--r--tests/UtilsTest.php2
2 files changed, 8 insertions, 3 deletions
diff --git a/application/Utils.php b/application/Utils.php
index a9a10ece..cb30595f 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -6,14 +6,19 @@
6/** 6/**
7 * Logs a message to a text file 7 * Logs a message to a text file
8 * 8 *
9 * The log format is compatible with fail2ban.
10 *
9 * @param string $logFile where to write the logs 11 * @param string $logFile where to write the logs
10 * @param string $clientIp the client's remote IPv4/IPv6 address 12 * @param string $clientIp the client's remote IPv4/IPv6 address
11 * @param string $message the message to log 13 * @param string $message the message to log
12 */ 14 */
13function logm($logFile, $clientIp, $message) 15function logm($logFile, $clientIp, $message)
14{ 16{
15 $line = strval(date('Y/m/d_H:i:s')).' - '.$clientIp.' - '.strval($message).'\n'; 17 file_put_contents(
16 file_put_contents($logFile, $line, FILE_APPEND); 18 $logFile,
19 date('Y/m/d H:i:s').' - '.$clientIp.' - '.strval($message).'\n',
20 FILE_APPEND
21 );
17} 22}
18 23
19/** 24/**
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 869a9695..f3bb556e 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -22,7 +22,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase
22 protected static $testLogFile = 'tests.log'; 22 protected static $testLogFile = 'tests.log';
23 23
24 // Expected log date format 24 // Expected log date format
25 protected static $dateFormat = 'Y/m/d_H:i:s'; 25 protected static $dateFormat = 'Y/m/d H:i:s';
26 26
27 27
28 /** 28 /**