From 5df60dd05711541b406860f2452f1a42231a1a85 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 4 May 2015 21:45:48 +0200 Subject: [PATCH] Improved logging. --- lib/sessions/backend/activity_stream.rb | 4 ++-- lib/sessions/backend/collections/base.rb | 4 ++-- lib/sessions/backend/rss.rb | 2 +- lib/sessions/backend/ticket_create.rb | 2 +- lib/sessions/backend/ticket_overview_index.rb | 2 +- lib/sessions/backend/ticket_overview_list.rb | 14 +++++++------- lib/sessions/client.rb | 13 ++++++------- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/sessions/backend/activity_stream.rb b/lib/sessions/backend/activity_stream.rb index ec4289f0a..946e27af4 100644 --- a/lib/sessions/backend/activity_stream.rb +++ b/lib/sessions/backend/activity_stream.rb @@ -29,7 +29,7 @@ class Sessions::Backend::ActivityStream end def client_key - "as::load::#{ self.class.to_s }::#{ @user.id }::#{ @client_id }" + "as::load::#{ self.class }::#{ @user.id }::#{ @client_id }" end def push @@ -53,7 +53,7 @@ class Sessions::Backend::ActivityStream } end - @client.log 'notify', "push activity_stream #{ data.first.class.to_s } for user #{ @user.id }" + @client.log "push activity_stream #{ data.first.class } for user #{ @user.id }" @client.send( event: 'activity_stream_rebuild', collection: 'activity_stream', diff --git a/lib/sessions/backend/collections/base.rb b/lib/sessions/backend/collections/base.rb index 4bdd65347..3647367dc 100644 --- a/lib/sessions/backend/collections/base.rb +++ b/lib/sessions/backend/collections/base.rb @@ -73,13 +73,13 @@ class Sessions::Backend::Collections::Base assets: assets, } end - @client.log 'notify', "push assets for push_collection #{ items.first.class.to_s } for user #{ @user.id }" + @client.log "push assets for push_collection #{ items.first.class.to_s } for user #{ @user.id }" @client.send( data: assets, event: [ 'loadAssets' ], ) - @client.log 'notify', "push push_collection #{ items.first.class.to_s } for user #{ @user.id }" + @client.log "push push_collection #{ items.first.class.to_s } for user #{ @user.id }" @client.send( event: 'resetCollection', data: { diff --git a/lib/sessions/backend/rss.rb b/lib/sessions/backend/rss.rb index 95ceaa646..3df8319b2 100644 --- a/lib/sessions/backend/rss.rb +++ b/lib/sessions/backend/rss.rb @@ -53,7 +53,7 @@ class Sessions::Backend::Rss } end - @client.log 'notify', "push rss for user #{@user.id}" + @client.log "push rss for user #{@user.id}" @client.send( event: 'rss_rebuild', collection: 'dashboard_rss', diff --git a/lib/sessions/backend/ticket_create.rb b/lib/sessions/backend/ticket_create.rb index eb0e1c70c..1f5caaf10 100644 --- a/lib/sessions/backend/ticket_create.rb +++ b/lib/sessions/backend/ticket_create.rb @@ -58,7 +58,7 @@ class Sessions::Backend::TicketCreate } end - @client.log 'notify', "push ticket_create for user #{ @user.id }" + @client.log "push ticket_create for user #{ @user.id }" @client.send( collection: 'ticket_create_attributes', data: data, diff --git a/lib/sessions/backend/ticket_overview_index.rb b/lib/sessions/backend/ticket_overview_index.rb index aced54e92..87ecd0653 100644 --- a/lib/sessions/backend/ticket_overview_index.rb +++ b/lib/sessions/backend/ticket_overview_index.rb @@ -56,7 +56,7 @@ class Sessions::Backend::TicketOverviewIndex } end - @client.log 'notify', "push overview_index for user #{ @user.id }" + @client.log "push overview_index for user #{ @user.id }" @client.send( event: ['ticket_overview_index'], data: data, diff --git a/lib/sessions/backend/ticket_overview_list.rb b/lib/sessions/backend/ticket_overview_list.rb index 73cd08a0a..56832a72a 100644 --- a/lib/sessions/backend/ticket_overview_list.rb +++ b/lib/sessions/backend/ticket_overview_list.rb @@ -24,13 +24,13 @@ class Sessions::Backend::TicketOverviewList data = { list: overview_data, index: overview } result.push data } - puts "LOG A #{result.inspect}" + Rails.logger.debug "LOG A #{result.inspect}" # no data exists return if !result || result.empty? # no change exists return if @last_change == result - puts "LOG B #{result.inspect}" + Rails.logger.debug "LOG B #{result.inspect}" # remember last state @last_change = result @@ -45,22 +45,22 @@ class Sessions::Backend::TicketOverviewList def push # check interval - puts "LOG 1 #{@user.inspect}" + Rails.logger.debug "LOG 1 #{@user.inspect}" return if Sessions::CacheIn.get( self.client_key ) # reset check interval - puts "LOG 2 #{@ttl.seconds}" + Rails.logger.debug "LOG 2 #{@ttl.seconds}" Sessions::CacheIn.set( self.client_key, true, { expires_in: @ttl.seconds } ) # check if min one ticket has changed last_ticket_change = Ticket.latest_change - puts "LOG 3 #{last_ticket_change}/#{@last_ticket_change}" + Rails.logger.debug "LOG 3 #{last_ticket_change}/#{@last_ticket_change}" return if last_ticket_change == @last_ticket_change @last_ticket_change = last_ticket_change # load current data items = self.load - puts "LOG 4 #{items.inspect}" + Rails.logger.debug "LOG 4 #{items.inspect}" return if !items # push overviews @@ -107,7 +107,7 @@ class Sessions::Backend::TicketOverviewList results.push result else - @client.log 'notify', "push overview_list for user #{ @user.id }" + @client.log "push overview_list for user #{ @user.id }" # send update to browser @client.send( diff --git a/lib/sessions/client.rb b/lib/sessions/client.rb index 80644cca5..8dc2c4cce 100644 --- a/lib/sessions/client.rb +++ b/lib/sessions/client.rb @@ -2,9 +2,9 @@ class Sessions::Client def initialize( client_id ) @client_id = client_id - self.log 'notify', '---client start ws connection---' + self.log '---client start ws connection---' self.fetch - self.log 'notify', '---client exiting ws connection---' + self.log '---client exiting ws connection---' end def fetch @@ -49,14 +49,14 @@ class Sessions::Client end loop_count += 1 - self.log 'notice', "---client - looking for data of user #{user.id}" + self.log "---client - looking for data of user #{user.id}" # push messages from backends backend_pool.each {|pool| pool.push } - self.log 'notice', '---/client-' + self.log '---/client-' # start faster in the beginnig if loop_count < 20 @@ -72,8 +72,7 @@ class Sessions::Client Sessions.send( @client_id, data ) end - def log( level, data ) - return if level == 'notice' - puts "#{Time.now}:client(#{ @client_id }) #{ data }" + def log( msg ) + Rails.logger.info "client(#{ @client_id }) #{ msg }" end end