#!/usr/bin/perl

### This script read your logfile and will remove :
###   - images entries (gif,jpg,png)
###   - local domain hosts (here inrp.fr hosts)
### to get a lighter logfile size !
### It works with a CLF or a ECLF logfile format

### Syntax : clean_log > newlog

$file =  "/var/www/logs/logfile";

open(LOGFILE,$file) || die "Error, unable to open $file\n";

while (<LOGFILE>) {
  $loglines++;
  $logfile_sep = " - - ";
  $logfile_sep2 = "\"";
  @line_log = split(/$logfile_sep/);
  @line_log2 = split(/$logfile_sep2/);
  if ($line_log[0] =~ /.inrp.fr/){
    } elsif ($line_log2[1] =~ /.gif/i) {
       } elsif ($line_log2[1] =~ /.jpg/i){
          } elsif ($line_log2[1] =~ /.png/i){
           } elsif ($line_log2[1] =~ /^GET http/ && $line_log2[1] !~ /^GET http:\/\/www\.inrp\.fr/ ){  
               } elsif ($line_log2[1] =~ /^POST http/ && $line_log2[1] !~ /^POST http:\/\/www\.inrp\.fr/ ){
	       	} elsif ($line_log2[1] =~ /^HEAD http/ && $line_log2[1] !~ /^HEAD http:\/\/www\.inrp\.fr/ ) {  
               } else {
          print "$_";
    }
  }
close(LOGFILE); 
