All Projects → tommy-muehle → error-log-parser

tommy-muehle / error-log-parser

Licence: MIT License
Simple PHP library to parse Apache or Nginx error-log file entries for further usage.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to error-log-parser

jota-cert-checker
Check SSL certificate expiration date of a list of sites.
Stars: ✭ 45 (+136.84%)
Mutual labels:  apache
ansible-role-apache-php-fpm
Apache FastCGI support for PHP-FPM
Stars: ✭ 31 (+63.16%)
Mutual labels:  apache
semalt-blocker
⛔ Self-updating PHP library which blocks referral spam from ruining your website statistics
Stars: ✭ 67 (+252.63%)
Mutual labels:  apache
h2go
Apache H2 Go SQL Driver
Stars: ✭ 35 (+84.21%)
Mutual labels:  apache
qpid-proton-j
Mirror of Apache Qpid Proton-J
Stars: ✭ 28 (+47.37%)
Mutual labels:  apache
qpid-jms
Mirror of Apache Qpid JMS
Stars: ✭ 60 (+215.79%)
Mutual labels:  apache
openwhisk-runtime-dotnet
Apache OpenWhisk Runtime .Net supports Apache OpenWhisk functions written in .Net languages
Stars: ✭ 23 (+21.05%)
Mutual labels:  apache
docker base images
Vlad's Base Images for Docker
Stars: ✭ 61 (+221.05%)
Mutual labels:  apache
reverse-proxy-php
在GAE php空间或者在国外apache php空间搭建反向代理
Stars: ✭ 51 (+168.42%)
Mutual labels:  apache
Apache
Docker container running Apache running on Ubuntu, Composer, Lavavel, TDD via Shippable & CircleCI
Stars: ✭ 15 (-21.05%)
Mutual labels:  apache
hadoop-data-ingestion-tool
OLAP and ETL of Big Data
Stars: ✭ 17 (-10.53%)
Mutual labels:  apache
baikal-docker
Provides a ready-to-go Baikal server, incl. docker-compose.yml & Systemd service file
Stars: ✭ 85 (+347.37%)
Mutual labels:  apache
zeppelin
Apache Zeppelin with support for SQL Server
Stars: ✭ 17 (-10.53%)
Mutual labels:  apache
modules
Mesos modules examples and open source modules outside of the Apache Mesos source tree.
Stars: ✭ 26 (+36.84%)
Mutual labels:  apache
apache-baseline
DevSec Apache Baseline - InSpec Profile
Stars: ✭ 37 (+94.74%)
Mutual labels:  apache
qpid-dispatch
Mirror of Apache Qpid Dispatch
Stars: ✭ 62 (+226.32%)
Mutual labels:  apache
ap-airflow
Astronomer Core Docker Images
Stars: ✭ 87 (+357.89%)
Mutual labels:  apache
analog-ce
Analog CE
Stars: ✭ 14 (-26.32%)
Mutual labels:  apache
CarbonDataLearning
Apache CarbonData Learning
Stars: ✭ 52 (+173.68%)
Mutual labels:  apache
Apache-Directory-Listing
A directory listing theme for Apache
Stars: ✭ 138 (+626.32%)
Mutual labels:  apache

error-log-parser

Build Status Minimum PHP Version GitHub license GitHub issues

Simple PHP library to parse Apache or Nginx error-log file entries for further usage.

Install

Using Composer

$ composer require tm/error-log-parser

or manually add this to composer.json

{
    "require": {
        "tm/error-log-parser": "~1.1"
    }
}

Usage

Instantiate the class:

use TM\ErrorLogParser\Parser; 
$parser = new Parser(Parser::TYPE_APACHE) // or TYPE_NGINX;

And then parse the lines:

function getLines($file)
 {
    $f = fopen($file, 'r');
    if (!$f) throw new Exception();
    while ($line = fgets($f)) {
        yield $line;
    }
    fclose($f);
}

foreach (getLines('/var/log/apache2/error.log') as $line) {
    $entry = $parser->parse($line);
}

Where $entry hold all parsed data. For Apache:

stdClass Object (
    [date] => "Tue Dec 29 08:14:45 2015"
    [type] => "warn"
    [client] => "193.158.15.243"
    [message] => "mod_fcgid: stderr: PHP Warning:  Division by zero in /var/www/kd/app.de/src/Calc.php on line 346, referer: https://www.app.de"
)

And for Nginx:

stdClass Object (
    [date] => "2011/06/10 13:30:10"
    [type] => "error"
    [message] => "*1 directory index of "/var/www/ssl/" is forbidden"
    [client] => "86.186.86.232"
    [server] => "hotelpublisher.com"
    [request] => "GET / HTTP/1.1"
    [host] => "hotelpublisher.com"
)

Otherwise you can use the FormlessParser for formless log files:

stdClass Object (
    [type] => "info"
    [message] => "23263#0: *1 directory index of "/var/www/ssl/" is forbidden, client: 86.186.86.232, server: hotelpublisher.com, request: "GET / HTTP/1.1", host: "hotelpublisher.com""
)

Contributing

Please refer to CONTRIBUTING.md for information on how to contribute.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].