我需要从我的日志文件中删除某些字符串。是的,我知道这听起来很落后,但是为了每个人的理智,相信我:没有办法避免这些无用的通知首先被写入登录。
因此,为了使我的日志可读,必须在写入后删除此类通知。
以下是污染日志文件的示例:
ERROR - 2012-08-06 02:12:01 --> Severity: Notice --> Undefined index: H1 /var/www/vhosts/example.com/httpdocs/application/helpers/mpdf/mpdf.php 14242
ERROR - 2012-08-06 02:12:01 --> Severity: Notice --> Undefined index: H1>>ID>> /var/www/vhosts/example.com/httpdocs/application/helpers/mpdf/mpdf.php 14288
ERROR - 2012-08-06 02:12:01 --> Severity: Notice --> Undefined index: H1 /var/www/vhosts/example.com/httpdocs/application/helpers/mpdf/mpdf.php 14242
ERROR - 2012-08-06 02:12:01 --> Severity: Notice --> Undefined index: H1>>ID>> /var/www/vhosts/example.com/httpdocs/application/helpers/mpdf/mpdf.php 14288
ERROR - 2012-08-06 02:12:01 --> Severity: Notice --> Undefined index: DIV /var/www/vhosts/example.com/httpdocs/application/helpers/mpdf/mpdf.php 14242
我想删除以下行:
- 包含“通知”和
- 包含“未定义”和
- 包含“mpdf.php”
我相信这些方面的事情可能是一个开始:
$dir = '/var/www/vhosts/example.com/httpdocs/application/logs/log-2012-07-07.php';
$content = file_get_contents($dir);
$new = preg_replace($pattern, '', $content) // <===== need help here with $pattern regex
file_put_contents($dir, $new);
你对如何做到这一点有什么建议吗?