/** * prints message and time until last message * * @param string $debugMessage the Message to be logged * @param string $messageLogLevel the Log level of the message, the message will only be logged if the Logger was instantiated with a higher or equal log level * @return void * @author jochum */ public static function printWithDuration($debugMessage, $messageLogLevel = 10000) { $logger = MyLog::singleton(); if ($messageLogLevel >= $logger->logLevel) { $fullMessage = RestUtils::getRealIpAddr() . " - " . date("[d/M/Y:G:i:s]") . " " . $debugMessage . " - took (ms): " . (microtime(true) - $logger->starttime) * 1000 . "\n"; $logger->writeToFile($fullMessage); $logger->starttime = microtime(true); } }
<?php // init logger $mylog = MyLog::singleton(MyLog::getLevel("ALL"), "test.log"); // define the autoloader to load classes from the lib folder function __autoload($className) { if (in_array($className, array("TestConfig", "SmintTestUtils"))) { $filename = dirname(__FILE__) . '/' . $className . '.php'; } else { $filename = dirname(__FILE__) . '/../../lib/' . $className . '.php'; } if (file_exists($filename)) { require $filename; } else { throw new Exception('Class "' . $className . '" could not be autoloaded. File not found: ' . $filename); } }
<?php // I expect $CONFIGFILENAME to be set, otherwise bail out if (isset($CONFIGFILENAME)) { $apiConfig = SmintapiConfig::initConfig($CONFIGFILENAME); $apiConfig = SmintapiConfig::getConfig(); } else { throw new Exception('Please set $CONFIGFILENAME to the config file to be used.'); } // init logger with log level defined in the config file $mylog = MyLog::singleton($apiConfig["logging"]["logLevel"]); // define the autoloader to load classes from the lib folder function __autoload($className) { $filename = dirname(__FILE__) . '/../lib/' . $className . '.php'; if (file_exists($filename)) { require $filename; } else { throw new Exception('Class "' . $className . '" could not be autoloaded. File not found: ' . $filename); } } function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; }