Results 1 to 5 of 5
  1. #1

    Apache2 Conditional Logging

    I want to do some conditional logging in Apache 2

    1. Remove any reference to robots.txt
    2. Don't log picture GETS at all
    3. Don't log 4 IP's which are admins (hundreds of log entries - just unnecessary)

    Not that it's specially relevant, this apache2 setup hosts a wordpress blog, and I'm trying to think down the logs just a little bit for the sake of readability.

    After a massive amount of Googling over the past couple of days, I've come up with what I THINK are solutions to the above, but I have no idea how to combine them.

    1.

    ##Don't want any mention of robots.txt in logfiles
    SetEnvIf Request_URI "^/robots\.txt$" dontlog
    CustomLog /var/log/apache2/access.log combined env=!dontlog

    2.

    ## Don't want thousands of "pointless" image requests
    SetEnvIf Request_URI \.gif image-request
    SetEnvIf Request_URI \.jpg image-request
    SetEnvIf Request_URI \.png image-request
    CustomLog /path/to/log/access.log env=!image-request

    3.

    ## It seems as if I can't *eliminate* admin IP addy's so les's toss 'em in a "local" logfile
    SetEnvIf Remote_Addr "192\.168\.1\." local
    SetEnvIf Remote_Addr "10\.1\.1\." local
    SetEnvIf Remote_Addr "1\.2\3\.44" local
    CustomLog /path/to/log/local.log common env=!local
    CustomLog /path/to/log/access.log common env=!local

    Could some wise eyes take a look at the above - and - of equal importance, tell me if (or how) I can combine these directives within one conf file? OR should I "Include" these as modular external files (which seems a "cleaner" solution somehow) if so, how?

    Regards & TIA for any suggestsions & guidance.

    CJR

  2. #2
    Join Date
    Mar 2007
    Location
    UK
    Posts
    89
    I haven't tried this, but how about:
    Code:
    ## flag robots.txt requests
    SetEnvIf Request_URI "^/robots\.txt$" robots=1
    
    ## flag image requests
    SetEnvIf Request_URI \.gif image-request=1
    SetEnvIf Request_URI \.jpg image-request=1
    SetEnvIf Request_URI \.png image-request=1
    
    ## flag local requests
    SetEnvIf Remote_Addr "192\.168\.1\." local=1
    SetEnvIf Remote_Addr "10\.1\.1\." local=1
    SetEnvIf Remote_Addr "1\.2\3\.44" local=1
    
    ## set do_not_log if any of the above flags are set
    SetEnvIf robots 1 do_not_log=1
    SetEnvIf image-request 1 do_not_log=1
    SetEnvIf local 1 do_not_log=1
    
    ## only log if do_not_log is not set
    CustomLog /var/log/apache2/access.log combined env=!do_not_log
    Let me know if it works.

    Once you have got this working, it would be worth investigating whether there is a performance benefit to combining them into a smaller number of regular expressions vs the current method of having a SetEnvIf directives per match.


    Cheers,

    Simon

  3. #3

    Apache2 Conditional Logging

    Hey Simon,

    Quote Originally Posted by isurus View Post
    I haven't tried this, but how about:
    (code as above post)

    THANK YOU for the suggestion, it's an interesting approach, and one I would never have dreamed up in a gazillion years. I'm going to give it a shot today, and report back

    Let me know if it works.
    I'll post the results! For sure!

    Once you have got this working, it would be worth investigating whether there is a performance benefit to combining them into a smaller number of regular expressions vs the current method of having a SetEnvIf directives per match.
    Not exactly tangentially, but would the original set of directives work if stated individually? Given that it's a production site, I posted for ideas because I wasn't crazy about staring my own experiments, and inadvertently screwing up apache, thus causing disruption on the site.

    I like the combined approach - yours IOW - because it "feels" cleaner. Performance wise? I don't think it's measurable, because although the site is "busy" that's a relative statement. We're only talking a few hundred hits per day on a dedicated VPS - hosting just one site ATM. (max historically 850/day). It just needs to work is all.

    I'm gonna deploy this and leave the editor open to remove the directives immediately if it starts spitting errors. "Leery?" - yeah - you bet! (I'd have done the same with my own home rolled/Googled recipe, but with considerably less confidence!!)

    Once again, very many thanks for the ideas. Feedback to come after logwatching for a while later pn today. Good Stuff!!!

    Regards & thanks,
    CJR

  4. #4

    Apache2 Conditional Logging

    Simon,

    Let me know if it works.
    1. Placed in conf file, edited to suit local paths yadda yadda
    2. Saved, restarted apache 2, hit the site from "known admin IP"

    No IP appeared in the logfile, so it's reasonable to say that the IP stanza worked.
    No header.png (etc) appeared, so it's equally reasonable to say that the image stanza's worked.

    No offsetting entries in error.log (YAY-----REPEATEDLY)

    It's not UNREASONABLE to say that the whole lot worked! What a lovely clean streamlined approach to this problem you presented. Thank you!


    Cheers,
    Simon
    I hope you'll enjoy a virtual beer on me, and accept warm thanks...both of which, incidentally, are well deserved!

    If you get the chance, could you PM me please? I'd like to run something by you, for your thoughts and comments.

    Warm regards & thanks,
    Colin

    CJR

  5. #5
    Join Date
    Mar 2007
    Location
    UK
    Posts
    89
    cjr|CCN has chosen not to receive private messages or may not be allowed to receive private messages. Therefore you may not send your message to him/her.

Similar Threads

  1. Conditional WordPress Plugin
    By realmind in forum Web Design and Content
    Replies: 0
    Last Post: 10-26-2010, 12:55 PM
  2. jquery conditional problem
    By Satch in forum Programming Discussion
    Replies: 2
    Last Post: 08-26-2008, 09:20 AM
  3. php conditional loop help needed
    By tonomud in forum Programming Discussion
    Replies: 10
    Last Post: 12-28-2005, 10:27 AM
  4. Conditional SSI
    By Cyberpunk in forum Web Hosting Lounge
    Replies: 2
    Last Post: 09-19-2001, 08:14 PM
  5. Raq4 stopped logging (plus other logging questions)
    By Addict in forum Dedicated Server
    Replies: 3
    Last Post: 08-27-2001, 10:29 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •