laravel 日志分析

Posted 菜的掉渣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel 日志分析相关的知识,希望对你有一定的参考价值。

<?php

$logs = /[d{4}-d{2}-d{2} d{2}:d{2}:d{2}([+-]d{4})?].*/;

$current_log = [
            /^[(d{4}-d{2}-d{2} d{2}:d{2}:d{2}([+-]d{4})?)](?:.*?(w+).|.*?),
            : (.*?)( in .*?:[0-9]+)?$/i
        ];

$log_day=date("Y-m-d");
$file="/mnt/hgfs/CentOS7/cdn.ikuai8.com/storage/logs/laravel-2020-05-20.log";
$content=file_get_contents($file);
preg_match_all($logs, $content, $headings);



//$log_data = preg_split($logs, $content);

$levels_imgs = [
    debug => info-circle,
    info => info-circle,
    notice => info-circle,
    warning => exclamation-triangle,
    error => exclamation-triangle,
    critical => exclamation-triangle,
    alert => exclamation-triangle,
    emergency => exclamation-triangle,
    processed => info-circle,
    failed => exclamation-triangle
];


$log_info=[];
foreach ($headings as $h) {
    for ($i = 0, $j = count($h); $i < $j; $i++) {

        foreach (array_keys($levels_imgs) as $level) {
            if (strpos(strtolower($h[$i]), . . $level) || strpos(strtolower($h[$i]), $level . :)) {

                preg_match($current_log[0] . $level . $current_log[1], $h[$i], $current);
                if (!isset($current[4])) {
                    continue;
                }

                $log_info[] = array(
                    context => $current[3],
                    level => $level,
                    
                    date => $current[1],
                    text => $current[4],
                    in_file => isset($current[5]) ? $current[5] : null,
                );
            }
        }
    }
}
array_reverse($log_info);

$error_num=5;
$current_error_num=0;
foreach($log_info as $log_val){
    if($current_error_num<$error_num){
       echo "-----------------------------------------------------
";
        foreach($log_val as $_key=>$_val){
            echo "[$_key]:	".$_val."
";
        }
        $current_error_num+=1;
    }
}

 

以上是关于laravel 日志分析的主要内容,如果未能解决你的问题,请参考以下文章

laravel 日志分析

分析laravel的核心日志类

需要一种有效的方法来避免使用 Laravel 5 重复代码片段

python分析apache和nginx日志文件输出访客ip列表的代码

Laravel:如何在控制器的几种方法中重用代码片段

argparse 代码片段只打印部分日志