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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置