Apache Error Conditional logs -tech help please.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • camperjohn64
    Confirmed User
    • Feb 2005
    • 1531

    #1

    Apache Error Conditional logs -tech help please.

    Does anyone have experience with the conditional logs of apache?

    I have 10x to 20,000 404 errors every day (which are actually correct, and are redirected to affiliate programs), and dont want to log those:
    [Sat Apr 17 21:15:25 2010] [error] [client 195.42.102.25] File does not exist: /home/photof/public_html/cats/random.htlm

    Is there a way I can get apache to log all errors except those?
    http://httpd.apache.org/docs/2.2/logs.html

    What environment variable do you think I could use to regex against to acheive this goal?
    www.gimmiegirlproductions.com
  • LoveSandra
    So Fucking Banned
    • Aug 2008
    • 10551

    #2
    bump bump

    Comment

    • Varius
      Confirmed User
      • Jun 2004
      • 6890

      #3
      ErrorLog doesn't support Env conditions, so you'll probably have to use CustomLog and pipe it to a sed command or script to strip out the unwanted lines.
      Skype variuscr - Email varius AT gmail

      Comment

      • camperjohn64
        Confirmed User
        • Feb 2005
        • 1531

        #4
        Oh yes I see it is possible to pipe it. Good idea.

        I will try this:
        ErrorLog "|/usr/bin/php /home/john/test.php"

        and see if I can make a little php program that checks for the 404 condition and doesn't write it if so

        Or do you think it would run faster if it was written as a shell script?

        I don't know I would write a shell script that would "If string not contain "404" and string not contain "not found" then write to /var/log/httpd/error_log"
        www.gimmiegirlproductions.com

        Comment

        • camperjohn64
          Confirmed User
          • Feb 2005
          • 1531

          #5
          So far, I don't think I can do this in PHP. I think this is an excersize for another day. But I did find this:

          http://www.sudleyplace.com/pipederrorlogs.html
          www.gimmiegirlproductions.com

          Comment

          • Varius
            Confirmed User
            • Jun 2004
            • 6890

            #6
            I'm not home right now so didn't test this but just try something simple like:

            ErrorLog "|/bin/grep -v 'File does not exist:' >> /var/log/httpd/error_log"

            Should do the trick.
            Skype variuscr - Email varius AT gmail

            Comment

            • camperjohn64
              Confirmed User
              • Feb 2005
              • 1531

              #7
              Hmmm.. I think this is a syntax issue, but it's close

              Code:
              Starting httpd: grep: does: No such file or directory
              grep: not: No such file or directory
              grep: exist:: No such file or directory
                                                                         [FAILED]
              www.gimmiegirlproductions.com

              Comment

              • camperjohn64
                Confirmed User
                • Feb 2005
                • 1531

                #8
                I really think I need to do it in a shell script and figure out how to do it with stdin, just don't know how to yet.
                www.gimmiegirlproductions.com

                Comment

                • rowan
                  Too lazy to set a custom title
                  • Mar 2002
                  • 17393

                  #9
                  Originally posted by camperjohn64
                  I really think I need to do it in a shell script and figure out how to do it with stdin, just don't know how to yet.
                  $fp = fopen("php://stdin", "r");
                  if (!$fp) die("could not open STDIN");

                  Running a PHP script is pretty clunky, I'd try fixing what Varius gave you. Something like this shoudl work...

                  ErrorLog "|/bin/grep -v \"File does not exist:\" >> /var/log/httpd/error_log"

                  Comment

                  • camperjohn64
                    Confirmed User
                    • Feb 2005
                    • 1531

                    #10
                    Wow that works (with single quotes rather than double quotes):

                    ErrorLog "|/bin/grep -v \'File does not exist:\' >> /var/log/httpd/error_log"

                    Now, how do I test for two error conditions with grep?

                    not found or unable to stat
                    File does not exist:

                    I tried this and let's see if it works:

                    ErrorLog "|/bin/grep -v \'File does not exist:\' |/bin/grep -v \'not found or unable to stat\' >> /var/log/httpd/error_log"
                    www.gimmiegirlproductions.com

                    Comment

                    Working...