{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/8214","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/8214/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/8214/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/8214/events","html_url":"https://github.com/yiisoft/yii2/issues/8214","id":71516161,"number":8214,"title":"Не пишутся логи в консольном приложении, которое запущено как демон","user":{"login":"exru","id":5754949,"avatar_url":"https://avatars.githubusercontent.com/u/5754949?v=3","gravatar_id":"","url":"https://api.github.com/users/exru","html_url":"https://github.com/exru","followers_url":"https://api.github.com/users/exru/followers","following_url":"https://api.github.com/users/exru/following{/other_user}","gists_url":"https://api.github.com/users/exru/gists{/gist_id}","starred_url":"https://api.github.com/users/exru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exru/subscriptions","organizations_url":"https://api.github.com/users/exru/orgs","repos_url":"https://api.github.com/users/exru/repos","events_url":"https://api.github.com/users/exru/events{/privacy}","received_events_url":"https://api.github.com/users/exru/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-28T08:00:38Z","updated_at":"2015-04-28T08:15:13Z","closed_at":null,"body":"Решил написать демона под gearman, столкнулся с проблемой логирования:\r\n```php\r\n\r\n#Конфиг логера\r\n[\r\n                    'class' => 'yii\\log\\FileTarget',\r\n                    'levels' => ['info'],\r\n                    'categories' => ['worker'],\r\n                    'logVars' => [null],\r\n                    'logFile' => '@app/runtime/logs/worker.log',\r\n ],\r\n\r\n#Код в контроллере worker\r\npublic function actionIndex() {\r\n    while(1){\r\n        yii::info('test');\r\n    }\r\n}\r\n#Консоль\r\nphp yii worker &\r\n\r\n#Стал копать\r\npublic static function info($message, $category = 'application')\r\n{\r\n        static::getLogger()->log($message, Logger::LEVEL_INFO, $category);\r\n}\r\n\r\npublic static function getLogger()\r\n{\r\n        if (self::$_logger !== null) {\r\n            return self::$_logger;\r\n        } else {\r\n            return self::$_logger = static::createObject('yii\\log\\Logger');\r\n        }\r\n}\r\n#В классе yii\\log\\Logger есть параметр который по умолчанию равен 0\r\n\r\n public $traceLevel = 0;\r\n /**\r\n     * @var Dispatcher the message dispatcher\r\n*/\r\n\r\n#а так же метод \r\n public function log($message, $level, $category = 'application')\r\n    {\r\n        $time = microtime(true);\r\n        $traces = [];\r\n        if ($this->traceLevel > 0) {\r\n            $count = 0;\r\n            $ts = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);\r\n            array_pop($ts); // remove the last trace since it would be the entry script, not very useful\r\n            foreach ($ts as $trace) {\r\n                if (isset($trace['file'], $trace['line']) && strpos($trace['file'], YII2_PATH) !== 0) {\r\n                    unset($trace['object'], $trace['args']);\r\n                    $traces[] = $trace;\r\n                    if (++$count >= $this->traceLevel) {\r\n                        break;\r\n                    }\r\n                }\r\n            }\r\n        }\r\n        \r\n        $this->messages[] = [$message, $level, $category, $time, $traces];\r\n        if ($this->flushInterval > 0 && count($this->messages) >= $this->flushInterval) {\r\n            $this->flush();\r\n        }\r\n    }\r\n#смутила сточка $this->traceLevel > 0, может как-то обойти можно?\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/96969146","html_url":"https://github.com/yiisoft/yii2/issues/8214#issuecomment-96969146","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/8214","id":96969146,"user":{"login":"lynicidn","id":7407411,"avatar_url":"https://avatars.githubusercontent.com/u/7407411?v=3","gravatar_id":"","url":"https://api.github.com/users/lynicidn","html_url":"https://github.com/lynicidn","followers_url":"https://api.github.com/users/lynicidn/followers","following_url":"https://api.github.com/users/lynicidn/following{/other_user}","gists_url":"https://api.github.com/users/lynicidn/gists{/gist_id}","starred_url":"https://api.github.com/users/lynicidn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lynicidn/subscriptions","organizations_url":"https://api.github.com/users/lynicidn/orgs","repos_url":"https://api.github.com/users/lynicidn/repos","events_url":"https://api.github.com/users/lynicidn/events{/privacy}","received_events_url":"https://api.github.com/users/lynicidn/received_events","type":"User","site_admin":false},"created_at":"2015-04-28T08:15:13Z","updated_at":"2015-04-28T08:15:13Z","body":"от какого юзера? php запускаете? от себя?"}}