dongyirong3564 2015-04-17 06:52
浏览 42

CodeIgniter 2中的非格式化错误日志

I am currently running a websocket daemon in CodeIgniter 2. The daemon is started using nohup and runs in an eternal loop. The error output is formatted as HTML. However, I'd like to have the errors logged without HTML formatting. Does CodeIgniter have an option to make this possible?

EDIT: I am not only tracking errors. I am also saving a websocket log. The log contains functions that have been run and other useful information. I don't want to hide errors from the log though since they may be useful for tracking some errors. I want to log my custom websocket messages along with errors that may occur.

Daemon start command:

nohup php /usr/share/nginx/html/index.php websocket server > /var/log/websocket/$(date +"%Y%m%d_%H%M%S") 2>&1 &

The errors in the log look like this:

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index: REMOTE_ADDR</p>
<p>Filename: core/Input.php</p>
<p>Line Number: 351</p>
  • 写回答

1条回答 默认 最新

  • dongyuqi3808 2015-04-17 07:39
    关注

    I think you're mixing things up a bit, There's the logs and there's the output produced by the page/script.

    What you're doing is saving the output from the script into the log, all output, including php errors, notices, warnings and codeigniter's errors(unable to conenct to database).

    Codeigniter doesn't have much to do with PHP errors as far as I know, which means this formatting actually comes from the php process itself, you can't prevent this format as far as I know.

    If you want to catch all errors, you could suppress all errors and use php's native error_get_last method, this returns something like this :

    Array
    (
        [type] => 8
        [message] => Undefined variable: a
        [file] => C:\WWW\index.php
        [line] => 2
    )
    

    However, should you have a compile error, this method won't work as it needs the code to compile first.

    Apache should save automatically the errors for you, I'm pretty sure that can be configured in php.ini but I haven't done that in a while.

    In conclusion, I don't think saving the entire output to a log would be the best way to track errors.

    Ref to docs : http://php.net/manual/en/function.error-get-last.php

    评论

报告相同问题?

悬赏问题

  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果