0

I am trying to log Parsing errors to a log file. Here's the snippet of code that is used to write to the log file.

if(!array_key_exists(1,$match))
{
       $result = file_put_contents("$mapdir/$log_fname","\n$link",FILE_APPEND | LOCK_EX);
       if($result===False)     echo "Write failed";
       else                    echo "$result bytes written to $mapdir/$log_fname - ";
       echo "Link error: $link\n";
       return False;
}

This returns-

104 bytes written to configs/test/log - Link error: FR3.SYD - 10GigabitEthernet5/1 - TRDU PUBLICP|10GE|PIPE NETWORKS|18398|LLNW-00004034 [EQX: NETPROV-981]

Which means that the contents were successfully written but when I open the file written to by vi command I see the same file. No content has been added.

Notes-

  1. The file I am writing to exists.
  2. Permissions for all have been set to 777 using chmod -R
  3. I am also writing to several config files in the same location with this script successfully using file_put_contents.

Then why do you think I am facing this problem now with the log file?

Akshay Kalghatgi
  • 423
  • 1
  • 4
  • 11
  • 1
    is the Link Error text supposed to be part of the if()? Because you have no `{}` on there, so each branch of the if() only handles one line of code. you put the error message no matter HOW the file_put turns out. – Marc B Aug 13 '15 at 21:28
  • Yeah, well that was only for debugging. I wanted to print the faulty link in any case. – Akshay Kalghatgi Aug 13 '15 at 21:34

0 Answers0