cwh icon indicating copy to clipboard operation
cwh copied to clipboard

[FEATURE] Use "keyword arguments" for the CloudWatch constructor

Open jdufresne opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe.

I recently wanted to change the $createGroup argument. This is the last argument in a long-ish list of arguments. To solve this, I had to copy and paste all the default arguments when instantiating the handler. It now looks like:

                $handler = new CloudWatch(
                    $client,
                    $log_group,
                    $stream_name,
                    14,            // $retention (default)
                    10000,         // $batchSize (default)
                    [],            // $tags (default)
                    Logger::DEBUG, // $level (default)
                    true,          // $bubble (default)
                    false,         // $createGroup
                );

If the library changes the default value, my instantiation could easily go out of sync.

The values themselves are opaque (what is 14?) requiring me to add multiple inline comments.

Describe the solution you'd like

Allow passing an array of keywords to the constructor. For example:

                $handler = new CloudWatch([
                    'client' => $client,
                    'group' => $log_group,
                    'stream' => $stream_name,
                    'createGroup' => false,
                ]);

This is self documenting and allows omitting default values.

This could be backwards compatible by checking the number and type of arguments and then acting accordingly.

jdufresne avatar Feb 21 '20 16:02 jdufresne

Hi! Good idea! Can you make a PR for this?

maxbanton avatar Nov 17 '20 16:11 maxbanton

OK, but what if I want the retention to be infinite?

In the actual code, there is no way to set $retention to null because it has a default >:/

perfectdeed avatar Feb 22 '21 21:02 perfectdeed