12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace app\models\logger;
- use Yii;
- use app\models\logger\ILogger;
- class LoggerFile extends \yii\db\ActiveRecord implements \app\models\logger\ILogger
- {
- private $cat_name;
-
- private function saveToFile($message)
- {
-
-
- $structure = $_SERVER['DOCUMENT_ROOT'].'/api/logs'.'/'.$this->cat_name;
- if ( !is_dir($structure) and !mkdir($structure, 0777, true)) {
- die('Не удалось создать директории...');
- }
-
- $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);
-
- }
- }
|