This repository has been archived by the owner on Jan 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from chekun/feature/support-sae-log
加入对sae log的支持
- Loading branch information
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/vendor/ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php namespace Lavender\Cloud\Sina\Log; | ||
|
||
use Monolog\Logger; | ||
use Illuminate\Log\LogServiceProvider as IlluminateLogServiceProvider; | ||
|
||
class LogServiceProvider extends IlluminateLogServiceProvider { | ||
|
||
public function register() | ||
{ | ||
$logger = new Writer( | ||
new Logger($this->app['env']), $this->app['events'] | ||
); | ||
|
||
$this->app->instance('log', $logger); | ||
|
||
// If the setup Closure has been bound in the container, we will resolve it | ||
// and pass in the logger instance. This allows this to defer all of the | ||
// logger class setup until the last possible second, improving speed. | ||
if (isset($this->app['log.setup'])) | ||
{ | ||
call_user_func($this->app['log.setup'], $logger); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php namespace Lavender\Cloud\Sina\Log; | ||
|
||
use Monolog\Handler\AbstractProcessingHandler; | ||
|
||
class SaeLogHandler extends AbstractProcessingHandler { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function write(array $record) | ||
{ | ||
sae_debug((string) $record['formatted']); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php namespace Lavender\Cloud\Sina\Log; | ||
|
||
use Illuminate\Log\Writer as IlluminateLogWriter; | ||
use Monolog\Formatter\LineFormatter; | ||
use Lavender\Cloud\Sina\Log\SaeLogHandler; | ||
use Config; | ||
|
||
class Writer extends IlluminateLogWriter { | ||
|
||
protected function useSaeLog($level = 'debug') | ||
{ | ||
$level = $this->parseLevel($level); | ||
$this->monolog->pushHandler($handler = new SaeLogHandler($level)); | ||
$handler->setFormatter(new LineFormatter(null, null, true)); | ||
} | ||
|
||
public function useFiles($path, $level = 'debug') | ||
{ | ||
if (Config::get('app.sae')) { | ||
return $this->useSaeLog($level); | ||
} | ||
|
||
parent::userFiles($path, $level); | ||
} | ||
|
||
public function useDailyFiles($path, $days = 0, $level = 'debug') | ||
{ | ||
if (Config::get('app.sae')) { | ||
return $this->useSaeLog($level); | ||
} | ||
|
||
parent::useDailyFiles($path, $days, $level); | ||
} | ||
|
||
} |