Files
majestic/Logger/FileLogger.php

54 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2014-06-02 18:58:49 +04:00
<?php namespace Majestic\Logger;
2011-11-21 19:14:49 +04:00
/**
* @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 = '';
2012-11-19 19:25:38 +04:00
/**
* @var resource
*/
2011-11-21 19:14:49 +04:00
protected $handler = null;
protected function __construct()
{
2014-06-02 18:58:49 +04:00
$this->file_path = \Majestic\Config::get('Logger')->filepath;
2011-11-21 19:14:49 +04:00
}
protected function generateOutString($message)
{
return microtime(true) . " \t: " . $this->pid . trim($message) . "\r\n";
}
2011-11-21 19:14:49 +04:00
protected function concreteLog($message)
{
$out = $this->generateOutString($message);
2011-11-21 19:14:49 +04:00
if (!$this->handler) {
$this->handler = @fopen($this->file_path, "a");
if (!$this->handler) {
2014-06-02 18:58:49 +04:00
throw new \Majestic\Exception\GeneralException('Could not open file ' . $this->file_path);
2011-11-21 19:14:49 +04:00
}
}
fwrite($this->handler, $out);
}
public function __destruct()
{
if ($this->handler) {
if (fclose($this->handler)) {
$this->handler = null;
}
}
}
}