Rey*_*rPM 2 php symfony monolog symfony-2.6
我在这里阅读了一些文档,但仍然不清楚如何编写和使用自定义Monolog处理程序和通道.让我解释一下我想要实现的目标.我有一个自定义函数,我希望将该日志记录到一个名为的文件中custom.log.我通过在config.yml文件中设置这个来启用Doctrine登录到另一个文件:
monolog:
handlers:
#Logs Doctrine to a different channel
doctrine:
level: debug
type: stream
path: "%kernel.logs_dir%/doctrine.log"
channels: [doctrine]
Run Code Online (Sandbox Code Playgroud)
我如何实现同样的目标custom.log?
你可以这样试试,
monolog:
channels: ["testchannel"]
handlers:
test:
# log all messages (since debug is the lowest level)
level: debug
type: stream
path: "%kernel.logs_dir%/testchannel.log"
channels: ["testchannel"]
Run Code Online (Sandbox Code Playgroud)
在控制器中你可以得到记录器并做你的事情;
class DefaultController extends Controller
{
public function indexAction()
{
$logger = $this->get('monolog.logger.testchannel');
$logger->info("This one goes to test channel!!");
return $this->render('AcmeBundle:Default:index.html.twig');
}
}
Run Code Online (Sandbox Code Playgroud)
您还可以通过运行命令来检查注册了哪些monolog处理程序和记录器 php app/console container:debug monolog
| 归档时间: |
|
| 查看次数: |
3744 次 |
| 最近记录: |