Skip to content

Use Laravel's logger instead of direct Monolog instantiation#55

Merged
alies-dev merged 2 commits into
mainfrom
fix/use-laravel-logger
Mar 5, 2026
Merged

Use Laravel's logger instead of direct Monolog instantiation#55
alies-dev merged 2 commits into
mainfrom
fix/use-laravel-logger

Conversation

@alies-dev
Copy link
Copy Markdown
Member

Summary

  • Inject \Psr\Log\LoggerInterface via GeoIP constructor instead of directly instantiating Monolog\Logger
  • Errors now flow through the application's configured log stack (Sentry, Datadog, etc.)
  • Updated GeoIPServiceProvider and test helper to pass the logger
  • Removed monolog/monolog from composer.json suggest section

Test plan

  • Added test: logger error() called when service lookup fails and log_failures is true
  • Added test: logger error() NOT called when log_failures is false
  • All 13 tests pass

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the GeoIP package's logging mechanism to align with Laravel's standard practices. By injecting the LoggerInterface and utilizing the application's logging stack, it ensures that all GeoIP-related errors are handled consistently with the rest of the application, improving maintainability and centralizing error reporting. This change removes the need for direct Monolog instantiation within the package, simplifying its dependencies and making it more flexible.

Highlights

  • Dependency Injection: The GeoIP class now injects Psr\Log\LoggerInterface via its constructor, promoting better testability and adherence to SOLID principles.
  • Logging Integration: Error logging for GeoIP lookup failures now utilizes Laravel's configured log stack, ensuring consistency with the application's logging setup (e.g., Sentry, Datadog).
  • Service Provider Update: The GeoIPServiceProvider has been updated to pass the application's logger instance when resolving the GeoIP service.
  • Test Coverage: New tests have been added to verify that the logger's error() method is correctly called (or not called) based on the log_failures configuration.
  • Composer Suggestions: The monolog/monolog package has been removed from the suggest section of composer.json as direct Monolog instantiation is no longer used.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • composer.json
    • Removed 'monolog/monolog' from the 'suggest' section.
  • src/GeoIP.php
    • Added Psr\Log\LoggerInterface import.
    • Modified the GeoIP constructor to accept and store a LoggerInterface instance.
    • Replaced direct Monolog\Logger instantiation and usage with the injected LoggerInterface for logging lookup failures.
  • src/GeoIPServiceProvider.php
    • Updated the registerGeoIpService method to pass $app['log'] (the LoggerInterface instance) to the GeoIP constructor when registering the singleton.
  • tests/GeoIPTest.php
    • Added ServiceInterface, Location, and LoggerInterface imports.
    • Implemented a new test it_logs_error_when_service_lookup_fails_and_log_failures_is_enabled to verify logging behavior.
    • Implemented a new test it_does_not_log_when_service_lookup_fails_and_log_failures_is_disabled to verify no logging when disabled.
    • Added helper methods makeGeoIPWithLogger, createFailingService, and setService for testing purposes.
  • tests/TestCase.php
    • Modified the makeGeoIP helper method to pass $this->app['log'] to the GeoIP constructor.
Activity
  • Added test: logger error() called when service lookup fails and log_failures is true.
  • Added test: logger error() NOT called when log_failures is false.
  • All 13 existing tests pass, ensuring no regressions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully refactors the logging mechanism to use Laravel's standard logger through dependency injection, removing the direct dependency on Monolog. This is a great improvement for decoupling and aligns with modern Laravel practices. The changes are well-executed across the service provider and tests. I have one minor suggestion to improve the code documentation.

Comment thread src/GeoIP.php
Comment on lines +64 to +68
public function __construct(
protected array $config,
CacheManager $cache,
private readonly LoggerInterface $logger,
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The constructor's PHPDoc block has not been updated to reflect the addition of the new $logger parameter. Please add @param \Psr\Log\LoggerInterface $logger to the docblock to keep the documentation in sync with the method signature, which improves code clarity and helps static analysis tools.

@alies-dev alies-dev force-pushed the fix/use-laravel-logger branch from 8296bc5 to af85ace Compare March 5, 2026 17:33
@alies-dev alies-dev force-pushed the fix/use-laravel-logger branch from af85ace to 5e9994f Compare March 5, 2026 17:34
@alies-dev alies-dev merged commit 3d4efee into main Mar 5, 2026
@alies-dev alies-dev deleted the fix/use-laravel-logger branch March 5, 2026 17:34
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

Successfully merging this pull request may close these issues.

1 participant