logtail / logtail-ruby-rails

Better Stack Rails client
https://betterstack.com/logs
Other
12 stars 6 forks source link

Disable logtail integration by `config.logtail.enabled = false` #10

Open mikz opened 1 year ago

mikz commented 1 year ago

Hi,

When logtail-rails is required, it will automatically be enabled and changes development log output.

That is fine, but it would be great if logtail could actually be disabled in the environment config like everything in Rails.

Right now it has to be disabled by Logtail::Integrations::Rails.enabled = false, which is unexpected, since it provides config.logtail configuration object.

I'm happy to make a PR that takes config.logtail.enabled as the global configuration in the Railtie and disables the integration.

Looks like there are config.integrations.{active_record,action_view,action_controller} that could be configured, but still it would be nice to have one that manages them all.

PetrHeinz commented 1 year ago

Hi @mikz, it makes sense to follow conventional ways of configuration. Thanks for opening up the issue 🙌

I'd be a bit careful with disabling the Logtail Logger though, since it accepts an additional argument (for formatted data). Disabling it would result in ArgumentError (wrong number of arguments (given 2, expected 0..1)) when logging with additional data (e.g.: Rails.logger.error("some error", code: 1337)).

For this reason, I would rather not promote a way to disable the logger via configuration. What do you think?

You could reconfigure the logger with a different io_device (currently STDOUT by default for development) instead.

mikz commented 1 year ago

Interesting. I didn't know. That would be a serious problem. If I'd be designing it, then I'd probably go with a different contract than extending the Logger API. I'd probably use the progname parameter to accept structured data. So you could do: logger.error(metadata) { message }.

Since it is already out there, then I'd at least ensure the development environment is not half configured to use logtail. It can still use logtail logger, but the default configuration should keep the logging the same as without the gem required. Or go all in and configure it to use logtail fully (but then give people an easy way out to go to the normal development log experience).

PetrHeinz commented 1 year ago

Thanks for sharing your thoughts. The easy way out of sending logs to Better Stack would be to set the environment variable LOGTAIL_SKIP_LOGS=1. It will prevent logger from sending logs to us.

gertjanjansen commented 9 months ago

It can still use logtail logger, but the default configuration should keep the logging the same as without the gem required.

+1 for this. I was surprised that installing the gem and not configuring anything immediately impacts the log format in development mode.

furedal commented 3 months ago

Adding this gem removes stack-traces to the terminal output when running in my local environment. The only way I found around this was by adding this gem under a group that excludes the environment that you run locally in the Gemfile like this:

group :production do
  gem 'logtail-rails'
end