You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage Logger
* @since 21-11-2011
* @user: agrebnev
*/
class FileLogger extends Logger
{
protected $file_path = '';
/**
* @var resource
*/
protected $handler = null;
protected function __construct()
{
$this->file_path = Config::get('Logger')->filepath;
}
protected function generateOutString($message)
{
return microtime(true) . " \t: " . $this->pid . trim($message) . "\r\n";
}
protected function concreteLog($message)
{
$out = $this->generateOutString($message);
if (!$this->handler) {
$this->handler = @fopen($this->file_path, "a");
if (!$this->handler) {
throw new GeneralException('Could not open file ' . $this->file_path);
}
}
fwrite($this->handler, $out);
}
public function __destruct()
{
if ($this->handler) {
if (fclose($this->handler)) {
$this->handler = null;
}
}
}
}