Skip to content

Commit

Permalink
Merge pull request #24 from ytake/feature-log-exceptions
Browse files Browse the repository at this point in the history
added LogException Annotation
  • Loading branch information
ytake committed Mar 17, 2016
2 parents d0ce91c + a44d5c2 commit a4b5d2f
Show file tree
Hide file tree
Showing 54 changed files with 500 additions and 79 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Yuuki Takezawa
Copyright (c) 2015-2016 Yuuki Takezawa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/AnnotationReaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Annotation;
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/CacheEvict.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Annotation;
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/CachePut.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Annotation;
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Cacheable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Annotation;
Expand Down
37 changes: 37 additions & 0 deletions src/Annotation/LogExceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Annotation;

use Monolog\Logger;
use Doctrine\Common\Annotations\Annotation;

/**
* @Annotation
* @Target("METHOD")
*/
final class LogExceptions extends Annotation implements LoggableAnnotate
{
/** @var int Log level */
public $value = Logger::ERROR;

/** @var string */
public $expect = '\Exception';

/** @var string */
public $name = 'LogExceptions';
}
4 changes: 2 additions & 2 deletions src/Annotation/Loggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Annotation;
Expand All @@ -24,7 +24,7 @@
* @Annotation
* @Target("METHOD")
*/
final class Loggable extends Annotation
final class Loggable extends Annotation implements LoggableAnnotate
{
/** @var int Log level */
public $value = Logger::INFO;
Expand Down
25 changes: 25 additions & 0 deletions src/Annotation/LoggableAnnotate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Annotation;

/**
* Interface LoggableAnnotate
*/
interface LoggableAnnotate
{
}
2 changes: 1 addition & 1 deletion src/Annotation/Transactional.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Annotation;
Expand Down
2 changes: 1 addition & 1 deletion src/AnnotationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
2 changes: 1 addition & 1 deletion src/AnnotationReadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
3 changes: 2 additions & 1 deletion src/ArrayReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
* Copyright (c) 2015 Yuuki Takezawa
*
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
2 changes: 1 addition & 1 deletion src/AspectBind.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
2 changes: 1 addition & 1 deletion src/AspectDriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
2 changes: 1 addition & 1 deletion src/AspectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
3 changes: 2 additions & 1 deletion src/AspectServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
* Copyright (c) 2015 Yuuki Takezawa
*
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ClearAnnotationCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Console;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ClearCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Console;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ModulePublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Console;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/stub/ModuleStub.stub
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class DummyClass extends DummyModuleClass
/** @var array */
protected $classes = [
// example
// \App\Services\AcmeServce::class
// \App\Services\AcmeService::class
];
}
3 changes: 2 additions & 1 deletion src/ConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
* Copyright (c) 2015 Yuuki Takezawa
*
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ClassNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/FileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Exception;
Expand Down
3 changes: 2 additions & 1 deletion src/FileReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
* Copyright (c) 2015 Yuuki Takezawa
*
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect;
Expand Down
2 changes: 1 addition & 1 deletion src/Interceptor/AbstractCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Interceptor;
Expand Down
56 changes: 56 additions & 0 deletions src/Interceptor/AbstractLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Interceptor;

use Ray\Aop\MethodInvocation;
use Ytake\LaravelAspect\Annotation\LoggableAnnotate;

/**
* Class AbstractLogger
*/
class AbstractLogger
{
/** @var string */
protected $format = "%s:%s.%s";

/**
* @param LoggableAnnotate $annotation
* @param MethodInvocation $invocation
*
* @return string[]
*/
protected function logFormatter(LoggableAnnotate $annotation, MethodInvocation $invocation)
{
$context = [];
$arguments = $invocation->getArguments();
foreach ($invocation->getMethod()->getParameters() as $parameter) {
$context['args'][$parameter->name] = $arguments[$parameter->getPosition()];
}

return [
'level' => $annotation->value,
'message' => sprintf(
$this->format,
$annotation->name,
$invocation->getMethod()->class,
$invocation->getMethod()->name
),
'context' => $context,
];
}
}
2 changes: 1 addition & 1 deletion src/Interceptor/CacheEvictInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Interceptor;
Expand Down
2 changes: 1 addition & 1 deletion src/Interceptor/CachePutInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Interceptor;
Expand Down
2 changes: 1 addition & 1 deletion src/Interceptor/CacheableInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2015 Yuuki Takezawa
* Copyright (c) 2015-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelAspect\Interceptor;
Expand Down
Loading

0 comments on commit a4b5d2f

Please sign in to comment.