From 3d4d646cb366bd6de2bab48ce68f7c9edd2c61e9 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Wed, 13 Dec 2017 14:58:11 +0100 Subject: factor out log_line from log function --- it.class | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'it.class') diff --git a/it.class b/it.class index e54137e..0ca1460 100644 --- a/it.class +++ b/it.class @@ -75,7 +75,17 @@ static function &cloneobj(&$object) static function log($name /* ... */) { $args = func_get_args(); - $line = date("Y-m-d H:i:s") . "\t" . implode("\t", array_slice($args, 1)) . "\n"; + $line = date("Y-m-d H:i:s") . "\t" . implode("\t", array_slice($args, 1)); + self::log_line($name, $line); + return $line; +} + +/** + * Append line to a logfile. Date will be added to filename + * @param $name Name of logfile. Will be in log/ of service unless it starts with / + * @param $line Line to log. + */ +static function log_line($name, $line) { $basefn = substr($name, 0, 1) == "/" ? $name : $GLOBALS['ULTRAHOME'] . "/log/$name"; $fullfn = $basefn . "-" . date('Ymd'); @@ -93,10 +103,8 @@ static function log($name /* ... */) @symlink($fullfn, $basefn); } - file_put_contents($fullfn, $line, FILE_APPEND); + file_put_contents($fullfn, $line . "\n", FILE_APPEND); } - - return $line; } -- cgit v1.2.3