]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/Utils.php
Merge pull request #441 from virtualtam/tests/check-file-permissions
[github/shaarli/Shaarli.git] / application / Utils.php
index aeaef9ff143a84e67f16bb99365fcdbd70680608..551db3e7cf4b74b1a347d7a84002d1472384fa6b 100644 (file)
@@ -3,6 +3,24 @@
  * Shaarli utilities
  */
 
+/**
+ * Logs a message to a text file
+ *
+ * The log format is compatible with fail2ban.
+ *
+ * @param string $logFile  where to write the logs
+ * @param string $clientIp the client's remote IPv4/IPv6 address
+ * @param string $message  the message to log
+ */
+function logm($logFile, $clientIp, $message)
+{
+    file_put_contents(
+        $logFile,
+        date('Y/m/d H:i:s').' - '.$clientIp.' - '.strval($message).PHP_EOL,
+        FILE_APPEND
+    );
+}
+
 /**
  *  Returns the small hash of a string, using RFC 4648 base64url format
  *