for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Ackintosh\Snidel;
class Log
{
/** @var int */
private $ownerPid;
private $masterPid;
/** @var resource */
private $destination;
/**
* @param int $ownerPid
*/
public function __construct($ownerPid)
$this->ownerPid = $ownerPid;
}
public function setMasterPid($pid)
$this->masterPid = $pid;
* sets the resource for the log.
*
* @param resource $resource
* @return void
public function setDestination($resource)
$this->destination = $resource;
* writes log
* @param string $type
* @param string $message
private function write($type, $message)
if ($this->destination === null) {
return;
$pid = getmypid();
switch (true) {
case $this->ownerPid === $pid:
$role = 'owner';
break;
case $this->masterPid === $pid:
$role = 'master';
default:
$role = 'worker';
fputs(
$this->destination,
sprintf(
'[%s][%s][%d(%s)] %s',
date('Y-m-d H:i:s'),
$type,
$pid,
$role,
$message . PHP_EOL
)
);
public function info($message)
$this->write('info', $message);
public function error($message)
$this->write('error', $message);