Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony configuration #10

Closed
nennad opened this issue Apr 20, 2017 · 9 comments
Closed

Symfony configuration #10

nennad opened this issue Apr 20, 2017 · 9 comments

Comments

@nennad
Copy link

nennad commented Apr 20, 2017

Hi there,

We would like to use this package in our Symfony project. Is there a chance that you have an example configuration for Symfony?

Many thanks!

@vurcease
Copy link

I would be interested in the same, as well. We're currently using an .ebextensions configuration to stream the Symfony logs to CloudWatch Logs, but it would be beneficial to stream specific log writes to CloudWatch directly. I started following this project with the intent to come back around to just this utilization.

@nennad
Copy link
Author

nennad commented Apr 21, 2017

Hi @vurcease, we figured it out.

So in your config.yml you need something like this:

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      custom
        custom:
            type: service
            id: cloudwatch_handler

Then in services.yml put this:

    cloudwatch_client:
        class: Aws\CloudWatchLogs\CloudWatchLogsClient
        arguments:
            -
                credentials: { key: "%amazon_accesskey%", secret: "%amazon_secretkey%" }
                region: "%amazon_region%"
                version: "2014-03-28"

    cloudwatch_handler:
        class: Maxbanton\Cwh\Handler\CloudWatch
        arguments:
            - "@cloudwatch_client"
            - "my_group_name"              # groupName
            - "%kernel.environment%" # streamName
            - 30                     # retentionDays
            - 10000                  # logsInBatch
            - { mytag: "tag" }       # tags
            - WARNING                # logLevel

In addition to this package you also need this:

composer require aws/aws-sdk-php

Hope this helps.

@maxbanton
Copy link
Owner

Hi!
Thanks @nennad for your posting!
Actually, last step

In addition to this package you also need this:

composer require aws/aws-sdk-php

is not needed, AWS SDK is already required by library.

@nennad
Copy link
Author

nennad commented Apr 21, 2017

You're right @maxbanton ! Thanks for the nice lib btw 🥇 🍻

@nennad nennad closed this as completed Apr 21, 2017
@maxbanton
Copy link
Owner

@nennad you are welcome!

@mikemix
Copy link

mikemix commented Nov 4, 2017

Would love to see the example upgraded so that an additional file handler would also keep the logs in case there were some connection issues with CloudWatch.

@ryanotella
Copy link

@mikemix I think the standard grouping mechanism would work fine.

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      grouped
        grouped:
            type:    group
            members: [local, cloudwatch]
        local:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
        cloudwatch:
            type: service
            id: cloudwatch_handler

@MichaelBrauner
Copy link

Omg, I thank u so much. This solved this issue for me so fast. Thought that will be hard work. But its was a joke so easy ;)! Thanks Guys.

@24HOURSMEDIA
Copy link

Note that the above configuration only logs the 'errors' or 'critical' logs to CloudWatch.
This is because the 'local' handler apparently removes the 'debug and notice' levels.

if you want to log debug and notice levels too, change. to:

grouped:
            type:    group
            members: [cloudwatch,local]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants