reidmorrison / rails_semantic_logger Goto Github PK
View Code? Open in Web Editor NEWRails Semantic Logger replaces the Rails default logger with Semantic Logger
Home Page: https://logger.rocketjob.io/rails
License: Apache License 2.0
Rails Semantic Logger replaces the Rails default logger with Semantic Logger
Home Page: https://logger.rocketjob.io/rails
License: Apache License 2.0
I have a file /app/config/initializers/logger.rb
, which has a following content
Rails.application.config.rails_semantic_logger.quiet_assets = true
Rails.application.config.rails_semantic_logger.add_file_appender = false
But because semantic logger is initialized before that file, my settings are not applied.
How to fix it?
It seems rails_semantic_logger won't work on Rails 5.0 beta, I am getting the following:
[79942] ! Unable to load application: NoMethodError: undefined method `include' for #<ActionCable::Server::Configuration:0x007fde92e726d8>
/usr/local/lib/ruby/gems/2.3.0/gems/rails_semantic_logger-3.0.0/lib/rails_semantic_logger/railtie.rb:71:in `block (3 levels) in <class:Railtie>': undefined method `include' for #<ActionCable::Server::Configuration:0x007fde92e726d8> (NoMethodError)
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /usr/local/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.beta2/lib/action_cable/server/base.rb:72:in `<module:Server>'
from /usr/local/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.beta2/lib/action_cable/server/base.rb:4:in `<module:ActionCable>'
from /usr/local/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.beta2/lib/action_cable/server/base.rb:3:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/dependencies.rb:302:in `require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/dependencies.rb:302:in `block in require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/dependencies.rb:268:in `load_dependency'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta2/lib/active_support/dependencies.rb:302:in `require'
from /usr/local/lib/ruby/gems/2.3.0/gems/actioncable-5.0.0.beta2/lib/action_cable.rb:43:in `server'
from cable/config.ru:4:in `block in <main>'
from /usr/local/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in `initialize'
from cable/config.ru:in `new'
from cable/config.ru:in `<main>'
from /usr/local/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in `eval'
from /usr/local/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in `new_from_string'
from /usr/local/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:40:in `parse_file'
from /usr/local/lib/ruby/gems/2.3.0/gems/puma-2.16.0/lib/puma/configuration.rb:155:in `load_rackup'
from /usr/local/lib/ruby/gems/2.3.0/gems/puma-2.16.0/lib/puma/configuration.rb:99:in `app'
from /usr/local/lib/ruby/gems/2.3.0/gems/puma-2.16.0/lib/puma/runner.rb:114:in `load_and_bind'
from /usr/local/lib/ruby/gems/2.3.0/gems/puma-2.16.0/lib/puma/cluster.rb:318:in `run'
from /usr/local/lib/ruby/gems/2.3.0/gems/puma-2.16.0/lib/puma/cli.rb:214:in `run'
from /usr/local/lib/ruby/gems/2.3.0/gems/puma-2.16.0/bin/puma:10:in `<top (required)>'
from /usr/local/bin/puma:23:in `load'
from /usr/local/bin/puma:23:in `<main>'
Any suggestions?
I am getting this exception when trying to send an email:
UserMailer.password_reset(user).deliver_later
NoMethodError: undefined method `current_tags' for nil:NilClass
from /usr/local/lib/ruby/gems/2.3.0/gems/activejob-5.0.0.beta3/lib/active_job/logging.rb:51:in `logger_tagged_by_active_job?'
This didn't happen with beta1 and doesn't happen if I remove rails_semantic_logger.
Any ideas?
I do not see full support for Rails filter parameters. I have looked through the code and grep'd for what I could, but is this a feature that is not supported or did I miss it?
Thanks,
-M
I received a deprecation notice for using semantic_logger.appenders << ..
so I used SemanticLogger.add_appender as describe in the message..
when config.log_level = :trace
, the gem will use this information, which is great, but with
SemanticLogger.add_appender("some_file", :debug)
, the log level isn't honored;
SemanticLogger["some_file"].level
= :trace.
I tried this with Rails 5 support and getting this error:
NameError: uninitialized constant ActionController::LogSubscriber
I'm using semantic logger and trying to get my app to only log to stdout, not the default "log/production.log" file. It seems that creating a config.logger wasn't enough, SemanticLogger apparently looks at config.paths['log']
and creates a new logger from the first path there. If I set the value to nil
I get errors so best I can do is /dev/null
. Although that means all log messages are still going through the formatter proc so it's not exactly a no-op.
Ruby 2.3.3, Rails 5.1.1, Rails Semantic Logger: 4.1.2, Semantic Logger: 4.1.1, No configuration
The default install of rails_semantic_logger is triggering errors in log files. I reverted to 4.1.1 to see if the error was present and it is not. I believe this problem is rails_semantic_logger since reverting to 4.1.1 for rails_semantic_logger without changing the semantic_logger version corrects the error, but I have not had an opportunity to investigate thoroughly. Logs included for actual and expected
ACTUAL (rails_semantic_logger 4.1.2)
2017-06-15 20:44:35.748368 E [1:SemanticLogger::Processor] SemanticLogger -- Appender thread: Failed to log to appender: #<SemanticLogger::Appender::File:0x00563291684588 @log=#<IO:<STDOUT>>, @formatter=:default, @application=nil, @host=nil, @filter=nil, @name="SemanticLogger::Appender::File", @level_index=nil, @level=nil> -- Exception: NoMethodError: undefined
method `call' for :default:Symbol
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/appender/file.rb:101:in `log'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:225:in `block in call_appenders'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:223:in `each'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:223:in `call_appenders'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:150:in `process_requests'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:7:in `block in start'
2017-06-15 20:44:35.748084 D [1:puma 005] Rack -- Started -- {:method=>"GET", :path=>"/ping", :ip=>"172.22.0.1"}
2017-06-15 20:44:35.877003 E [1:SemanticLogger::Processor] SemanticLogger -- Appender thread: Failed to log to appender: #<SemanticLogger::Appender::File:0x00563291684588 @log=#<IO:<STDOUT>>, @formatter=:default, @application=nil, @host=nil, @filter=nil, @name="SemanticLogger::Appender::File", @level_index=nil, @level=nil> -- Exception: NoMethodError: undefined
method `call' for :default:Symbol
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/appender/file.rb:101:in `log'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:225:in `block in call_appenders'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:223:in `each'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:223:in `call_appenders'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:150:in `process_requests'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:7:in `block in start'
2017-06-15 20:44:35.876823 D [1:puma 005] (0.768ms) ActiveRecord::Base -- {:sql=>"SELECT \"schema_migrations\".\"version\" FROM \"schema_migrations\" ORDER BY \"schema_migrations\".\"version\" ASC"}
2017-06-15 20:44:36.030428 E [1:SemanticLogger::Processor] SemanticLogger -- Appender thread: Failed to log to appender: #<SemanticLogger::Appender::File:0x00563291684588 @log=#<IO:<STDOUT>>, @formatter=:default, @application=nil, @host=nil, @filter=nil, @name="SemanticLogger::Appender::File", @level_index=nil, @level=nil> -- Exception: NoMethodError: undefined
method `call' for :default:Symbol
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/appender/file.rb:101:in `log'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:225:in `block in call_appenders'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:223:in `each'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:223:in `call_appenders'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:150:in `process_requests'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:7:in `block in start'
2017-06-15 20:44:36.030264 D [1:puma 005] V1::PingsController -- Processing #show
2017-06-15 20:44:36.095865 E [1:SemanticLogger::Processor] SemanticLogger -- Appender thread: Failed to log to appender: #<SemanticLogger::Appender::File:0x00563291684588 @log=#<IO:<STDOUT>>, @formatter=:default, @application=nil, @host=nil, @filter=nil, @name="SemanticLogger::Appender::File", @level_index=nil, @level=nil> -- Exception: NoMethodError: undefined
method `call' for :default:Symbol
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/appender/file.rb:101:in `log'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:225:in `block in call_appenders'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:223:in `each'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:223:in `call_appenders'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:150:in `process_requests'
/usr/local/bundle/gems/semantic_logger-4.1.1/lib/semantic_logger/processor.rb:7:in `block in start'
2017-06-15 20:44:36.095255 I [1:puma 005] (64.5ms) V1::PingsController -- Completed #show -- {:controller=>"V1::PingsController", :action=>"show", :format=>"JSON", :method=>"GET", :path=>"/ping", :status=>204, :view_runtime=>0.0, :db_runtime=>0.0, :status_message=>"No Content"}
Expected (rails_semantic_logger 4.1.1)
2017-06-15 20:37:47.265632 D [1:puma 005] Rack -- Started -- {:method=>"GET", :path=>"/ping", :ip=>"172.22.0.1"}
2017-06-15 20:37:47.404282 D [1:puma 005] (0.824ms) ActiveRecord::Base -- {:sql=>"SELECT \"schema_migrations\".\"version\" FROM \"schema_migrations\" ORDER BY \"schema_migrations\".\"version\" ASC"}
2017-06-15 20:37:47.582106 D [1:puma 005] V1::PingsController -- Processing #show
2017-06-15 20:37:47.645568 I [1:puma 005] (63.3ms) V1::PingsController -- Completed #show -- {:controller=>"V1::PingsController", :action=>"show", :format=>"JSON", :method=>"GET", :path=>"/ping", :status=>204, :view_runtime=>0.0, :db_runtime=>0.0, :status_message=>"No Content"}
Provide at least:
2017-05-10 09:18:01.893499 ERROR [28123:13799700 log_subscriber.rb:85] Rails -- Could not log "process_action.action_controller" event. NoMethodError: undefined method `to_unsafe_h' for {"controller"=>"tasks", "action"=>"report_statsd_counts"}:Hash ["/var/local/kenhub/kenhub.d/913/vendor/bundle/ruby/2.3.0/gems/rails_semantic_logger-4.1.0/lib/rails_semantic_logger/extensions/action_controller/log_subscriber.rb:14:in `block in process_action'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/semantic_logger-4.1.0/lib/semantic_logger/log.rb:131:in `assign_positional'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/semantic_logger-4.1.0/lib/semantic_logger/base.rb:307:in `log_internal'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/semantic_logger-4.1.0/lib/semantic_logger/base.rb:84:in `info'", "/var/local/kenhub/kenhub.d/913/vendor/bundle/ruby/2.3.0/gems/rails_semantic_logger-4.1.0/lib/rails_semantic_logger/extensions/action_controller/log_subscriber.rb:12:in `process_action'",
...
2017-05-10 09:18:10.299339 ERROR [28121:13799700 log_subscriber.rb:85] Rails -- Could not log "write_fragment.action_controller" event. NoMethodError: undefined method `enable_fragment_cache_logging' for ActionController::Base:Class ["/var/local/kenhub/kenhub.d/913/vendor/bundle/ruby/2.3.0/gems/rails_semantic_logger-4.1.0/lib/rails_semantic_logger/extensions/action_controller/log_subscriber.rb:72:in `write_fragment'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/subscriber.rb:100:in `finish'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/log_subscriber.rb:83:in `finish'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/fanout.rb:102:in `finish'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/fanout.rb:46:in `block in finish'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/fanout.rb:46:in `each'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/fanout.rb:46:in `finish'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/instrumenter.rb:36:in `finish'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/instrumenter.rb:25:in `instrument'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications.rb:164:in `instrument'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.8/lib/action_controller/caching/fragments.rb:99:in `instrument_fragment_cache'", "/var/local/kenhub/kenhub/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.8/lib/action_controller/caching/fragments.rb:31:in `write_fragment'", "/varโฆ
configs:
# config/environments/production.rb
config.log_level = :info
config.log_errors_to_sentry = true
config.paths['log'] = "/var/log/kenhub/#{Rails.env}.log"
config.colorize_logging = false
config.rails_semantic_logger.quiet_assets = true
# config/initializers/logging.rb
include SemanticLogger::Loggable
# based on https://github.com/rocketjob/semantic_logger/blob/0f047df6019a14dcd2c05cac9cbfbf38f0a24461/lib/semantic_logger/formatters/default.rb
# only small modification of log level to show DEBUG/WARN instead of D/W/...
module SemanticLogger
module Formatters
class Kenhub < Base
# Default text log format
# Generates logs of the form:
# 2011-07-19 14:36:15.660235 D [1149:ScriptThreadProcess] Rails -- Hello World
def call(log, logger)
# Date & time
message = time_format.nil? ? '' : "#{format_time(log.time)} "
# Log level and process info
message << "#{log.level.upcase} [#{log.process_info}]"
# Tags
message << ' ' << log.tags.collect { |tag| "[#{tag}]" }.join(' ') if log.tags && (log.tags.size > 0)
# Named Tags
if (named_tags = log.named_tags) && !named_tags.empty?
list = []
named_tags.each_pair { |name, value| list << "[#{name}: #{value}]" }
message << ' ' << list.join(' ')
end
# Duration
message << " (#{log.duration_human})" if log.duration
# Class / app name
message << " #{log.name}"
# Log message
message << " -- #{log.message}" if log.message
# Payload
if payload = log.payload_to_s
message << ' -- ' << payload
end
# Exceptions
if log.exception
message << " -- Exception: #{log.exception.class}: #{log.exception.message}\n"
message << log.backtrace_to_s
end
message
end
end
end
end
if Kenhub.config.log_errors_to_sentry
SemanticLogger.add_appender(:appender => :sentry, :level => :error)
end
unless Kenhub.config.colorize_logging
appender = SemanticLogger.appenders.find{ |a| a.is_a?(SemanticLogger::Appender::File) }
appender.formatter = SemanticLogger::Formatters::Kenhub.new
end
No matter how much configuration I throw at rails_semantic_logger
I can't seem to make it behave as expected, which leads me to believe that my expectations are wrong.
Personal context: old with ruby, new with rails, new with semantic_logger, completely befuddled by autoload and how the Rails config system determines order of processing.
Create and fire up a new rails app, without initially mucking with anything other than the Gemfile
$> rails new s_l_app
$> # edit Gemfile to add `gem "rails_semantic_logger"`
$> bundle install
$> bundle list rails_semantic_logger #=>.../ruby/2.4.0/gems/rails_semantic_logger-4.1.3
$> bundle exec rails s
$> curl 'http://localhost:3000/'
$> # stop it and explicitly add `config.rails_semantic_logger.started = false` to `application.rb`
$> mv log/development.log log/dev1.log
$> bundle exec rails s
$> curl 'http://localhost:3000/'
application.rb
will be honored, e.g. config.rails_semantic_logger.started = false
$> diff log/dev1.log log/development.log
# the same except for timestamps, pids
$> cat log/development.log
2017-09-14 06:38:57.032152 D [81773:puma 002] Rack -- Started -- {:method=>"GET", :path=>"/", :ip=>"127.0.0.1"}
2017-09-14 06:38:57.041290 D [81773:puma 002] Rails::WelcomeController -- Processing #index
2017-09-14 06:38:57.204222 D [81773:puma 002] ActionView::Base -- Rendering /Users/dueberb/.gem/ruby/2.4.0/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb
2017-09-14 06:38:57.207505 D [81773:puma 002] ActionView::Base -- Rendered /Users/dueberb/.gem/ruby/2.4.0/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb (3.2ms)
2017-09-14 06:38:57.207720 I [81773:puma 002] (166.4ms) Rails::WelcomeController -- Completed #index -- {:controller=>"Rails::WelcomeController", :action=>"index", :format=>"*/*", :method=>"GET", :path=>"/", :status=>200, :view_runtime=>18.33, :status_message=>"OK"}
We have an issue where no logging happens in our rails app after our before_fork handler executes on a deploy.
What is the right way to re-initialize SemanticLogger after the fork? (I'm guessing that is what happens).
We currently have code like this in the unicorn.conf:
after_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
if defined?(Resque)
Resque.redis = ENV['REDIS_RESQUE_URL']
Rails.logger.info("Resque connected to Redis at #{ENV['REDIS_RESQUE_URL']}")
end
end
We do not see those two log messages (and none of the others). Pointers?
In this patch #49, I'm still encountering the issue since there is no fallback when controller.constantize.logger
returns nil
Full details here: doorkeeper-gem/doorkeeper#1061
I'm using semantic_logger to send logs to a remote syslog endpoint, but they are all reporting as SemanticLogger.
How do I change the name to the app's name, so centralized logging can parse it more easily?
production unicorn
gems:
# config/environments/production.rb
config.rails_semantic_logger.add_file_appender = false
config.semantic_logger.add_appender(
appender: SemanticLogger::Appender::Syslog.new(
application: 'MYAPP-admin',
facility: ::Syslog::LOG_LOCAL7
)
)
# config/unicorn.conf.rb
worker_processes 4 # this is important
...
after_fork do |server, worker|
# Re-open appenders after forking the process
SemanticLogger.reopen
end
$ bundle exec unicorn -E production -c config/unicorn.rb
When running the unicorn server in several processes the logger does not work.
If add SemanticLogger.reopen
i see error in log/unicorn.stderr.log
syslog already open (RuntimeError)
Similar to this issue: #26 (comment)
Hello and thank you for this gem.
I would like to ask what the best way would be to override the formatter for the default file appender that captures the log output from Rails / ActiveRecord / ActionController / ActionMailer (as configured in the railtie).
I have read the README on the semantic logger gem page, but it is my understanding that this covers new appenders, not preconfigured ones.
I have tried to use SemanticLogger.remove_appender and then add my own, but to no avail.
Thank you in advance for your support.
I've been looking at the code for a really long time now and I can't seem to find any decent way of turning the rails appender into a JSON formatted STDOUT.
If this isn't easily achievable I wanted to add a feature request for this. I don't like the initializer approach because I am trying to solve a problem once for all our projects which means I am wrapping SemanticLogger (and rails_semantic_logger) in a gem that we own and control that has (for us) sensible defaults.
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
rails-5.0.5
semantic_logger-4.2.0
rails_semantic_logger-4.1.3
puma-3.8.2
no semantic_logger configuration changes
Devise::SessionsController -- Completed #new -- { :controller => "Devise::SessionsController", :action => "new",
:format => "HTML",
:method => "GET",
:path => "/devise_users/sign_in",
:status => 200,
:view_runtime => 1598.92,
:db_runtime => 3.59,
:status_message => "OK" }
When controller response is 401 (due to failed before_action), the status and status_message are NOT recorded:
MiscPagesController -- Completed #terms_and_conditions -- { :controller => "MiscPagesController", :action => "terms_and_conditions",
:format => "HTML",
:method => "GET",
:path => "/terms",
:view_runtime => 0.0,
:db_runtime => 0.0 }
Note: this 401 is due to Devise's before_action :authenticate_user!
In the docs:
When running in an environment where local file logging is not available, or to completely replace the file logger, disable the default rails file logging by setting:
config.rails_semantic_logger.add_file_appender = true
I believe this is supposed to be:
config.rails_semantic_logger.add_file_appender = false
Ruby 2.3.2p217
Rails 4.2.0
Semantic Logger 4.2.0
Rails Semantic Logger 4.1.3
Puma 3.11.0
Rails configuration:
# config/environments/production.rb
# โฆ
config.log_level = :info
config.rails_semantic_logger.add_file_appender = false
config.semantic_logger.add_appender(io: STDOUT, formatter: :color, async: true)
# โฆ
Logs of "rendered" activity (for views and partials) from ActionView should be classified as debug
.
In production "rendered" entries are showing up with I
(info).
What's interesting is that this works fine in development environment. I see "rendered" messages correctly showing up as D
(debug) and not I
. I have a hunch that the problem is here:
The defined?(ActionView::LogSubscriber)
might be returning false in production and true in development, but why would it do that? Here's puma config:
daemonize false
directory '/app'
threads 1, 40
bind 'unix:///var/run/puma.sock'
worker_timeout 60
environment ENV['RAILS_ENV']
rails_semantic_logger already uses append_info_to_payload
to let us configure what gets logged automatically with every request. This works really well.
However, in some cases, we manually log some errors, warnings, infos etc, i.e. logger.warn("something went wrong here")
. The "problem" with this is that this particular log record is somehow detached from the request log message, so I can't easily trace it to the same request... The logs will look something like this
2018-02-16 10:57:03.495567 W [18:13144340] HomeController -- something went wrong here
2018-02-16 10:57:03.571882 D [18:13144340] (1.724ms) ActiveRecord::Base -- {:sql=>"BEGIN"}
...
2018-02-16 10:57:09.953765 I [18:13144340] (6.459s) HomeController -- Completed #index -- {:controller=>"HomeController", :action=>"index", :format=>"HTML", :method=>"GET", :path=>"/", :status=>200, :view_runtime=>6271.12, :db_runtime=>103.66, :geoip_country=>nil, :ip=>"1.2.3.4", :current_user=>"bob", :status_message=>"OK"}
I'm wondering what's the best way to add some request info into those manual logs ... I can probably wrap logger with some helper, but I'm not sure it's the best way. Any suggestions / best practice to achieve this in a clean and safe way?
It's been close to 9 months since a release and there have been significant contributions including tests for Rails 5.2.
What needs to happen to get at the very least a patch-rev version out to rubygems?
I have an application with multiple environments in Heroku. Both of them use the production
rails environment. I have a Sidekiq job that starts like this:
module Workers
module Slack
class NewOrders
include Sidekiq::Worker
include SemanticLogger::Loggable
extend Memoist
def initialize
@slack_client = default_slack_client
end
# :reek:ControlParameter
def perform(client: nil)
logger.info "Checking for new orders since #{since} ..."
@slack_client = client if client
send_notifications(since: since)
update_last_query_time
end
In one environment (staging
), I see the output in the Heroku logs. However, in the other environment (production
), I am not seeing the output.
I have confirmed that my default_level
is set to :trace
in both environments. Here is my initializer:
require 'semantic_logger'
SemanticLogger.default_level = :trace
SemanticLogger.add_appender(io: $stdout) if Figaro.env.heroku_app_name
How come the logs are not appearing in production?
Ruby: 2.5.1
, 2.4.3
Rails: 5.1.6
, 5.1.5
Rails Semantic Logger: 4.2.1
Puma: 3.11.3
application.rb config:
config.log_level = :info
config.log_tags = {
request_id: :request_id,
ip: :remote_ip,
user: -> request { request.cookie_jar['login'] }
}
config.rails_semantic_logger.semantic = true
config.rails_semantic_logger.started = false
config.rails_semantic_logger.processing = false
config.rails_semantic_logger.rendered = false
Using the configuration above, I would expect the log tags to be appended to the log output.
Seems that the log_tags
hash just gets serialized via to_s
and prepended to the log output.
2018-04-08 14:44:17.288342 I [98222:puma 004] [[[:request_id, :request_id], [:ip, :remote_ip], [:user, #<Proc:0x00007fa40d7e0a50@/Users/tpesut/mindleaps/tracker/config/application.rb:41 (lambda)>]]] (239.9ms) StudentsController -- Completed #show -- { :controller => "StudentsController", :action => "show", :params => { "id" => "204" }, :format => "HTML", :method => "GET", :path => "/students/204", :status => 200, :view_runtime => 216.52, :rendered_format => :html, :variant => [], :db_runtime => 3.17, :status_message => "OK" }
This is in line with the default Rails log_tags
configuration, since it really expects an array of symbols that correspond to request methods and everything else gets serialized; however, since Semantic logger specifically mentions the log_tags
hash in the documentation, I would expect it to behave differently.
I get the following error when attempting to define a new appender.
db_log_appender.rb:3:in `<top (required)>': uninitialized constant SemanticLogger::Subscriber (NameError)
I changed it to SemanticLogger::Appender::Base and it stopped erring but I don't understand why. The sample code says to inherit from Subscriber.
Is there something else I should be doing?
what | value |
---|---|
Ruby Version | 2.3 |
Rails Version | 4.2.7 |
Semantic Logger Version | 4.2.0 |
Rails Semantic Logger Version | 4.1.3 |
Puma | 3.9.1 |
My config as described in
# per rails_12factor, example of ussing ENV var to need for rails_stdout_logging
# On Heroku, config:set RAILS_LOG_TO_STDOUT=true
if ENV["RAILS_LOG_TO_STDOUT"].present?
# turn off file logging
config.rails_semantic_logger.add_file_appender = false
# configure logging to STDOUT like rails_stdout_logging (i.e. 'io: STDOUT' and 'STDOUT.sync = true')
config.semantic_logger.add_appender(io: STDOUT, level: config.log_level, formatter: config.rails_semantic_logger.format)
STDOUT.sync = true
end
additional config if still using rails_12factor or rails_stdout_logging
fail "remove the block which overrides the RailsStdoutLogging override" unless defined?(RailsStdoutLogging)
initializer(:override_rails_stdout_logging_logger, after: :rails_stdout_logging) do
::Rails.logger = config.logger = SemanticLogger[Rails]
end
Results in logs which Heroku prints as:
2017-12-19T20:45:43.067591+00:00 app[scheduler.7507]: 2017-12-19T20:45:43.067183Z I [4:70005105193240] Rails -- [SKYLIGHT] [1.4.2] Skylight agent enabled -- {:pid=>4}
I expected dropping in rails_semantic_logger would be enough.
However, rails_stdout_logger was still setting the logger in production. I override its initializer to get over that.
But now nothing was being logged because, and I'm guessing, the default file appender was trying to log to a file. Since there's no Rails-level config I see for telling it to use the STDOUT
device, even though it takes an io
option, I had to write my own config, which I'm not sharing.
This took quite a bit of docs and code reading, and I would have thought someone else had tried this, or that there'd even be a 'plugin'. I'm happy to have that discussion here or in the other repo, or make a PR if this looks like I'm using the gem correctly.
Also, while here, I wanted to show how I added some default params to the payload using a module, since it was unclear if log tags could/should do that.
# Extend logging formatter: default
config.rails_semantic_logger.format = :default
SemanticLogger::Formatters::Default.prepend ::LoggingFormater
module LoggingFormatter
# Default time format is ISO8601
def initialize(time_format: :iso_8601, log_host: true, log_application: true)
super(time_format: time_format, log_host: log_host, log_application: log_application)
end
def payload
log.payload ||= {}
log.payload[:pid] = Process.pid
super
end
end
Note:
config.rails_semantic_logger.semantic = true
it throws an error. It is happening whenever the application hits the database and tries to log the SQL queries.{"name":"ActiveRecord::Base","pid":3125,"thread":"70305435605980","level":"error","level_index":4,"host":"MacBook-Pro.local","application":"Semantic Logger","file":"/Users/sampleuser/.rvm/gems/ruby-2.1.7@sample/gems/activesupport-3.2.22.5/lib/active_support/log_subscriber.rb","line":95,"message":"Could not log \"sql.active_record\" event. NameError: uninitialized constant
ERROR -- : Could not log "sql.active_record" event. NameError: uninitialized constant ActiveRecord::LogSubscriber::IGNORE_PAYLOAD_NAMES
Please help me to resolve to move forward
In production.rb I am trying to set the log level to trace as follows config.log_level = :trace. I get the following error.
/home/ubuntu/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/application/bootstrap.rb:56:in `const_get': uninitialized constant ActiveSupport::Logger::TRACE (NameError)
Is the logger not getting replaced and should possibly be done in an initializer? Also on a fun side not in production mode when I try and write out to the log nothing is getting written. I am not sure if it is an issue with the gem or not, however, my sidekiq logger is getting replaced in the sidekiq initializer Sidekiq::Logging.logger = SemanticLogger['Sidekiq'] and anything coming from there is getting logged.
Rails -- Exception: NoMethodError: undefined method `current_tags' for nil:NilClass
/var/lib/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb:21:in `tag'
/var/lib/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb:36:in `log'
/var/lib/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb:30:in `block (2 levels) in <class:TaggedLoggerProxy>'
/var/lib/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/base.rb:71:in `process'
/var/lib/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/server/base.rb:28:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/routing/mapper.rb:17:in `block in <class:Constraints>'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/routing/mapper.rb:46:in `serve'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/journey/router.rb:39:in `block in serve'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/journey/router.rb:26:in `each'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/journey/router.rb:26:in `serve'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/routing/route_set.rb:725:in `call'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/etag.rb:25:in `call'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/conditional_get.rb:25:in `call'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/head.rb:12:in `call'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/session/abstract/id.rb:222:in `context'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/session/abstract/id.rb:216:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/cookies.rb:613:in `call'
/var/lib/gems/2.3.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:553:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
/var/lib/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:97:in `__run_callbacks__'
/var/lib/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
/var/lib/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/callbacks.rb:90:in `run_callbacks'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/callbacks.rb:36:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/executor.rb:12:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
/var/lib/gems/2.3.0/gems/better_errors-2.1.1/lib/better_errors/middleware.rb:59:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
/var/lib/gems/2.3.0/gems/web-console-3.4.0/lib/web_console/middleware.rb:135:in `call_app'
/var/lib/gems/2.3.0/gems/web-console-3.4.0/lib/web_console/middleware.rb:28:in `block in call'
/var/lib/gems/2.3.0/gems/web-console-3.4.0/lib/web_console/middleware.rb:18:in `catch'
/var/lib/gems/2.3.0/gems/web-console-3.4.0/lib/web_console/middleware.rb:18:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
/var/lib/gems/2.3.0/gems/railties-5.0.1/lib/rails/rack/logger.rb:36:in `call_app'
/var/lib/gems/2.3.0/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `block in call'
/home/msg7086/.bundle/ruby/2.3.0/semantic_logger-f8d2970cb247/lib/semantic_logger/semantic_logger.rb:299:in `tagged'
/home/msg7086/.bundle/ruby/2.3.0/semantic_logger-f8d2970cb247/lib/semantic_logger/base.rb:146:in `tagged'
/var/lib/gems/2.3.0/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `call'
/var/lib/gems/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/quiet_assets.rb:13:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/request_id.rb:24:in `call'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/method_override.rb:22:in `call'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/runtime.rb:22:in `call'
/var/lib/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/executor.rb:12:in `call'
/var/lib/gems/2.3.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/static.rb:136:in `call'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call'
/var/lib/gems/2.3.0/gems/railties-5.0.1/lib/rails/engine.rb:522:in `call'
/var/lib/gems/2.3.0/gems/rack-2.0.1/lib/rack/handler/webrick.rb:86:in `service'
/usr/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/usr/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/usr/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
Where action_cable/connection/tagged_logger_proxy.rb:21
says
if logger.respond_to?(:tagged)
current_tags = tags - logger.formatter.current_tags <--
logger.tagged(*current_tags) { yield }
else
yield
end
Problem only gets hit by action cable connections. On latest github version.
config.action_mailer.logger = nil
Basically if I set config.action_mailer.logger = nil
I expect messages not to be logged at all.
Should not log messages if logging is disabled in app config ๐
Messages are being logged ๐ข
Hi there,
We recently did a bundle update of rsl and we do not get any logging into our standard log. After troubleshooting it a bit, we rolled back to 4.2.0 and everything started working again.
I'm not sure what could be going on, exactly; we have the issue show up in all our environments, not just development (where we have more going on, with colorized logging, awesome print, extra appenders, etc). Production is very simple -- we just use 2 options:
config.colorize_logging = false
config.rails_semantic_logger.quiet_assets = true
I believe this is the diff:
I'm not sure what might be causing this. Is anyone else experiencing this?
I'm running Rails 5.0.0.1 with active_model_serializers 0.10.2. I'm trying to get UDP logging going so I can send logs to my logstash server (logstash-logger removes data I'm adding to my log payload, so I'm trying to find another way to use logstash), but I'm getting the described exception.
I've got the following in my config/environments/development.rb
:
# All of these result in the same failure
# SemanticLogger.add_appender appender: :udp, server: 'my_address_and_port'
# SemanticLogger.add_appender logger: config.logger
config.after_initialize do
config.semantic_logger.add_appender appender: :udp, server: 'my_address_and_port'
end
# The following doesn't seem to change anything, but including just in case
config.rails_semantic_logger.semantic = false
Here's the top of the trace in case it's helpful:
2016-10-10 16:15:16.670190 F [73913:70130055111100 debug_exceptions.rb:7] [bfae6a2c-464a-4f09-a02d-95583a43a266] Rails -- Exception: NoMethodError: undefined method `logger' for ActiveModelSerializers::SerializableResource:Class
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/semantic_logger-3.3.0/lib/semantic_logger/loggable.rb:44:in `logger'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/rails_semantic_logger-3.3.1/lib/rails_semantic_logger/extensions/active_model_serializers/logging.rb:9:in `tag_logger'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/active_model_serializers-0.10.2/lib/active_model_serializers/logging.rb:20:in `block in instrument_rendering'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:391:in `instance_exec'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:391:in `block in make_lambda'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:285:in `call'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:285:in `block in halting'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:447:in `call'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:447:in `block in around'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:750:in `_run_render_callbacks'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:90:in `run_callbacks'
/Users/sloveless/Development/agrian/choopa/vendor/bundle/ruby/2.2.0/gems/active_model_serializers-0.10.2/lib/active_model_serializers/logging.rb:68:in `block (2 levels) in notify'
/
I suppose there could be something with my configuration
E [24050:puma 002 log_subscriber.rb:85] ActiveRecord::Base -- Could not log "sql.active_record" event. ArgumentError: wrong number of arguments (given 1, expected 2)
Hi,
Thanks again.
Scott
Hi, help me with this, please
To work with ES i configure a connection:
require 'faraday_middleware/aws_signers_v4'
transport_configuration = lambda do |f|
f.request :aws_signers_v4,
credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_KEY']),
service_name: 'es',
region: 'eu-west-1'
f.response :logger
f.adapter Faraday.default_adapter
end
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
hosts: [{scheme: 'https', host: ENV['ELASTICSEARCH_URL'], port: '443'}],
&transport_configuration
Elasticsearch::Model.client = Elasticsearch::Client.new transport: transport, trace: true
And it works, but how can i do the same for semantic logger ES appender?
SemanticLogger.add_appender(
appender: :elasticsearch
url: 'http://some-search-server-here.eu-west-1.es.amazonaws.com'
)
Note:
Only one parameter is expected:
https://github.com/rails/rails/blob/v5.1.5/activerecord/lib/active_record/log_subscriber.rb#L45
But we pass two:
https://github.com/rocketjob/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/active_record/log_subscriber.rb#L33
Rails version: 5.0.0.beta3
In my Rails 5 application, I don't seem to be getting the semantic behavior of this library (e.g. the format, runtimes, status_message, etc) on "completed" logs. The logs are still being formatted correctly, it just seems to be missing some information:
{
"name": "Rails",
"pid": 10,
"thread": "70187985393180",
"level": "info",
"level_index": 2,
"host": "33e8208f-a23a-44e3-8e51-ad97fec62806",
"application": "SSO",
"tags": [
"001d4663-2784-443e-8970-ba154ed3d24c"
],
"message": "Completed 302 Found in 117ms (ActiveRecord: 0.0ms)",
"timestamp": "2016-04-19T14:04:17.974534Z"
}
This is with the rails_semantic_logger
included in my Gemfile, with no other configuration. No awesome_print
included as well.
(moved from reidmorrison/semantic_logger#32)
In semantic_logger v1.8 I had logging output that looked like this (with a custom formatter):
I just upgraded to v3.3 and the same formatter (adapted to new AwesomePrint format) looks like this:
Unfortunately, the 'payload' portion of the log feels like a step backwards. Any way to get the old log formatting back?
bundle install
, then boot with rails s
=> Booting WEBrick
=> Rails 3.2.22.5 application starting in development on http://0.0.0.0:3005
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rails_semantic_logger-4.3.0/lib/rails_semantic_logger.rb:24:in `swap_subscriber': undefined method `subscribers' for ActiveSupport::LogSubscriber:Class (NoMethodError)
Did you mean? log_subscribers
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rails_semantic_logger-4.3.0/lib/rails_semantic_logger/engine.rb:225:in `block in <class:Engine>'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/activesupport-3.2.22.5/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/activesupport-3.2.22.5/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/activesupport-3.2.22.5/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/activesupport-3.2.22.5/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/application/finisher.rb:59:in `block in <module:Finisher>'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/initializable.rb:30:in `run'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/initializable.rb:54:in `each'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/application.rb:136:in `initialize!'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/huntermeyer/Documents/L360Repos/legacy_dashboards/config/environment.rb:5:in `<top (required)>'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:251:in `require'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:251:in `require'
from /Users/huntermeyer/Documents/L360Repos/legacy_dashboards/config.ru:3:in `block in <main>'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rack-1.4.7/lib/rack/builder.rb:51:in `instance_eval'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rack-1.4.7/lib/rack/builder.rb:51:in `initialize'
from /Users/huntermeyer/Documents/L360Repos/legacy_dashboards/config.ru:in `new'
from /Users/huntermeyer/Documents/L360Repos/legacy_dashboards/config.ru:in `<main>'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rack-1.4.7/lib/rack/builder.rb:40:in `eval'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rack-1.4.7/lib/rack/builder.rb:40:in `parse_file'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rack-1.4.7/lib/rack/server.rb:200:in `app'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/commands/server.rb:46:in `app'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rack-1.4.7/lib/rack/server.rb:304:in `wrapped_app'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/rack-1.4.7/lib/rack/server.rb:254:in `start'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/commands/server.rb:70:in `start'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/commands.rb:50:in `tap'
from /Users/huntermeyer/.rvm/gems/ruby-2.3.6@legacy_dashboards/gems/railties-3.2.22.5/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:21:in `require'
from script/rails:21:in `<main>'
Note:
ActiveSupport::LogSubscriber
does not respond to subscribers
. Furthermore, on this line here, an instance of ActiveSupport::LogSubscriber
does not respond to patterns
.I experienced this issue: reidmorrison/semantic_logger#43 where semantic logger doesn't log anything on production that is using unicorn. I saw that I needed to do this:
# config/unicorn.conf.rb
after_fork do |server, worker|
# Re-open appenders after forking the process
SemanticLogger.reopen
end
# reference: http://rocketjob.github.io/semantic_logger/forking.html
to make it work.
But when I tried it, the site doesn't load and I found out it's because it is using 100% cpu after I added SemanticLogger.reopen
My config/environments/production.rb
file also contains this:
config.rails_semantic_logger.add_file_appender = false # disable logging to a file
config.after_initialize do
config.semantic_logger.add_appender(appender: :syslog, formatter: :json)
end
In config/application.rb:
config.semantic_logger.backtrace_level = :trace
In config/puma.rb
on_worker_boot do
# Re-open appenders after forking the process
SemanticLogger.reopen
end
While testing upgrading an app to Rails 4.2, I came across some logger related errors when using ActiveJob.
Trying to use the deliver_later
method on a mailer with active job throws an error on this line: https://github.com/rails/rails/blob/master/activejob/lib/active_job/logging.rb#L50
The error thrown is undefined method current_tags
for nil.
From my gemfile
gem 'active_model_serializers', github: 'rails-api/active_model_serializers', tag: 'v0.10.0.rc5'
2016-04-28 17:11:12.727557 F [90816:2172420880 debug_exceptions.rb:7] Rails -- Exception: NoMethodError: undefined method `current_tags' for nil:NilClass
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/bundler/gems/active_model_serializers-2da361f16357/lib/active_model_serializers/logging.rb:102:in `logger_tagged_by_active_model_serializers?'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/bundler/gems/active_model_serializers-2da361f16357/lib/active_model_serializers/logging.rb:94:in `tag_logger'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/bundler/gems/active_model_serializers-2da361f16357/lib/active_model_serializers/logging.rb:20:in `block in instrument_rendering'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:441:in `instance_exec'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:441:in `block in make_lambda'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:342:in `call'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:342:in `block in simple'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:497:in `call'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:497:in `block in around'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:505:in `call'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:505:in `call'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:778:in `_run_render_callbacks'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/gems/activesupport-4.2.4/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/andrew/.rvm/gems/ruby-2.1.1@coolon_light_manager/bundler/gems/active_model_serializers-2da361f16357/lib/active_model_serializers/logging.rb:68:in `block (2 levels) in notify'
/Users/andrew/light_architect_web/app/serializers/base_serializer.rb:4:in `serialize'
Any thoughts?
Using regular logging, I should get something like:
ActiveRecord::SchemaMigration Load (1.5ms) SELECT `schema_migrations`.* FROM `schema_migrations`
User Load (2.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 637242267 ORDER BY `users`.`id` ASC LIMIT 1
Role Load (1.9ms) SELECT `roles`.* FROM `roles` INNER JOIN `users_roles` ON `roles`.`id` = `users_roles`.`role_id` WHERE `users_roles`.`user_id` = 637242267
But instead, I'm getting:
2017-04-07 14:14:06.999558 E [43197:70206873811960 log_subscriber.rb:85] ActiveRecord::Base -- Could not log "sql.active_record" event. TypeError: no implicit conversion of Hash into String ["/Users/joao/.rbenv/versions/2.1.8/lib/ruby/gems/2.1.0/bundler/gems/octopus-a138b9363163/lib/octopus/log_subscriber.rb:17:in `+'", "/Users/joao/.rbenv/versions/2.1.8/lib/ruby/gems/2.1.0/bundler/gems/octopus-a138b9363163/lib/octopus/log_subscriber.rb:17:in `debug_with_octopus_shard'", "/Users/joao/.rbenv/versions/2.1.8/lib/ruby/gems/2.1.0/gems/rails_semantic_logger-4.0.0/lib/rails_semantic_logger/extensions/active_record/log_subscriber.rb:36:in `sql'", "/Users/joao/.rbenv/versions/2.1.8/lib/ruby/gems/2.1.0/gems/activesupport-4.2.7/lib/active_support/subscriber.rb:100:in `finish'", "/Users/ (...)
The issue in particular seems to be caused by Could not log "sql.active_record" event. TypeError: no implicit conversion of Hash into String
.
I'm using the gem without any configuration.
Just an FYI when 3.3 is released.
BTW it actually gives this error even if the file exists and has the right permissions.
2016-04-11 10:08:44.094278 T [14802:SemanticLogger::AppenderThread] SemanticLogger::Appender::File -- V3.3.0 Appender thread active
2016-04-11 10:08:44.094424 W [14802:70115773506000 base.rb:19] Rails -- Rails Error: Unable to access log file. Please ensure that /Users/tim/Documents/mhn/source/pgdw/log/development.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed. -- Exception: ArgumentError: Unknown options: {:multiline=>false}
/Users/tim/.gem/ruby/2.2.3/bundler/gems/semantic_logger-6939a43eb3a8/lib/semantic_logger/formatters/base.rb:19:in `initialize'
/Users/tim/.gem/ruby/2.2.3/bundler/gems/semantic_logger-6939a43eb3a8/lib/semantic_logger/formatters/color.rb:20:in `initialize'
/Users/tim/.gem/ruby/2.2.3/gems/rails_semantic_logger-3.1.1/lib/rails_semantic_logger/railtie.rb:77:in `new'
/Users/tim/.gem/ruby/2.2.3/gems/rails_semantic_logger-3.1.1/lib/rails_semantic_logger/railtie.rb:77:in `block in <class:Railtie>'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `each'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `tsort_each_child'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:413:in `call'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `call'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
/Users/tim/.rubies/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
/Users/tim/Documents/mhn/source/pgdw/config/environment.rb:5:in `<top (required)>'
/Users/tim/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
/Users/tim/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
/Users/tim/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/tim/.gem/ruby/2.2.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/application.rb:328:in `require_environment!'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:142:in `require_application_and_environment!'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:67:in `console'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
/Users/tim/.gem/ruby/2.2.3/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
The documentation states that if add_file_appender
is set to false
no logs will go anywhere. The implication being that a configuration like
config.rails_semantic_logger.add_file_appender = false
config.semantic_logger.add_appender(
io: STDOUT,
level: config.log_level,
formatter: :son
)
Would result in a single appender, going to standard out.
However, when using the rails server (in development, for example), a default appender is still added, so we see duplicate logs (one :json format, one :color format).
How do you set this up if you want your logs to be tagged by default without using a block?
Hi, I've been looking into semantic_logger for formatting logs for Logstash, and it looks pretty nice overall! Really like the threaded design to avoid logging slowing down the application. I just noticed something strange in development though; each GET for an asset has a bunch of extra blank lines, which is kind of annoying. I actually think that in production Rails still defaults to log_level = :debug
so it seems like this would show up there too?
Example log output:
2016-04-11 19:26:50.958934 D [4403:47051589538600] Rails -- Started GET "/assets/application.css" for 10.0.3.1 at 2016-04-11 19:26:50 +0000 2016-04-11 19:26:50.982768 D [4403:47051589538600] Rails -- 2016-04-11 19:26:50.982815 D [4403:47051589538600] Rails --
As you can see, there are two extra lines for the GET that are completely blank. This happens for eac GET. Disabling semantic_logger removes these lines, and interestingly, setting config.rails_semantic_logger.semantic = false
still results in this output (i.e., the output above is with semantic disabled).
This seems like a poor interaction with some other part of my infrastructure, but not sure what it could be. We're using unicorn as our development and production server, Rails 4.2.6, Sprockets 3.52, etc. Any ideas? Thanks!
ruby 2.4.2-p198
Rails 5.1.5
semantic logger 4.2.0
Puma: Version 3.11.3 (ruby 2.4.2-p198), codename: Love Song
2018-03-21 15:13:51.224088 E [20407:puma 001 log_subscriber.rb:86] ActiveRecord::Base -- Could not log "sql.active_record" event. ArgumentError: wrong number of arguments (given 2, expected 1) [
"/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/activerecord-5.1.5/lib/active_record/log_subscriber.rb:45:in `type_casted_binds'",
"/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/rails_semantic_logger-4.2.0/lib/rails_semantic_logger/extensions/active_record/log_subscriber.rb:33:in `sql'",
"/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/activesupport-5.1.5/lib/active_support/subscriber.rb:99:in `finish'",
"/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/activesupport-5.1.5/lib/active_support/log_subscriber.rb:83:in `finish'", "/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/activesupport-5.1.5/lib/active_support/notifications/fanout.rb:102:in `finish'",
"/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/activesupport-5.1.5/lib/active_support/notifications/fanout.rb:46:in `block in finish'",
"/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/activesupport-5.1.5/lib/active_support/notifications/fanout.rb:46:in `each'", "/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/activesupport-5.1.5/lib/active_support/notifications/fanout.rb:46:in `finish'", "/Users/enrico/.rvm/gems/ruby-2.4.2@frontend/gems/activesupport-5.1.5/lib/active_support/notifications/instrumenter.rb:42:in `finish_with_state'",
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.