error logging

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    error logging

    I have set a error_log value in php.ini and its reporting errors to that file correctly .In my site case there will be various events taking place so each will be maintained by others .So i wanted to write tht events errors to separate log files of tht events instead of writing everything to a single log file
    so i tried this script but not working

    Code:
    <?php
    ini_set('error_reporting', E_ALL);
    //error_reporting(E_ALL);
    ini_set('log_errors',TRUE);
    ini_set('html_errors',FALSE);
    ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'errors.txt');
    //error_log('sadfsadasd','1',dirname(__FILE__) . DIRECTORY_SEPARATOR . 'errors.txt');
    ini_set('display_errors',FALSE);
    error_reporting(E_ALL);
    
    $test="ttt
    echo $test;
    echo "<br/>";
    echo dirname(__FILE__). DIRECTORY_SEPARATOR . 'Errors.log';
    ?>

    as u can see i have made a error in the script so tht it generates error but its not writing to new file but still writing errors to old log file in php.ini. Any way to solve this
  • altonator
    New Member
    • Jan 2008
    • 15

    #2
    . .
    Last edited by altonator; Jan 2 '09, 08:44 AM. Reason: I wrote something stupid. Deleting my post.

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      Originally posted by altonator
      Have you tried changing 'error_log' in your php.ini file? Surely that will change the error log file?
      That will work .but there we can specify only one name ..thats the problem....

      Comment

      • pradeepjain
        Contributor
        • Jul 2007
        • 563

        #4
        Originally posted by pradeepjain
        That will work .but there we can specify only one name ..thats the problem....
        what happened guys no answers for the question at all

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi.

          I'm not really sure it is possible to manipulate the log the way you are trying if your intention is to catch syntax errors. Those would most likely have to be logged to the file you specify in the error_log directive.
          I mean, you can't really rely on the broken syntax to set your ini values correctly, can you?

          But, you can use the error_log function to catch logical errors and log them to different files.

          Like say, if you had a database abstraction class and a function that handles member logins, you could do something like:
          [code=php]
          class MyDatabase
          {
          // Not botherhing with the details... just skipping ahead to the good stuff :)
          public function Execute($sql) {
          $result = mysql_query($sq l);
          if(!$result) {
          error_log(time( ) ." - Query failed: ". mysql_error(),
          3, "/path/to/db/error.log");
          }
          else {
          // Do something useful.
          }
          }
          }

          function MemberLogin($us r, $pwd)
          {
          $pwd = sha1($pwd);
          $sql =<<<SQL
          SELECT ID FROM MemberTable
          WHERE User = '$usr' AND Pass = '$pwd'
          SQL;

          $dbLink = MyDatabase::Get Link();
          $result = $dbLink->Execute($sql );

          if($result->RowCount == 0) {
          error_log(time( ) ." - Failed login for '$usr' ",
          3, "/path/to/login/failiure.log");
          return false;
          }
          else if($result->RowCount > 1) {
          error_log(time( ) ." - Multiple users matched for user '$usr'",
          3, "/path/to/impossible/error.log");
          return false;
          }
          else {
          return true;
          }
          }
          [/code]
          Get my meaning?

          Comment

          • pradeepjain
            Contributor
            • Jul 2007
            • 563

            #6
            Originally posted by Atli
            Hi.

            I'm not really sure it is possible to manipulate the log the way you are trying if your intention is to catch syntax errors. Those would most likely have to be logged to the file you specify in the error_log directive.
            I mean, you can't really rely on the broken syntax to set your ini values correctly, can you?

            But, you can use the error_log function to catch logical errors and log them to different files.

            Like say, if you had a database abstraction class and a function that handles member logins, you could do something like:
            [code=php]
            class MyDatabase
            {
            // Not botherhing with the details... just skipping ahead to the good stuff :)
            public function Execute($sql) {
            $result = mysql_query($sq l);
            if(!$result) {
            error_log(time( ) ." - Query failed: ". mysql_error(),
            3, "/path/to/db/error.log");
            }
            else {
            // Do something useful.
            }
            }
            }

            function MemberLogin($us r, $pwd)
            {
            $pwd = sha1($pwd);
            $sql =<<<SQL
            SELECT ID FROM MemberTable
            WHERE User = '$usr' AND Pass = '$pwd'
            SQL;

            $dbLink = MyDatabase::Get Link();
            $result = $dbLink->Execute($sql );

            if($result->RowCount == 0) {
            error_log(time( ) ." - Failed login for '$usr' ",
            3, "/path/to/login/failiure.log");
            return false;
            }
            else if($result->RowCount > 1) {
            error_log(time( ) ." - Multiple users matched for user '$usr'",
            3, "/path/to/impossible/error.log");
            return false;
            }
            else {
            return true;
            }
            }
            [/code]
            Get my meaning?
            yup custom error logging and mailing i have tried..i wanted the way i wanted ..if i cld achieve it it would be good bcos each event there will be different coders so if i can generate a separate log for each of them they cld fix it else me monitoring each of them in a single file :(

            Comment

            Working...