php错误日志,如何删除重复项/查找唯一错误[重复]

This question already has an answer here:

Is there a way to search the error log for only unique errors. Reason being I have a lot of duplicate errors and don't want to miss the rare ones.

How would I go about writing a custom script which parses the error log, and filters out all of the duplicates excluding the datetime.

</div>

Set ignore-repeated-errors= On in php.ini or add ini_set('ignore-repeated-errors', 1); to your php scripts

This will stop php from logging an error more than once i.e. error messages caused by same line in same script.

To analyze /var/log/apache2/error.log use

sed 's^\[.*\]^^g' /var/log/apache2/error.log | sort | uniq -c

This will

  1. cut the date at the beginning of each line like:

    [28-Aug-2012 11:20:24 UTC] PHP Notice: Undefined index: test in /var/www/... on line ...

  2. sort them according to numerical value

  3. finds and counts unique lines

source: strictcoder.blogspot.de