Пример #1
0
 /**
  * Implements writing to log files.
  *
  * @param string $type The type of log you are making.
  * @param string $message The message you want to log.
  * @return boolean success of write.
  */
 public function write($type, $message)
 {
     $trace = debug_backtrace();
     if (isset($trace[2]) && isset($trace[2]['file']) && isset($trace[2]['line'])) {
         parent::write($type, $trace[2]['file'] . ' Line: ' . $trace[2]['line']);
     }
     parent::write($type, $message);
 }
Пример #2
0
 /**
  * test using the path setting to write logs in other places.
  *
  * @return void
  */
 function testPathSetting()
 {
     $path = TMP . 'tests' . DS;
     @unlink($path . 'error.log');
     $log = new FileLog(compact('path'));
     $log->write('warning', 'Test warning');
     $this->assertTrue(file_exists($path . 'error.log'));
     unlink($path . 'error.log');
 }
Пример #3
0
 public function testMaskSetting()
 {
     if (DS === '\\') {
         $this->markTestSkipped('File permission testing does not work on Windows.');
     }
     $path = TMP . 'tests' . DS;
     $this->_deleteLogs($path);
     $log = new FileLog(array('path' => $path, 'mask' => 0666));
     $log->write('warning', 'Test warning one');
     $result = substr(sprintf('%o', fileperms($path . 'error.log')), -4);
     $expected = '0666';
     $this->assertEquals($expected, $result);
     unlink($path . 'error.log');
     $log = new FileLog(array('path' => $path, 'mask' => 0644));
     $log->write('warning', 'Test warning two');
     $result = substr(sprintf('%o', fileperms($path . 'error.log')), -4);
     $expected = '0644';
     $this->assertEquals($expected, $result);
     unlink($path . 'error.log');
     $log = new FileLog(array('path' => $path, 'mask' => 0640));
     $log->write('warning', 'Test warning three');
     $result = substr(sprintf('%o', fileperms($path . 'error.log')), -4);
     $expected = '0640';
     $this->assertEquals($expected, $result);
     unlink($path . 'error.log');
 }
Пример #4
0
 /**
  * test log rotation
  *
  * @return void
  */
 public function testRotation()
 {
     $path = TMP . 'tests' . DS;
     $this->_deleteLogs($path);
     file_put_contents($path . 'error.log', "this text is under 35 bytes\n");
     $log = new FileLog(array('path' => $path, 'size' => 35, 'rotate' => 2));
     $log->write('warning', 'Test warning one');
     $this->assertTrue(file_exists($path . 'error.log'));
     $result = file_get_contents($path . 'error.log');
     $this->assertRegExp('/Warning: Test warning one/', $result);
     $this->assertEquals(0, count(glob($path . 'error.log.*')));
     clearstatcache();
     $log->write('warning', 'Test warning second');
     $files = glob($path . 'error.log.*');
     $this->assertEquals(1, count($files));
     $result = file_get_contents($files[0]);
     $this->assertRegExp('/this text is under 35 bytes/', $result);
     $this->assertRegExp('/Warning: Test warning one/', $result);
     sleep(1);
     clearstatcache();
     $log->write('warning', 'Test warning third');
     $result = file_get_contents($path . 'error.log');
     $this->assertRegExp('/Warning: Test warning third/', $result);
     $files = glob($path . 'error.log.*');
     $this->assertEquals(2, count($files));
     $result = file_get_contents($files[0]);
     $this->assertRegExp('/this text is under 35 bytes/', $result);
     $result = file_get_contents($files[1]);
     $this->assertRegExp('/Warning: Test warning second/', $result);
     sleep(1);
     clearstatcache();
     $log->write('warning', 'Test warning fourth');
     // rotate count reached so file count should not increase
     $files = glob($path . 'error.log.*');
     $this->assertEquals(2, count($files));
     $result = file_get_contents($path . 'error.log');
     $this->assertRegExp('/Warning: Test warning fourth/', $result);
     $result = file_get_contents(array_pop($files));
     $this->assertRegExp('/Warning: Test warning third/', $result);
     $result = file_get_contents(array_pop($files));
     $this->assertRegExp('/Warning: Test warning second/', $result);
     file_put_contents($path . 'debug.log', "this text is just greater than 35 bytes\n");
     $log = new FileLog(array('path' => $path, 'size' => 35, 'rotate' => 0));
     $log->write('debug', 'Test debug');
     $this->assertTrue(file_exists($path . 'debug.log'));
     $result = file_get_contents($path . 'debug.log');
     $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: Test debug/', $result);
     $this->assertFalse(strstr($result, 'greater than 5 bytes'));
     $this->assertEquals(0, count(glob($path . 'debug.log.*')));
 }
Пример #5
0
    echo "Свойство {$p} = {$v} <br>";
}
echo Car::CNAME, "<br>";
abstract class Log
{
    abstract function write($txt);
}
class FileLog extends Log
{
    function write($txt)
    {
        file_put_contents("log.txt", $txt);
    }
}
$fileLog = new FileLog();
$fileLog->write('q');
interface Numerable
{
    function showList();
}
class Books implements Numerable
{
    public $bList = [];
    function __construct($l)
    {
        $this->bList = $l;
    }
    function showList()
    {
        foreach ($this->bList as $v) {
            echo "Книга {$v}<br>";