From 1abe655597da7b3c5b59146c4351eef59f69514c Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 16 Jan 2016 15:48:26 +0100 Subject: Logging: move logm() from index.php to application/Utils.php Relates to #436 Modifications: - inject dependencies to global variables ($_SERVER, $GLOBALS) - apply coding conventions - add test coverage Signed-off-by: VirtualTam --- application/Utils.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'application/Utils.php') diff --git a/application/Utils.php b/application/Utils.php index aeaef9ff..a9a10ece 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -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 * -- cgit v1.2.3