Judging from the source code at
you should be able to use several file handlers at the same time. Try something along the lines of this:
Analog::handler(Analog\Handler\Multi::init(array(
Analog::ERROR => Analog\Handler\File::init('/path/to/logs/errors.log'),
Analog::WARNING => Analog\Handler\File::init('/path/to/logs/warnings.log'),
Analog::DEBUG => Analog\Handler\File::init('/path/to/logs/debug.log')
)));
If you cannot make it work with Analog\Handler\Multi
, you can still write your own Composite Logger, adapting the Analog File Handler. To do that, first create an Interface defining how you want to use Loggers in your application:
interface Logger
{
const ERROR = 'error';
const WARNING = 'warning';
const DEBUG = 'debug';
public function log($message, $level);
}
Then create the Adapter for Analog so that it satisfies the Interface:
class AnalogAdapter implements Logger
{
private $adaptee;
public function __construct(Analog $analog)
{
$this->adaptee = $analog;
}
public function log($message, $level)
{
$adaptee = $this->adaptee;
$adaptee::log($message, $adaptee::$level);
}
}
Finally, write the Composite Logger:
class CompositeLogger implements Logger
{
private $loggers = array;
public function registerLogger(Logger $logger)
{
$this->loggers[] = $logger;
}
public function log($message, $level)
{
foreach ($this->loggers as $logger)
{
$logger->log($message, $level);
}
}
}
Then you create your Analog file handlers and register them with the Composite:
$logger = new CompositeLogger;
$logger->registerLogger(
new AnalogAdapter(
Analog\Handler\File::init('/path/to/logs/errors.log')
)
);
// … add more Loggers in the same way
$logger->log('This is a warning', Logger::WARNING);
The warning will then get written to all the registered Loggers.