12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace app\models\logger;
- use Yii;
- use app\models\logger\ILogger;
- /**
- * This is the model class for table "os_logs".
- *
- * @property int $id
- * @property string $date
- * @property string $section
- * @property string $error_text
- */
- class LoggerFile extends \yii\db\ActiveRecord implements \app\models\logger\ILogger
- {
- private $cat_name;
-
- private function saveToFile($message)
- {
-
- //$file = $_SERVER['DOCUMENT_ROOT'].'/api/'.$this->cat_name .'/'. date('Y-m-d').'.txt';
- $structure = $_SERVER['DOCUMENT_ROOT'].'/api/logs'.'/'.$this->cat_name;
- if ( !is_dir($structure) and !mkdir($structure, 0777, true)) {
- die('Не удалось создать директории...');
- }
- //var_dump('sdfsdf');
- $file = $structure . '/'.date('Y-m-d').'.txt';
- $current = '';
- if ( is_file($file)) {
- $current = file_get_contents($file);
- }
- $current .= $message . "\n";
- $res = file_put_contents($file, $current);
- // сохраняем в файл
- }
-
- public function log($message,$cat) {
- // запись ошибки в логфайл
- $cat = explode('\\',$cat);
- $this->cat_name = array_pop($cat);
-
- $this->saveToFile($message);
-
- }
- }
|