From a5b8f28e8e3b6f177ce3e070d38a1f19bb9aba8f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 5 May 2015 07:55:06 +0200 Subject: [PATCH] Improved logging. --- app/models/user.rb | 1 + lib/auth.rb | 2 ++ lib/auth/developer.rb | 5 ++++- lib/auth/ldap.rb | 12 ++++++------ lib/sso.rb | 2 ++ test/test_helper.rb | 1 - test/unit/ticket_notification_test.rb | 8 ++++---- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 198287fcb..972e2bfea 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -194,6 +194,7 @@ returns # check failed logins max_login_failed = Setting.get('password_max_login_failed').to_i || 10 if user && user.login_failed > max_login_failed + logger.info "Max login faild reached for user #{user.login}." return false end diff --git a/lib/auth.rb b/lib/auth.rb index f1a21ea2f..5f85ab982 100644 --- a/lib/auth.rb +++ b/lib/auth.rb @@ -48,6 +48,8 @@ returns # auth ok if user_auth + Rails.logger.info "Authentication against #{config_item[:adapter]} for user #{user.login} ok." + # remember last login date user_auth.update_last_login diff --git a/lib/auth/developer.rb b/lib/auth/developer.rb index fc28219ee..27383b8b5 100644 --- a/lib/auth/developer.rb +++ b/lib/auth/developer.rb @@ -5,7 +5,10 @@ module Auth::Developer # development systems if Setting.get('developer_mode') == true - return user if password == 'test' + if password == 'test' + Rails.logger.info "System in developer mode, authentication for user #{user.login} ok." + return user + end end false diff --git a/lib/auth/ldap.rb b/lib/auth/ldap.rb index b9a13334e..c7b83c349 100644 --- a/lib/auth/ldap.rb +++ b/lib/auth/ldap.rb @@ -18,11 +18,11 @@ module Auth::Ldap # ldap bind begin if !ldap.bind - puts "NOTICE: Can't bind to '#{config[:host]}', #{ldap.get_operation_result.code}, #{ldap.get_operation_result.message}" + Rails.logger.info "Can't bind to '#{config[:host]}', #{ldap.get_operation_result.code}, #{ldap.get_operation_result.message}" return end rescue Exception => e - puts "NOTICE: Can't connect to '#{config[:host]}', #{e.to_s}" + Rails.logger.info "Can't connect to '#{config[:host]}', #{e.to_s}" return end @@ -47,14 +47,14 @@ module Auth::Ldap end if user_dn == nil - puts "NOTICE: ldap entry found for user '#{username}' with filter #{filter} failed!" + Rails.logger.info "ldap entry found for user '#{username}' with filter #{filter} failed!" return nil end # try ldap bind with user credentals auth = ldap.authenticate user_dn, password if !ldap.bind( auth ) - puts "NOTICE: ldap bind with '#{user_dn}' failed!" + Rails.logger.info "ldap bind with '#{user_dn}' failed!" return false end @@ -72,10 +72,10 @@ module Auth::Ldap if !user user_attributes[:created_by_id] = 1 user = User.create( user_attributes ) - puts "NOTICE: user created '#{user.login}'" + Rails.logger.debug "user created '#{user.login}'" else user.update_attributes( user_attributes ) - puts "NOTICE: user updated '#{user.login}'" + Rails.logger.debug "user updated '#{user.login}'" end end diff --git a/lib/sso.rb b/lib/sso.rb index 26c58725a..83cdb75c6 100644 --- a/lib/sso.rb +++ b/lib/sso.rb @@ -59,6 +59,8 @@ returns # auth ok if user_auth + Rails.logger.info "Authentication against #{config_item[:adapter]} for user #{user.login} ok." + # remember last login date user_auth.update_last_login diff --git a/test/test_helper.rb b/test/test_helper.rb index 5bd0c6865..cdc1e9abc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -42,7 +42,6 @@ class ActiveSupport::TestCase # cleanup jobs def teardown - puts 'teardown' # check if jobs are proccessed return if Delayed::Job.all.empty? diff --git a/test/unit/ticket_notification_test.rb b/test/unit/ticket_notification_test.rb index 29157e490..0579da7ca 100644 --- a/test/unit/ticket_notification_test.rb +++ b/test/unit/ticket_notification_test.rb @@ -509,7 +509,7 @@ class TicketNotificationTest < ActiveSupport::TestCase }, ) - puts "hc #{human_changes.inspect}" + #puts "hc #{human_changes.inspect}" # check changed attributes human_changes = bg.human_changes(agent1, ticket1) assert( human_changes['Title'], 'Check if attributes translated based on ObjectManager::Attribute' ) @@ -523,13 +523,13 @@ class TicketNotificationTest < ActiveSupport::TestCase assert_not( human_changes['pending_till'] ) human_changes = bg.human_changes(agent2, ticket1) - puts "hc2 #{human_changes.inspect}" + #puts "hc2 #{human_changes.inspect}" template = bg.template_update(agent1, ticket1, article, human_changes) - puts "t1 #{template.inspect}" + #puts "t1 #{template.inspect}" template = bg.template_update(agent2, ticket1, article, human_changes) - puts "t2 #{template.inspect}" + #puts "t2 #{template.inspect}" end