I\'m back with more Laravel problems as I\'m having a problem understanding things.
Again, I\'m attempting to create a package to do my own logging. After doing some ext
I've managed to get it all sorted, so will provide the answer for completeness sake.
We basically mimic the LogServiceProvider class, but instead of calling the Laravel Writer class, we call out own Vmlog class, that simply extends the writer class. That way all functionality of the original logging is kept in place and we simply override the functions we need to. You also need to comment out the registration of the Laravel Log service provider and put your own one in the app.php file.
Here is the ServiceProvider Class.
package('vm/vmlog');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$logger = new Vmlog(new Logger('log'), $this->app['events']);
$this->app->instance('log', $logger);
if (isset($this->app['log.setup']))
{
call_user_func($this->app['log.setup'], $logger);
}
}
}
?>
Here is the Vmlog class that extends the Writer class.
dateFormat = 'Y-m-d\TH:i:s';
$this->output = "|%datetime%|%level%|%level_name%|%message%|%context%".PHP_EOL;
parent::__construct($monolog, $dispatcher);
}
/**
* Register a file log handler.
*
* @param string $path
* @param string $level
* @return void
*/
public function useFiles($path, $level = 'debug')
{
$level = $this->parseLevel($level);
$this->path = VM_LOGPATH.APP_VLCODE."/".APP_VLCODE."_".APP_INSTANCE.".log";
$formatter = new LineFormatter(APP_HOST.$this->output, $this->dateFormat);
$stream = new StreamHandler($this->path, $level);
$stream->setFormatter($formatter);
$this->monolog->pushHandler($stream);
}
/**
* Register a daily file log handler.
*
* @param string $path
* @param int $days
* @param string $level
* @return void
*/
public function useDailyFiles($path, $days = 0, $level = 'debug')
{
$level = $this->parseLevel($level);
$this->path = VM_LOGPATH.APP_VLCODE."/".APP_VLCODE."_".APP_INSTANCE.".log";
$formatter = new LineFormatter(APP_HOST.$this->output, $this->dateFormat);
$stream = new RotatingFileHandler($this->path, $days, $level);
$stream->setFormatter($formatter);
$this->monolog->pushHandler($stream);
}
}
?>
I still need to make it so that the log path is configured in the config files for the package, but this will do for now and for this answer.