From fc5a7cf003163399236d97cf6e1d6d564823984c Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 29 Jun 2010 13:22:21 +0000 Subject: allow absolut paths in it::log --- it.class | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'it.class') diff --git a/it.class b/it.class index b1ed522..b02892d 100644 --- a/it.class +++ b/it.class @@ -71,28 +71,29 @@ static function &cloneobj(&$object) /** - * Append a line to a logfile in log/. Date will be added to filename and line - * @param $name Name of logfile + * Append a line to a logfile. Date will be added to filename and line + * @param $name Name of logfile. Will be in log/ of service unless it starts with / * @param $line1 Line to append (varargs) */ static function log($name /* ... */) { $args = func_get_args(); $line = date("Y-m-d H:i:s") . "\t" . implode("\t", array_slice($args, 1)) . "\n"; - $fn = $GLOBALS['ULTRAHOME'] . "/log/$name-" . date('Ymd'); + $basefn = substr($name, 0, 1) == "/" ? $name : $GLOBALS['ULTRAHOME'] . "/log/$name"; + $fullfn = $basefn . "-" . date('Ymd'); - $existed = file_exists($fn); + $existed = file_exists($fullfn); - if (isset($GLOBALS['ULTRAHOME']) && ($fh = fopen($fn, "a"))) + if (substr($fullfn, 0, 1) == "/" && ($fh = fopen($fullfn, "a"))) { fputs($fh, $line); fclose($fh); if (!$existed) { - @chgrp($fn, "www"); - @unlink($GLOBALS['ULTRAHOME'] . "/log/$name"); - @symlink($fn, $GLOBALS['ULTRAHOME'] . "/log/$name"); + @chgrp($fullfn, "www"); + @unlink($basefn); + @symlink($fullfn, $basefn); } } } -- cgit v1.2.3