Syslog support broken?

Infos:

  • Used Zammad version: 3.6
  • Used Zammad installation source: source
  • Operating system: Ubuntu 18.04
  • Browser + version: n/a

Expected behavior:

  • Zammad is logging to syslog

Actual behavior:

  • Starting zammad with syslog enabled, an “undefined method” error is logged:

undefined method `silence’ for #Syslog::Logger:0x00005593f64ab660

Steps to reproduce the behavior:

  • I’ve uncommented line 86 and 87 in production.rb to enable syslog support. It has been working before (I don’t know the version when it broke :frowning: )

Any idea how to solve this issue?

I’ve seen the same while building and running docker images locally:

zammad-railsserver_1    | I, [2021-03-18T16:08:49.539401 #1-47129039157600]  INFO -- : Setting.set('models_searchable', ["User", "Chat::Session", "Ticket", "KnowledgeBase::Answer::Translation", "Organization"])
zammad-railsserver_1    | Puma starting in single mode...
zammad-railsserver_1    | * Version 3.12.6 (ruby 2.6.6-p146), codename: Llamas in Pajamas
zammad-railsserver_1    | * Min threads: 5, max threads: 30
zammad-railsserver_1    | * Environment: production
zammad-railsserver_1    | * Listening on tcp://[::]:3000
zammad-railsserver_1    | Use Ctrl-C to stop
zammad-railsserver_1    | I, [2021-03-18T16:15:10.182220 #1-47129111432300]  INFO -- : Started GET "/" for ::ffff:172.24.0.10 at 2021-03-18 16:15:10 +0000
zammad-railsserver_1    | I, [2021-03-18T16:15:10.192108 #1-47129111432300]  INFO -- : Processing by InitController#index as */*
zammad-railsserver_1    | E, [2021-03-18T16:15:10.192813 #1-47129111432300] ERROR -- : undefined method `silence' for #<Logger:0x000055ba2fdbae90> (NoMethodError)
zammad-railsserver_1    | /usr/local/bundle/gems/activerecord-session_store-2.0.0/lib/action_dispatch/session/active_record_store.rb:119:in `get_session_model'
zammad-railsserver_1    | /usr/local/bundle/gems/activerecord-session_store-2.0.0/lib/action_dispatch/session/active_record_store.rb:147:in `find_session'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:314:in `load_session'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/session/abstract_store.rb:46:in `block in load_session'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/session/abstract_store.rb:54:in `stale_session_check!'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/session/abstract_store.rb:46:in `load_session'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/request/session.rb:227:in `load!'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/request/session.rb:223:in `load_for_write!'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/request/session.rb:124:in `[]='
zammad-railsserver_1    | /opt/zammad/app/controllers/application_controller/has_user.rb:83:in `session_update'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:426:in `block in make_lambda'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:199:in `block in halting'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:513:in `block in invoke_before'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:513:in `each'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:513:in `invoke_before'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:107:in `block in run_callbacks'
zammad-railsserver_1    | /opt/zammad/app/controllers/application_controller/handles_transitions.rb:14:in `handle_transaction'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:136:in `run_callbacks'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/abstract_controller/callbacks.rb:41:in `process_action'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_controller/metal/rescue.rb:22:in `process_action'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/notifications.rb:168:in `block in instrument'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/notifications.rb:168:in `instrument'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
zammad-railsserver_1    | /usr/local/bundle/gems/activerecord-5.2.4.5/lib/active_record/railties/controller_runtime.rb:24:in `process_action'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/abstract_controller/base.rb:134:in `process'
zammad-railsserver_1    | /usr/local/bundle/gems/actionview-5.2.4.5/lib/action_view/rendering.rb:32:in `process'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_controller/metal.rb:191:in `dispatch'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_controller/metal.rb:252:in `dispatch'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/routing/route_set.rb:34:in `serve'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/journey/router.rb:52:in `block in serve'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/journey/router.rb:35:in `each'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/journey/router.rb:35:in `serve'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/routing/route_set.rb:840:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:420:in `call_app!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-saml-1.10.1/lib/omniauth/strategies/saml.rb:89:in `other_phase'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:190:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:192:in `call!'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/strategy.rb:169:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/omniauth-1.9.1/lib/omniauth/builder.rb:45:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/conditional_get.rb:27:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:266:in `context'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/cookies.rb:670:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/callbacks.rb:98:in `run_callbacks'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/railties-5.2.4.5/lib/rails/rack/logger.rb:38:in `call_app'
zammad-railsserver_1    | /usr/local/bundle/gems/railties-5.2.4.5/lib/rails/rack/logger.rb:28:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/request_id.rb:27:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/activesupport-5.2.4.5/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/actionpack-5.2.4.5/lib/action_dispatch/middleware/executor.rb:14:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/railties-5.2.4.5/lib/rails/engine.rb:524:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/puma-3.12.6/lib/puma/configuration.rb:227:in `call'
zammad-railsserver_1    | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:706:in `handle_request'
zammad-railsserver_1    | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:476:in `process_client'
zammad-railsserver_1    | /usr/local/bundle/gems/puma-3.12.6/lib/puma/server.rb:334:in `block in run'
zammad-railsserver_1    | /usr/local/bundle/gems/puma-3.12.6/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
zammad-railsserver_1    | /usr/local/bundle/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
zammad-railsserver_1    | E, [2021-03-18T16:15:10.195404 #1-47129111432300] ERROR -- : Error ID 7lSwTqtc: undefined method `silence' for #<Logger:0x000055ba2fdbae90>
zammad-railsserver_1    | I, [2021-03-18T16:15:10.195829 #1-47129111432300]  INFO -- : Completed 500 Internal Server Error in 4ms (Views: 0.2ms)

@thorsteneckel
as activerecord-session_store-2.0.0 is mentioned it might be related to the update of the module?
see: Maintenance: Updated activerecord-session_store gem dependency to 2.0.0. · zammad/zammad@d032025 · GitHub

This looks interesting: Get rid of LoggerSilencer and assume ActiveRecord::Base.logger includ… · rails/activerecord-session_store@0106147 · GitHub

Looking a bit further: NoMethodError: undefined method silence for Logger after 2.0.0 upgrade · Issue #176 · rails/activerecord-session_store · GitHub
Now I just need to know, how to solve it for zammad :slight_smile:

Hey there :wave: I’m having hard times reproducing the error. All I found was this remark from the activerecord-session_store README:

Please note that you will need to manually include the silencer module to your custom logger if you are using a logger other than Logger and Syslog::Logger and their subclasses:

MyLogger.send :include, ActiveRecord::SessionStore::Extension::LoggerSilencer
This silencer is being used to silence the logger and not leaking private information into the log, and it is required for security reason.

However, it states that Syslog::Logger already includes the required changes.

As you @saz have installed from source there might be other changes related?

@monotek what docker image are you building?

@saz can you try adding this as a third line config.logger.class.include ActiveSupport::LoggerSilence

should look something like this:

  require 'syslog/logger'
  config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
  config.logger.include(ActiveSupport::LoggerSilence)

@monotek I guess you are changing the logger somewhere in your codebase as well. Please add the corresponding lines too.

Let me know if this works for you guys :wave:

Thanks! :slight_smile:
Fixed it in: use port 8080 for nginx by monotek · Pull Request #193 · zammad/zammad-docker-compose · GitHub

1 Like

@thorsteneckel changing it, as you’ve suggested results in the following error:

NameError: uninitialized constant ActiveSupport::LoggerSilence

Here are the changes I’ve made on production.rb:

diff --git a/config/environments/production.rb b/config/environments/production.rb
index 873d86c41..4db3d1fc1 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -36,7 +36,7 @@ Rails.application.configure do

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
-  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
 
# Store uploaded files on the local file system (see config/storage.yml for options)
# config.active_storage.service = :local
@@ -47,7 +47,7 @@ Rails.application.configure do
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
-  # config.force_ssl = true
+  config.force_ssl = true

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
@@ -58,6 +58,8 @@ Rails.application.configure do

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
+  config.cache_store = :dalli_store, 'mc1', 'mc2', 'mc3', { :namespace => 'zammad_' }
+  config.session_store = :dalli_store, 'mc1', 'mc2', 'mc3', { :namespace => 'zammad_sess_' }

# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter     = :resque
@@ -83,8 +85,9 @@ Rails.application.configure do
# config.log_formatter = ::Logger::Formatter.new

# Use a different logger for distributed setups.
-  # require 'syslog/logger'
-  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+  require 'syslog/logger'
+  config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'zammad')
+  config.logger.include(ActiveSupport::LoggerSilence)

if ENV['RAILS_LOG_TO_STDOUT'].present?
  logger           = ActiveSupport::Logger.new($stdout)

And these are all open changes:

On branch stable
Your branch is up to date with 'origin/stable'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

    modified:   config/environments/production.rb

Untracked files:
(use "git add <file>..." to include in what will be committed)

    .bash_history
    .gem/
    .irb-history
    .rvm/
    .viminfo
    .wget-hsts
    public/assets/addons/

no changes added to commit (use "git add" and/or "git commit -a")

As you can see, there are no other code changes, which might be the culprit for the error.

If you need anything else or I should test something, just let me know.

Sorry, I double checked and the correct line is:
config.logger.class.include(LoggerSilence)

Please be aware that you probably need to change this line somewhere in the future when we update our Rails dependency: Update logger silencer instructions by byroot · Pull Request #180 · rails/activerecord-session_store · GitHub

Next error :frowning:

undefined method `local_level=' for #<Syslog::Logger:0x0000564f3feb65b0>

:neutral_face: It’s a tough one…

Please replace all the lines with the following:

require 'syslog/logger'

Syslog::Logger.class_eval do
  include LoggerSilence
  include ActiveSupport::LoggerThreadSafeLevel

  alias_method :initialize_original, :initialize

  def initialize(*args)
    initialize_original(*args)
    after_initialize
  end
end

config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'zammad')

Except for a change at the beginning of the last line, everything’s working as expected.
Zammad is starting and logging to syslog as before.

Thanks!

Do you think this is a permanent solution or is there still something weird on my installation?

config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'zammad')

This will at least need one change in the future when we update to a later version of Rails because they changed the class names of the used modules.

I had to use some tricks to get it work. TBH I think that should be fixed at some other place. Maybe rails (already did it in a later version?).

We strongly discourage any manual changes to Zammad because of unforeseeable issues like these. Would love to see it wrapped up and tested somewhere but Zammad core is unfortunately not the right place.

We test all of our (customer) package extensions regularly against changes in develop to be aware of those kind of issues as soon as they arise - before production deployment is anywhere near. If you’re interested we could offer that for you as part of our commercial services. However, it comes with a price tag. You can get in touch with our sales team over at sales at zammad.com if you’re interested.

Glad that it works now though…

config/environments/production.rb is a part of Zammad, but I’m not aware of any other way to change some settings if it’s a source installation.

If we’re taking the docker installation as an example, it’s using sed to make required changes within config/application.rb

If such changes are discouraged, I’m more than happy to send in a pull request adding proper environment variables for such cases.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.