diff options
author | VirtualTam <virtualtam@flibidi.net> | 2016-01-16 16:16:56 +0100 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2016-01-16 16:19:44 +0100 |
commit | 478ce8afb467d59eb3dce5ec4a9e9446b134aecf (patch) | |
tree | 6858a1d21267f504ddad6c40af616127cb4110b4 /application | |
parent | 73151d95469b6aee727f3c1f55c07bb91346f9d3 (diff) | |
download | Shaarli-478ce8afb467d59eb3dce5ec4a9e9446b134aecf.tar.gz Shaarli-478ce8afb467d59eb3dce5ec4a9e9446b134aecf.tar.zst Shaarli-478ce8afb467d59eb3dce5ec4a9e9446b134aecf.zip |
Logging: improve formatting to enable fail2ban parsing
Fixes #436
Modifications:
- remove calls to strval() on safe data
- update the date format: 'Y/m/d_H:i:s' => 'Y/m/d H:i:s'
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'application')
-rw-r--r-- | application/Utils.php | 9 |
1 files changed, 7 insertions, 2 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 | */ |
13 | function logm($logFile, $clientIp, $message) | 15 | function 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 | /** |