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

Decoupling of RollbarLogger in init #190

Merged
merged 6 commits into from
Jun 11, 2017
Merged

Decoupling of RollbarLogger in init #190

merged 6 commits into from
Jun 11, 2017

Conversation

jasny
Copy link
Contributor

@jasny jasny commented May 30, 2017

Allow passing a RollbarLogger in init instead of creating one from config.
This allows to use a custom RollbarLogger by extending the class. You can also get the logger from a container for container based frameworks.

Allow passing a `RollbarLogger` in init instead of creating one from config.
This allows to use a custom `RollbarLogger` by extending the class. You can also get the logger from a container for container based frameworks.
@ArturMoczulski
Copy link
Contributor

This is great. Do you think you can add a test case for this?

@ftrrtf
Copy link

ftrrtf commented May 30, 2017

Cool idea, but naming can be better. $config is not just config anymore.

@jasny
Copy link
Contributor Author

jasny commented May 30, 2017

@ArturMoczulski Yest, but not easily. These are static methods altering the global state. We need to reset the state in RollbarTest::tearDown().
@ftrrtf We could name it $logger. Any other ideas?

I also noticed that it's going to break if you pass a RollbarLogger when self::$logger is already set. What do you think should happen? We could simply replace it, but that might lead to unexpected behavior. Alternatively an exception can be through

throw new BadMethodCallException("It's not possible to replace the global rollbar logger. You may any specify a new configuration.");

Please let me know and I'll make the modifications.

@ArturMoczulski
Copy link
Contributor

Yes, but we will need it for test coverage. The extent of the test can be as minimal as just checking if subsequent call to Rollbar::logger() returns the same instance as the one passed in Rollbar::init().

Passing a new instance of RollbarLogger when one already exists in self::$logger should replace the old one. I can't think of any reasons why that would be bad.

@rokob
Copy link
Contributor

rokob commented May 30, 2017

L30 needs to change as you have mentioned, it should be the same as L21, which makes me think it should delegate to a shared method like setLogger. The config variable shouldn't be named logger either because it is a config or a logger, so maybe just configOrLogger which is at least explicit.

Renamed `$config` to `$configOrLogger` in `Rollbar::init()`
Added tests
Added DI section in README
@jasny
Copy link
Contributor Author

jasny commented Jun 6, 2017

@rokob Replacing the logger when passing a new configuration in Rollbar::init() would break backwards compatibility.

@coryvirok coryvirok added the Type: Enhancement Changes that add to, improve upon, enhance, or extend the existing component. label Jun 7, 2017
{
Rollbar::init(self::$simpleConfig);

$this->assertInstanceOf('Rollbar\RollbarLogger', Rollbar::logger());
Copy link
Contributor

@ArturMoczulski ArturMoczulski Jun 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this comment above the method signature to suppress PHPMD issues in Codacy:

    /**
     * Usage of static method Rollbar::logger() is intended here.
     *
     * @SuppressWarnings(PHPMD.StaticAccess)
     */

{
$logger = $this->getMockBuilder('Rollbar\RollbarLogger')->disableOriginalConstructor()->getMock();

Rollbar::init($logger);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this comment above method signature to suppress PHPMD issues in Codacy:

    /**
     * Usage of static method Rollbar::logger() is intended here.
     *
     * @SuppressWarnings(PHPMD.StaticAccess)
     */

Static access is intended in these tests so suppress the warning for PHPMD.
@ArturMoczulski ArturMoczulski merged commit 58b817e into rollbar:master Jun 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Changes that add to, improve upon, enhance, or extend the existing component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants