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 extra reading and going through the core code and trying other approaches, I've come to the conclusion that all I need to do is extend the core functionality of the logging of laravel, so that it logs to a different path with a custom formatter.
I've created my package. Here is my service provider class:
use Illuminate\Log\LogServiceProvider;
class VmlogServiceProvider extends LogServiceProvider {
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
App::bind('log', function()
{
return new Vm\Vmlog\Vmlog;
});
parent::boot();
}
}
?>
Here's the VmLog class
<?php namespace Vm\Vmlog;
use App;
use Illuminate\Support\ServiceProvider;
use Log;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\RotatingFileHandler;
class Vmlog extends \Illuminate\Log\Writer {
protected $path;
protected $formatter;
protected $stream;
protected $rotatingStream;
public function __construct() {
$output = APP_HOST."|%datetime%|%level%|%level_name%|".__METHOD__."|%message%|%context%".PHP_EOL;
$this->path = VM_LOGPATH.APP_VLCODE."/".APP_VLCODE."_".APP_INSTANCE.".log";
$this->formatter = new LineFormatter($output, $dateFormat);
parent::__construct();
}
/**
* Register a file log handler.
*
* @param string $path
* @param string $level
* @return void
*/
public function useFiles($path, $level = 'debug')
{
$level = $this->parseLevel($level);
$this->stream = new StreamHandler($this->path, $level);
$this->stream->setFormatter($this->formatter);
$this->monolog->pushHandler($this->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->rotatingStream = new RotatingFileHandler($this->path, $days, $level);
$this->rotatingStream->setFormatter($this->formatter);
$this->monolog->pushHandler($this->rotatingStream);
}
}
?>
I've commented out the LogServiceProvider in app.php and added in my VmlogServiceProvider in it's place.
Yet, when I try run things, I get the following error.
Call to undefined method Illuminate\Support\Facades\Log::useDailyFiles()
I don't understand why this is happening. I've removed the core LogServiceProvider, I've added my own in it's place and binded it correctly, as per the documentation (I think). What am I doing wrong here?