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

Allow logster to run in other environments #27

Merged
merged 2 commits into from
Jun 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ constraints lambda { |req| req.session["admin"] } do
end
```

By default, logster will only run in development and production environments.

To run logster in other environments, in `config/application.rb`

```
Logster.set_environments([:development, :staging, :production])
```

### Note
If you are seeing error
'No such middleware to insert before: ActionDispatch::DebugExceptions' after installing logster,
Expand Down
5 changes: 5 additions & 0 deletions lib/logster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ def self.add_to_env(env, key, value)
logster_env = Logster::Message.populate_from_env(env)
logster_env[key] = value
end

def self.set_environments(envs)
@config.environments = envs
end
end

Logster.config.current_context = lambda{ |env, &block| block.call }
Logster.config.environments = [:development, :production]

if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
require 'logster/rails/railtie'
Expand Down
2 changes: 1 addition & 1 deletion lib/logster/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Logster
class Configuration
attr_accessor :subdirectory, :current_context
attr_accessor :subdirectory, :current_context, :environments
end
end
4 changes: 2 additions & 2 deletions lib/logster/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Engine < Rails::Engine
end

def self.set_logger(config)
return unless Rails.env.development? || Rails.env.production?
return unless Logster.config.environments.include?(Rails.env.to_sym)

require 'logster/middleware/debug_exceptions'
require 'logster/middleware/reporter'
Expand All @@ -22,7 +22,7 @@ def self.set_logger(config)


def self.initialize!(app)
return unless Rails.env.development? || Rails.env.production?
return unless Logster.config.environments.include?(Rails.env.to_sym)

if Logster::Logger === Rails.logger
app.middleware.insert_before ActionDispatch::ShowExceptions, Logster::Middleware::Reporter
Expand Down