Error handling when writing to the log file

doorknob
13 years ago
Hi,
I recently installed MJ (v1.0RC4). In trying to set up a test environment with FireFox, I eventually got a "content encryption error" I recovered from that but couldn't then reproduce it! In my experience, this type of problem often traces back to an incorrectly handled fopen() command and so I started looking at those. I found one in plugins/Mobile/terawurfl/TeraWurFl.php and, sure enough, it doesn't allow for the possibility of errors occurring (like the user doesn't have write permission on the file, for example). At line 462, I changed
		$_logFP = fopen($logfile, "a+");
fputs($_logFP, $_textToLog."\n");
fclose($_logFP);
 
to
		$_logFP = @fopen($logfile, "a+");
if (is_resource($_logFP)) {
fputs($_logFP, $_textToLog."\n");
fclose($_logFP);
}
 
I don't know if it is related to the problem I experienced but a bit of defensive coding can't do any harm.
Regards
Phil
dryabov
13 years ago
MJ disables writing to log file (look at TeraWurflConfig::$LOG_LEVEL=0; in plugins/mobile/terawurfl.php).
doorknob
13 years ago
I'm not sure what point you are making.
Do you mean that it doesn't matter because it's redundant code?
dryabov
13 years ago
Yes, we use TeraWURFL library "as is". The library can save some notices to log file, but we disable this feature by assigning zero value to LOG_LEVEL parameter.

By continuing to use this site you consent to the use of cookies on your device as described in our cookie policy unless you have disabled them. This site will not function correctly without cookies.

I accept cookies from this site.