Write your own regex

Just to show you how you can easily write your own configuration file.

First,

go to http://localhost/PimpMyLog/inc/test.php. You should have this error message :

config1.png

Then touch the requested file :

cd inc
touch test.REMOVE_UPPERCASE.php

Then reload the page.

Copy :

  1. some logs
  2. the regex
  3. the match array
  4. the types array

config2.png

In this article, I have copied these values :

Log

65.55.24.217 - - [07/May/2014:10:17:51 +0200] "GET /italiano/rame/all_news.php?subaction=showfull&id=1335178938&archive=&start_from=&ucat=&page=3 HTTP/1.1" 200 5244 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
66.249.76.165 - - [07/May/2014:10:17:51 +0200] "GET /11402-thickbox_default/cleaning-card-kit-zxp-series8-.jpg HTTP/1.1" 404 1049 "-" "Googlebot-Image/1.0"
66.249.76.165 - - [07/May/2014:10:17:52 +0200] "GET /25337-category_product_table/aculaser-c3900n-a4-col-.jpg HTTP/1.1" 200 26767 "-" "Googlebot-Image/1.0"
208.115.113.91 - - [07/May/2014:10:17:53 +0200] "GET /robots.txt HTTP/1.1" 200 304 "-" "Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)"
5.255.253.66 - - [07/May/2014:10:17:51 +0200] "GET /en/home/arrotolatore-g10-per-piscina-a-piastrine-da-5-a-6-m/ask HTTP/1.1" 303 - "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
66.249.76.165 - - [07/May/2014:10:17:54 +0200] "GET /46221-category_product_table/kiso-acoustic-hb-1.jpg HTTP/1.1" 200 31306 "-" "Googlebot-Image/1.0"
5.255.253.66 - - [07/May/2014:10:17:55 +0200] "GET /index.php?option=com_virtuemart&category_id=257&flypage=flypage.tpl&lang=en&manufacturer_id=1&page=shop.ask&product_id=2596&Itemid=1&vmcchk=1&Itemid=1 HTTP/1.1" 301 - "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
157.55.35.77 - - [07/May/2014:10:17:59 +0200] "GET /robots.txt HTTP/1.1" 200 865 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
208.115.113.91 - - [07/May/2014:10:18:00 +0200] "GET /robots.txt HTTP/1.1" 404 42823 "-" "Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)"
208.115.113.91 - - [07/May/2014:10:18:00 +0200] "GET /robots.txt HTTP/1.1" 200 865 "-" "Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)"
5.255.253.66 - - [07/May/2014:10:17:59 +0200] "GET /en/home/arrotolatore-g10-per-piscina-a-piastrine-da-5-a-6-m/ask?vmcchk=1 HTTP/1.1" 200 61658 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
66.249.76.182 - - [07/May/2014:10:18:00 +0200] "GET /ecommerce/vini-spumanti/334-mionetto.html HTTP/1.1" 200 34127 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
66.249.76.225 - - [07/May/2014:10:18:04 +0200] "GET /index.php/torrini HTTP/1.1" 200 14177 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

RegEx

|^((\S*) )*(\S*) (\S*) (\S*) \[(.*)\] "(\S*) (.*) (\S*)" ([0-9]*) (.*)( "(.*)" "(.*)"( [0-9]*/([0-9]*))*)*$|U

Match

{
    "Date"    : 6,
    "IP"      : 3,
    "CMD"     : 7,
    "URL"     : 8,
    "Code"    : 10,
    "Size"    : 11,
    "Referer" : 13,
    "UA"      : 14,
    "User"    : 5,
    "\u03bcs" : 16
}

Types

{
    "Date"    : "date:H:i:s",
    "IP"      : "ip:geo",
    "URL"     : "txt",
    "Code"    : "badge:http",
    "Size"    : "numeral:0b",
    "Referer" : "link",
    "UA"      : "ua:{os.name} {os.version} | {browser.name} {browser.version}\/100",
    "\u03bcs" : "numeral:0,0"
}

Then when I click on the blue Test button, Pimp My Log parses logs and displays each log with found values. For example, the first log has been parsed and here is the result :

#1 66.249.76.225 - - [07/May/2014:10:18:04 +0200] "GET /index.php/torrini HTTP/1.1" 200 14177 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
   Date   : 10:18:04
   IP     : 66.249.76.225
   CMD    : GET
   URL    : /index.php/torrini
   Code   : 200
   Size   : 14177
   Referer: -
   UA     : Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
   User   : -
   μs    :

Feel free now to modify the regex, the match array and the types array to fit your needs. When you are done, click on the green Copy to clipboard button to copy the result ready to be parsed in your config.user.json file.