Skip to content

Commit 2acdcb4

Browse files
committed
Add debug support
Close #72
1 parent 2079caa commit 2acdcb4

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Install
5151
'region' => env('DYNAMODB_REGION'),
5252
'local_endpoint' => env('DYNAMODB_LOCAL_ENDPOINT'), // see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html
5353
'local' => env('DYNAMODB_LOCAL'), // true or false? should use dynamodb_local or not?
54+
'debug' => true, // if true, it will use Laravel Log. For advanced options, see http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html
5455
],
5556
...
5657
```
@@ -61,12 +62,8 @@ Install
6162
// config/services.php
6263
...
6364
'dynamodb' => [
64-
'key' => env('AWS_ACCESS_KEY_ID'),
65-
'secret' => env('AWS_SECRET_ACCESS_KEY'),
65+
...
6666
'token' => env('AWS_SESSION_TOKEN'),
67-
'region'=> env('DYNAMODB_REGION'),
68-
'local_endpoint' => env('DYNAMODB_LOCAL_ENDPOINT'),
69-
'local'=> env('DYNAMODB_LOCAL') // true or false? should use dynamodb_local or not?
7067
]
7168
...
7269
```

src/DynamoDbServiceProvider.php

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Aws\DynamoDb\Marshaler;
66
use Illuminate\Support\Facades\App;
7+
use Illuminate\Support\Facades\Log;
78
use Illuminate\Support\ServiceProvider;
89

910
class DynamoDbServiceProvider extends ServiceProvider
@@ -34,6 +35,21 @@ public function register()
3435
$this->bindForApp($marshalerOptions);
3536
}
3637

38+
protected function getDebugOptions()
39+
{
40+
$debug = config('services.dynamodb.debug');
41+
42+
if ($debug === true) {
43+
$logfn = function ($msg) {
44+
Log::info($msg);
45+
};
46+
47+
return ['logfn' => $logfn];
48+
}
49+
50+
return $debug;
51+
}
52+
3753
protected function bindForApp($marshalerOptions = [])
3854
{
3955
$this->app->singleton('BaoPham\DynamoDb\DynamoDbClientInterface', function ($app) use ($marshalerOptions) {
@@ -45,6 +61,7 @@ protected function bindForApp($marshalerOptions = [])
4561
],
4662
'region' => config('services.dynamodb.region'),
4763
'version' => '2012-08-10',
64+
'debug' => $this->getDebugOptions(),
4865
];
4966

5067
$client = new DynamoDbClientService($config, new Marshaler($marshalerOptions), new EmptyAttributeFilter());
@@ -66,7 +83,9 @@ protected function bindForTesting($marshalerOptions = [])
6683
'region' => $region,
6784
'version' => '2012-08-10',
6885
'endpoint' => config('services.dynamodb.local_endpoint'),
86+
'debug' => $this->getDebugOptions(),
6987
];
88+
7089
$client = new DynamoDbClientService($config, new Marshaler($marshalerOptions), new EmptyAttributeFilter());
7190

7291
return $client;

0 commit comments

Comments
 (0)