Merge pull request #438 from virtualtam/utils/logm/date-format
Logging: improve formatting to enable fail2ban parsing
This commit is contained in:
commit
122d90ef8d
2 changed files with 8 additions and 3 deletions
|
@ -6,14 +6,19 @@
|
||||||
/**
|
/**
|
||||||
* Logs a message to a text file
|
* Logs a message to a text file
|
||||||
*
|
*
|
||||||
|
* The log format is compatible with fail2ban.
|
||||||
|
*
|
||||||
* @param string $logFile where to write the logs
|
* @param string $logFile where to write the logs
|
||||||
* @param string $clientIp the client's remote IPv4/IPv6 address
|
* @param string $clientIp the client's remote IPv4/IPv6 address
|
||||||
* @param string $message the message to log
|
* @param string $message the message to log
|
||||||
*/
|
*/
|
||||||
function logm($logFile, $clientIp, $message)
|
function logm($logFile, $clientIp, $message)
|
||||||
{
|
{
|
||||||
$line = strval(date('Y/m/d_H:i:s')).' - '.$clientIp.' - '.strval($message).'\n';
|
file_put_contents(
|
||||||
file_put_contents($logFile, $line, FILE_APPEND);
|
$logFile,
|
||||||
|
date('Y/m/d H:i:s').' - '.$clientIp.' - '.strval($message).'\n',
|
||||||
|
FILE_APPEND
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase
|
||||||
protected static $testLogFile = 'tests.log';
|
protected static $testLogFile = 'tests.log';
|
||||||
|
|
||||||
// Expected log date format
|
// Expected log date format
|
||||||
protected static $dateFormat = 'Y/m/d_H:i:s';
|
protected static $dateFormat = 'Y/m/d H:i:s';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue