Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

35 lines (31 sloc) 0.761 kb
<?php
namespace Analog\Handler;
/**
* Append to the specified log file. Does the same thing as the default
* handling.
*
* Usage:
*
* $log_file = 'log.txt';
* Analog::handler (Analog\Handler\File::init ($log_file));
*
* Analog::log ('Log me');
*
* Note: Uses Analog::$format for the appending format.
*/
class File {
public static function init ($file) {
return function ($info) use ($file) {
$f = fopen ($file, 'a+');
if (! $f) {
throw new \LogicException ('Could not open file for writing');
}
if (! flock ($f, LOCK_EX | LOCK_NB)) {
throw new \RuntimeException ('Could not lock file');
}
fwrite ($f, vsprintf (\Analog\Analog::format (), $info));
flock ($f, LOCK_UN);
fclose ($f);
};
}
}
Jump to Line
Something went wrong with that request. Please try again.