doucan1979 2015-03-05 12:38
浏览 132
已采纳

使用Monolog在symfony中写入日志

I have a problem with my project, I want to use Monolog to write the logs and I can't do. So, I created an service :

services:
 my_logger:
  class: Monolog\Logger
  arguments: [Debug]
  calls:
    - [pushHandler, [@my_log_handler]]

 my_log_handler:
   class: Monolog\Handler\StreamHandler
   arguments: [/home/vagrant/Workspace/symfony/app/logs/test.log, 100]

My controller :

    $em = $this->getDoctrine()->getManager();
    $categories = $em->getRepository('EnsJobeetBundle:Category')->getWithJobs();

If I write :

$logger = $this->get('my_logger');
$logger->info('Test log');

The logs is inserted in test.log

If I write :

$logger = $this->get('my_logger');
$logger->info(print_r($categories,true));

The logs doesn't write. I get the error 500. Please help me. Thx in advance!!! Errors :

2015/03/05 12:58:48 [error] 4698#0: *76 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 532676608 bytes) 


PHP message: PHP   8. print_r() /home/vagrant/Workspace/symfony/src/Ens  /JobeetBundle/Controller/JobController.php:34" while reading response header  from upstream, client: 10.0.2.2, server: symfony.md, request: "GET
/job/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "symfony.dev:8000"
  • 写回答

1条回答 默认 最新

  • duanfu9523 2015-03-05 14:31
    关注

    You're running out of memory trying to process the array. That could be for many reasons, maybe it's just too big, maybe it has recursive aspects, etc.

    A good trick when working with this is to just print the keys. You will see less data, but you will be much less likely to surpass your memory limits. When you get a look at your array, then you can print specific parts of it after you have a look at the keys. Try this:

    $logger = $this->get('my_logger');
    $logger->info(print_r(array_keys($categories),true));
    

    Your other alternative, if you really need to see the whole array, it to increase your memory limits in php.ini. Look for a line like this to change them:

    memory_limit = 128MB
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题