在Codeingiter中显示来自文件的错误消息

时间:2016-07-28 06:17:22

标签: php codeigniter

在我的控制器上,我试图找到以指定单词开头的多行。

@Entity
public class User {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;
    private String userName;
    private String password;

    protected User() {}

    public User(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }

    // standard getters and setters

    @Override
    public String toString() {
        return String.format(
                "User[id=%d, userName='%s', password='%s']",
                id, userName, password);
    }

}

功能display_lines

$file = file(FCPATH . 'application/logs/log-' . date('Y-m-d') . '.php');
$data['debug_messages'] = $this->display_lines($file, 'DEBUG');
$data['informational_messages'] = $this->display_lines($file, 'INFO');

当我查看输出时,它只显示每行的一行,并且不显示多个信息和调试行,如图所示

它应显示更多消息,但由于某种原因,每个消息只显示一行。

  

问题如果有多行以info开头,请调试如何让它为每个信息返回多行并进行调试?

enter image description here

日志文件

function display_lines($file, $str) {
    $lines = $file;
    foreach ($lines as $lineNumber => $line) {
        if (strpos($line, $str) !== false) {
            return $line;
        }
    }
}

查看

INFO - 2016-07-28 21:41:43 --> Config Class Initialized
INFO - 2016-07-28 21:41:43 --> Hooks Class Initialized
DEBUG - 2016-07-28 21:41:43 --> UTF-8 Support Enabled
INFO - 2016-07-28 21:41:43 --> Utf8 Class Initialized
INFO - 2016-07-28 21:41:43 --> URI Class Initialized
INFO - 2016-07-28 21:41:43 --> Router Class Initialized
INFO - 2016-07-28 21:41:44 --> Output Class Initialized
INFO - 2016-07-28 21:41:44 --> Security Class Initialized
DEBUG - 2016-07-28 21:41:44 --> Global POST, GET and COOKIE data sanitized
INFO - 2016-07-28 21:41:44 --> Input Class Initialized
INFO - 2016-07-28 21:41:44 --> Language Class Initialized
INFO - 2016-07-28 21:41:44 --> Loader Class Initialized
INFO - 2016-07-28 21:41:44 --> Helper loaded: form_helper
INFO - 2016-07-28 21:41:44 --> Helper loaded: url_helper
INFO - 2016-07-28 21:41:44 --> Database Driver Class Initialized
DEBUG - 2016-07-28 21:41:44 --> Encryption: Auto-configured driver 'openssl'.

1 个答案:

答案 0 :(得分:1)

我可能误解了这个问题。你想要所有的线,但现在你只返回第一场比赛,为什么不编辑你的功能:

function display_lines($file, $str) {
    $lines = array();
    foreach ($file as $lineNumber => $line) {
        if (strpos($line, $str) !== false) {
            $lines[] = $line;
        }
    }

    return $lines;
}