stevegrunwell / lost-in-translation

Uncover missing translations and localization strings in Laravel applications.
https://stevegrunwell.com/blog/find-missing-laravel-translations/
MIT License
36 stars 8 forks source link

Replace laravel logger with custom logger #4

Closed padarom closed 6 years ago

padarom commented 6 years ago

This PR solves #1.

The Laravel helper logger() returns the Logger singleton as defined by Laravel's LogServiceProvider. When adding a monolog handler to this log, it will make Monolog write to Laravel's default log and the new log. To circumvent this you could pop all handlers from the underlying Monolog instance before adding your own, though I am uncertain what kind of repercussions that would have on the rest of the logging functionality.

As such I went with creating a new logger altogether. Laravel's handler uses a Monolog channel name based on the app environment, but I think hardcoding one for a dedicated log file is fine as well.

Now, since this is wanted behavior and not covered by any of the tests, I recommend to create another one to test for it:

  1. Make log path configurable (?)
  2. Include a virtual file stream package for testing (such as adlawson/vfs)
  3. Overwrite the storage_path helper to aim at a virtual file stream path, so that laravel's logs get posted in it
  4. Configure this package's log path (for testing) to aim at the virtual file stream also
  5. Force a lost-in-translation notice to be logged
  6. Assert the laravel log to be empty and the lost-in-translation log to have content

If you agree with this plan of action I'll gladly give it a shot to implement this myself.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling b6047acbd17766b6c598fcc3265492c98a853bc2 on padarom:develop into 4fb656bad99e313375969117de566c8c859fbbb4 on stevegrunwell:develop.