可以使用模拟库创建多个日志文件吗?

I'm looking for a decent, easy to use logging helper class-set/framework.

I discovered Analog and find it to be exactly what I need, despite the fact that it seems to be usable for one logfile at a time only.

Am I wrong ?!

Do you know some similar (in size/functionality) project that allows multiple logs to be written? An Analog-Branch maybe? I had a look at log4php, KLogger and Monolog already.

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.

Yes it does work great. And you can create different log functions for different log types.

EG. This will email errors. But write warnings to a log.

Analog::handler(Analog\Handler\Multi::init(array(
    Analog::ERROR   => Analog\Handler\Buffer::init (
    Analog\Handler\Mail::init (
        'you@example.com',
        'Log messages',
        'noreply@example.com'
    )
)
    ,Analog::WARNING => Analog\Handler\File::init(__DIR__.'/log/warning.log')
    //Analog::DEBUG   => Analog\Handler\File::init('/path/to/logs/debug.log')
)));