amalgama has asked for the wisdom of the Perl Monks concerning the following question:

I find the logger script, its looks enough accurate. Its simple script that keeps a log of everyone who "hits" the page, keeping the information in one file.
What I want is add one feature - logs emailing feature.
Emaling need be configurable, i.e. logfile will be emailed after "hits" exceed predefined 'hits' quantity, even after 1 hit). Emaling feature can be turned off if not required. Also, can be used txt for logfile, main.txt not .log? Excecuting script should be via image tags, not SSI. Probably ,it possible to return a location header that points to an existing image url, one pix gif. Or print image.
I was wondering if someone can help me. Its looks not difficult task..
#! /usr/local/bin/perl # logger.cgi # version 1.0 # # Create a file called main.log. Must have write permissions # set to main.log $mainlog = "main.log"; $shortdate = `date +"%D %T %Z"`; chop ($shortdate); print "Content-type: text/plain\n\n "; open (MAINLOG, ">>$mainlog"); print MAINLOG "Time: $shortdate\n"; print MAINLOG "User: $ENV{'REMOTE_IDENT'}\n"; print MAINLOG "Host: $ENV{'REMOTE_HOST'}\n"; print MAINLOG "Addr: $ENV{'REMOTE_ADDR'}\n"; print MAINLOG "With: $ENV{'HTTP_USER_AGENT'}\n"; print MAINLOG "Page: $ENV{'DOCUMENT_URI'}\n"; print MAINLOG "From: $ENV{'HTTP_REFERER'}\n\n"; close (MAINLOG); exit;

Edit by castaway - Font tags removed as they muck with themes.

Replies are listed 'Best First'.
Re: logger.cgi script - implementing one feature
by sh1tn (Priest) on May 10, 2005 at 23:30 UTC
    Why not just:
    ... print MAINLOG "$_ $ENV{$_}\n" for keys %ENV; ...


Re: logger.cgi script - implementing one feature
by polettix (Vicar) on May 11, 2005 at 00:03 UTC
    You can use whatever name you want, it's YOUR file :) .log extension aims to communicate that a file contains logs data instead of simple, general text as .txt would suggest, but if you feel more comfortable with .txt (probably because it's better to double-clik in some file exploring facility) go ahead.

    For the emailing part, you can peruse Q&A about it for some hints; I personally use Jenda's Mail::Sender to send emails with attachments and find that it serves excellently to the job.

    Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

    Don't fool yourself.
Re: logger.cgi script - implementing one feature
by ikegami (Patriarch) on May 10, 2005 at 19:46 UTC
    The script you presented doesn't maintain a number of hits. Why don't you start with a hit counter instead of a logger?
      Yes, that's right- I need also add hit counter to this logger. Hits q-ty should be printed in the logfile, for information. As to use modules, I would make it democratic as possible, i.e.does not requiring in any modules, just sendmail.