]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/Utils.php
Logging: move logm() from index.php to application/Utils.php
[github/shaarli/Shaarli.git] / application / Utils.php
index f84f70e44a7f8662f136bd19909b35f338796cbd..a9a10ece572a02e36c151931c719be739894faaa 100644 (file)
@@ -3,6 +3,19 @@
  * Shaarli utilities
  */
 
+/**
+ * Logs a message to a text file
+ *
+ * @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)
+{
+    $line = strval(date('Y/m/d_H:i:s')).' - '.$clientIp.' - '.strval($message).'\n';
+    file_put_contents($logFile, $line, FILE_APPEND);
+}
+
 /**
  *  Returns the small hash of a string, using RFC 4648 base64url format
  *
@@ -72,12 +85,14 @@ function sanitizeLink(&$link)
 
 /**
  * Checks if a string represents a valid date
+
+ * @param string $format The expected DateTime format of the string
+ * @param string $string A string-formatted date
+ *
+ * @return bool whether the string is a valid date
  *
- * @param string        a string-formatted date
- * @param format        the expected DateTime format of the string
- * @return              whether the string is a valid date
- * @see                 http://php.net/manual/en/class.datetime.php
- * @see                 http://php.net/manual/en/datetime.createfromformat.php
+ * @see http://php.net/manual/en/class.datetime.php
+ * @see http://php.net/manual/en/datetime.createfromformat.php
  */
 function checkDateFormat($format, $string)
 {