Commit 27b4a44e authored by Benjamin Neff's avatar Benjamin Neff Committed by Dennis Schubert

replace Rails.logger with logging-logger

closes #6041
parent b6c46b3f
......@@ -25,6 +25,7 @@
* Increase post titles length to 50 and use configured pod name as title in the atom feed [#6020](https://github.com/diaspora/diaspora/pull/6020)
* Remove deprecated Facebook permissions [#6019](https://github.com/diaspora/diaspora/pull/6019)
* Make used post title lengths more consistent [#6022](https://github.com/diaspora/diaspora/pull/6022)
* Improved logging source [#6041](https://github.com/diaspora/diaspora/pull/6041)
## Bug fixes
* Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846)
......
......@@ -15,7 +15,8 @@ class MessagesController < ApplicationController
message = current_user.build_message(conversation, opts)
if message.save
Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}")
logger.info "event=create type=comment user=#{current_user.diaspora_handle} status=success " \
"message=#{message.id} chars=#{params[:message][:text].length}"
Postzord::Dispatcher.build(current_user, message).post
else
flash[:error] = I18n.t('conversations.new_conversation.fail')
......
......@@ -15,12 +15,12 @@ class RegistrationsController < Devise::RegistrationsController
flash[:notice] = I18n.t 'registrations.create.success'
@user.seed_aspects
sign_in_and_redirect(:user, @user)
Rails.logger.info("event=registration status=successful user=#{@user.diaspora_handle}")
logger.info "event=registration status=successful user=#{@user.diaspora_handle}"
else
@user.errors.delete(:person)
flash[:error] = @user.errors.full_messages.join(" - ")
Rails.logger.info("event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'")
logger.info "event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'"
render :action => 'new', :layout => 'with_header'
end
end
......
......@@ -32,7 +32,7 @@ class ServicesController < ApplicationController
end
def failure
Rails.logger.info "error in oauth #{params.inspect}"
logger.info "error in oauth #{params.inspect}"
flash[:error] = t('services.failure.error')
redirect_to services_url
end
......
......@@ -53,7 +53,7 @@ module NotificationMailers
" recipient_handle=#{@recipient.diaspora_handle}"
log_string << " sender_handle=#{@sender.diaspora_handle}" if sender_id.present?
logger.info(log_string)
logger.info log_string
end
end
end
......@@ -13,7 +13,7 @@ class Mention < ActiveRecord::Base
after_destroy :delete_notification
def notify_recipient
Rails.logger.info "event=mention_sent id=#{self.id} to=#{person.diaspora_handle} from=#{post.author.diaspora_handle}"
logger.info "event=mention_sent id=#{id} to=#{person.diaspora_handle} from=#{post.author.diaspora_handle}"
Notification.notify(person.owner, self, post.author) unless person.remote?
end
......
......@@ -261,7 +261,8 @@ class Person < ActiveRecord::Base
new_person.url = profile.seed_location
#hcard_profile = HCard.find profile.hcard.first[:href]
Rails.logger.info("event=webfinger_marshal valid=#{new_person.valid?} target=#{new_person.diaspora_handle}")
::Logging::Logger[self].info "event=webfinger_marshal valid=#{new_person.valid?} " \
"target=#{new_person.diaspora_handle}"
new_person.url = hcard[:url]
new_person.assign_new_profile_from_hcard(hcard)
new_person.save!
......
......@@ -56,7 +56,7 @@ class Profile < ActiveRecord::Base
def receive(user, person)
person.reload # make sure to have old profile referenced
Rails.logger.info("event=receive payload_type=profile sender=#{person} to=#{user}")
logger.info "event=receive payload_type=profile sender=#{person.diaspora_handle} to=#{user.diaspora_handle}"
profiles_attr = self.attributes.merge('tag_string' => self.tag_string).slice('diaspora_handle', 'first_name', 'last_name', 'image_url', 'image_url_small', 'image_url_medium', 'birthday', 'gender', 'bio', 'location', 'searchable', 'nsfw', 'tag_string')
person.profile.update_attributes(profiles_attr)
......
......@@ -9,7 +9,7 @@ class Services::Facebook < Service
end
def post(post, url='')
Rails.logger.debug("event=post_to_service type=facebook sender_id=#{self.user_id}")
logger.debug "event=post_to_service type=facebook sender_id=#{user_id} post=#{post.guid}"
response = post_to_facebook("https://graph.facebook.com/me/feed", create_post_params(post).to_param)
response = JSON.parse response.body
post.facebook_id = response["id"]
......@@ -39,7 +39,7 @@ class Services::Facebook < Service
def delete_post(post)
if post.present? && post.facebook_id.present?
Rails.logger.debug("event=delete_from_service type=facebook sender_id=#{self.user_id}")
logger.debug "event=delete_from_service type=facebook sender_id=#{user_id} post=#{post.guid}"
delete_from_facebook("https://graph.facebook.com/#{post.facebook_id}/", {:access_token => self.access_token})
end
end
......
......@@ -43,7 +43,7 @@ class Services::Tumblr < Service
def delete_post(post)
if post.present? && post.tumblr_ids.present?
Rails.logger.debug("event=delete_from_service type=tumblr sender_id=#{self.user_id}")
logger.debug "event=delete_from_service type=tumblr sender_id=#{user_id} post=#{post.guid}"
tumblr_posts = JSON.parse(post.tumblr_ids)
tumblr_posts.each do |blog_name,post_id|
delete_from_tumblr(blog_name, post_id)
......
......@@ -10,7 +10,7 @@ class Services::Twitter < Service
end
def post post, url=''
Rails.logger.debug "event=post_to_service type=twitter sender_id=#{self.user_id}"
logger.debug "event=post_to_service type=twitter sender_id=#{user_id} post=#{post.guid}"
tweet = attempt_post post
post.tweet_id = tweet.id
post.save
......@@ -22,7 +22,7 @@ class Services::Twitter < Service
def delete_post post
if post.present? && post.tweet_id.present?
Rails.logger.debug "event=delete_from_service type=twitter sender_id=#{self.user_id}"
logger.debug "event=delete_from_service type=twitter sender_id=#{user_id} post=#{post.guid}"
delete_from_twitter post.tweet_id
end
end
......
......@@ -53,7 +53,7 @@ module User::Connecting
def disconnect(bad_contact, opts={})
person = bad_contact.person
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}")
logger.info "event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}"
retraction = Retraction.for(self)
retraction.subscribers = [person]#HAX
Postzord::Dispatcher.build(self, retraction).post
......@@ -63,7 +63,7 @@ module User::Connecting
end
def disconnected_by(person)
Rails.logger.info("event=disconnected_by user=#{diaspora_handle} target=#{person.diaspora_handle}")
logger.info "event=disconnected_by user=#{diaspora_handle} target=#{person.diaspora_handle}"
if contact = self.contact_for(person)
remove_contact(contact, :retracted => true)
end
......
......@@ -68,7 +68,7 @@ module User::Querying
end
def construct_public_followings_sql(opts)
Rails.logger.debug("[EVIL-QUERY] user.construct_public_followings_sql")
logger.debug "[EVIL-QUERY] user.construct_public_followings_sql"
# For PostgreSQL and MySQL/MariaDB we use a different query
# see issue: https://github.com/diaspora/diaspora/issues/5014
......
module Diaspora
module Encryptable
include Diaspora::Logging
# Check that signature is a correct signature of #signable_string by person
#
# @param [String] signature The signature to be verified.
......@@ -7,19 +9,17 @@ module Diaspora
# @return [Boolean]
def verify_signature(signature, person)
if person.nil?
Rails.logger.info("event=verify_signature status=abort reason=no_person guid=#{self.guid}")
logger.warn "event=verify_signature status=abort reason=no_person guid=#{guid}"
return false
elsif person.public_key.nil?
Rails.logger.info("event=verify_signature status=abort reason=no_key guid=#{self.guid}")
logger.warn "event=verify_signature status=abort reason=no_key guid=#{guid}"
return false
elsif signature.nil?
Rails.logger.info("event=verify_signature status=abort reason=no_signature guid=#{self.guid}")
logger.warn "event=verify_signature status=abort reason=no_signature guid=#{guid}"
return false
end
log_string = "event=verify_signature status=complete guid=#{self.guid}"
validity = person.public_key.verify OpenSSL::Digest::SHA256.new, Base64.decode64(signature), signable_string
log_string += " validity=#{validity}"
Rails.logger.info(log_string)
logger.info "event=verify_signature status=complete guid=#{guid} validity=#{validity}"
validity
end
......@@ -27,9 +27,7 @@ module Diaspora
# @return [String] A Base64 encoded signature of #signable_string with key
def sign_with_key(key)
sig = Base64.strict_encode64(key.sign( OpenSSL::Digest::SHA256.new, signable_string ))
log_hash = {:event => :sign_with_key, :status => :complete}
log_hash.merge(:model_id => self.id) if self.respond_to?(:persisted?)
Rails.logger.info(log_hash)
logger.info "event=sign_with_key status=complete guid=#{guid}"
sig
end
......
......@@ -11,7 +11,9 @@
module Diaspora
module Federated
module Base
module Base
include Diaspora::Logging
def self.included(model)
model.instance_eval do
include ROXML
......
......@@ -30,17 +30,18 @@ class RelayableRetraction < SignedRetraction
end
def perform receiving_user
Rails.logger.debug "Performing relayable retraction for #{target_guid}"
logger.debug "Performing relayable retraction for #{target_guid}"
if not self.parent_author_signature.nil? or self.parent.author.remote?
# Don't destroy a relayable unless the top-level owner has received it, otherwise it may not get relayed
self.target.destroy
Rails.logger.info("event=relayable_retraction status =complete target_type=#{self.target_type} guid =#{self.target_guid}")
logger.info "event=relayable_retraction status=complete target_type=#{target_type} guid=#{target_guid}"
end
end
def receive(recipient, sender)
if self.target.nil?
Rails.logger.info("event=retraction status=abort reason='no post found' sender=#{sender.diaspora_handle} target_guid=#{target_guid}")
logger.warn "event=retraction status=abort reason='no post found' sender=#{sender.diaspora_handle} " \
"target_guid=#{target_guid}"
return
elsif self.parent.author == recipient.person && self.target_author_signature_valid?
#this is a retraction from the downstream object creator, and the recipient is the upstream owner
......@@ -51,7 +52,9 @@ class RelayableRetraction < SignedRetraction
#this is a retraction from the upstream owner
self.perform(recipient)
else
Rails.logger.info("event=receive status=abort reason='object signature not valid' recipient=#{recipient.diaspora_handle} sender=#{self.parent.author.diaspora_handle} payload_type=#{self.class} parent_id=#{self.parent.id}")
logger.warn "event=receive status=abort reason='object signature not valid' " \
"recipient=#{recipient.diaspora_handle} sender=#{parent.author.diaspora_handle} " \
"payload_type=#{self.class} parent_id=#{parent.id}"
return
end
self
......
......@@ -73,7 +73,7 @@ class Request
# @note A [Contact] may already exist if the [Request]'s recipient is sharing with the sender
# @return [Request]
def receive(user, person)
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
logger.info("event=receive payload_type=request sender=#{sender} to=#{recipient}")
contact = user.contacts.find_or_initialize_by(person_id: self.sender.id)
contact.sharing = true
......
......@@ -40,24 +40,27 @@ class Retraction
end
def perform receiving_user
Rails.logger.debug "Performing retraction for #{post_guid}"
logger.debug "Performing retraction for #{post_guid}"
self.target.destroy if self.target
Rails.logger.info("event=retraction status=complete type=#{self.type} guid=#{self.post_guid}")
logger.info "event=retraction status=complete type=#{type} guid=#{post_guid}"
end
def receive(user, person)
if self.type == 'Person'
unless self.person.guid.to_s == self.post_guid.to_s
Rails.logger.info("event=receive status=abort reason='sender is not the person he is trying to retract' recipient=#{self.diaspora_handle} sender=#{self.person.diaspora_handle} payload_type=#{self.class} retraction_type=person")
logger.warn "event=receive status=abort reason='sender is not the person he is trying to retract' " \
"recipient=#{diaspora_handle} sender=#{self.person.diaspora_handle} " \
"payload_type=#{self.class} retraction_type=person"
return
end
user.disconnected_by(self.target)
elsif self.target.nil? || self.target.author != self.person
Rails.logger.info("event=retraction status=abort reason='no post found authored by retractor' sender=#{person.diaspora_handle} post_guid=#{post_guid}")
logger.warn "event=retraction status=abort reason='no post found authored by retractor' " \
"sender=#{person.diaspora_handle} post_guid=#{post_guid}"
else
self.perform(user)
end
self
end
end
\ No newline at end of file
end
......@@ -24,6 +24,7 @@ module Diaspora
end
module InstanceMethods
include Diaspora::Logging
def diaspora_handle
read_attribute(:diaspora_handle) || self.author.diaspora_handle
end
......@@ -52,7 +53,8 @@ module Diaspora
self.receive_non_persisted(user, person)
else
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason='update not from shareable owner' existing_shareable=#{self.id}")
logger.warn "event=receive payload_type=#{self.class} update=true status=abort " \
"sender=#{diaspora_handle} reason='update not from shareable owner' existing_shareable=#{id}"
false
end
end
......@@ -88,13 +90,15 @@ module Diaspora
known_shareable.update_attributes(self.attributes.except("id"))
true
else
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason=immutable") #existing_shareable=#{known_shareable.id}")
logger.warn "event=receive payload_type=#{self.class} update=true status=abort " \
"sender=#{diaspora_handle} reason=immutable existing_shareable=#{known_shareable.id}"
false
end
else
user.contact_for(person).receive_shareable(local_shareable)
user.notify_if_mentioned(local_shareable)
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=complete sender=#{self.diaspora_handle}") #existing_shareable=#{local_shareable.id}")
logger.info "event=receive payload_type=#{self.class} update=true status=complete " \
"sender=#{diaspora_handle} existing_shareable=#{local_shareable.id}"
true
end
end
......@@ -103,10 +107,12 @@ module Diaspora
if self.save
user.contact_for(person).receive_shareable(self)
user.notify_if_mentioned(self)
Rails.logger.info("event=receive payload_type=#{self.class} update=false status=complete sender=#{self.diaspora_handle}")
logger.info "event=receive payload_type=#{self.class} update=false status=complete " \
"sender=#{diaspora_handle}"
true
else
Rails.logger.info("event=receive payload_type=#{self.class} update=false status=abort sender=#{self.diaspora_handle} reason=#{self.errors.full_messages}")
logger.warn "event=receive payload_type=#{self.class} update=false status=abort " \
"sender=#{diaspora_handle} reason=#{errors.full_messages}"
false
end
end
......
......@@ -72,7 +72,7 @@ class SignedRetraction
end
def perform receiving_user
Rails.logger.debug "Performing retraction for #{target_guid}"
logger.debug "Performing retraction for #{target_guid}"
if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_guid => target_guid).first
onward_retraction = self.dup
onward_retraction.sender = receiving_user.person
......@@ -81,18 +81,20 @@ class SignedRetraction
if target && !target.destroyed?
self.target.destroy
end
Rails.logger.info("event=retraction status =complete target_type=#{self.target_type} guid =#{self.target_guid}")
logger.info "event=retraction status=complete target_type=#{target_type} guid=#{target_guid}"
end
def receive(recipient, sender)
if self.target.nil?
Rails.logger.info("event=retraction status=abort reason='no post found' sender=#{sender.diaspora_handle} target_guid=#{target_guid}")
logger.warn "event=retraction status=abort reason='no post found' sender=#{sender.diaspora_handle} " \
"target_guid=#{target_guid}"
return
elsif self.target_author_signature_valid?
#this is a retraction from the upstream owner
self.perform(recipient)
else
Rails.logger.info("event=receive status=abort reason='object signature not valid' recipient=#{recipient.diaspora_handle} sender=#{self.sender_handle} payload_type=#{self.class}")
logger.warn "event=receive status=abort reason='object signature not valid' " \
"recipient=#{recipient.diaspora_handle} sender=#{sender_handle} payload_type=#{self.class}"
return
end
self
......
......@@ -159,7 +159,9 @@ module Diaspora; module Fetcher; class Public
guid = post['author']['guid']
equal = (guid == @person.guid)
logger.warn "the author (#{guid}) does not match the person currently being processed (#{@person.guid})" unless equal
unless equal
logger.warn "the author (#{guid}) does not match the person currently being processed (#{@person.guid})"
end
equal
end
......
......@@ -71,7 +71,8 @@ module Diaspora
# Check to make sure the signature of the comment or like comes from the person claiming to author it
unless comment_or_like.parent_author == user.person || comment_or_like.verify_parent_author_signature
Rails.logger.info("event=receive status=abort reason='object signature not valid' recipient=#{user.diaspora_handle} sender=#{self.parent.author.diaspora_handle} payload_type=#{self.class} parent_id=#{self.parent.id}")
logger.warn "event=receive status=abort reason='object signature not valid' recipient=#{user.diaspora_handle} "\
"sender=#{parent.author.diaspora_handle} payload_type=#{self.class} parent_id=#{parent.id}"
return
end
......
module EvilQuery
class Base
include Diaspora::Logging
def fetch_ids!(relation, id_column)
#the relation should be ordered and limited by here
@class.connection.select_values(id_sql(relation, id_column))
......@@ -51,24 +53,24 @@ module EvilQuery
end
def make_relation!
Rails.logger.debug("[EVIL-QUERY] make_relation!")
logger.debug("[EVIL-QUERY] make_relation!")
post_ids = aspects_post_ids! + ids!(followed_tags_posts!) + ids!(mentioned_posts)
post_ids += ids!(community_spotlight_posts!) if @include_spotlight
Post.where(:id => post_ids)
end
def aspects_post_ids!
Rails.logger.debug("[EVIL-QUERY] aspect_post_ids!")
logger.debug("[EVIL-QUERY] aspect_post_ids!")
@user.visible_shareable_ids(Post, :limit => 15, :order => "#{@order} DESC", :max_time => @max_time, :all_aspects? => true, :by_members_of => @user.aspect_ids)
end
def followed_tags_posts!
Rails.logger.debug("[EVIL-QUERY] followed_tags_posts!")
logger.debug("[EVIL-QUERY] followed_tags_posts!")
StatusMessage.public_tag_stream(@user.followed_tag_ids)
end
def mentioned_posts
Rails.logger.debug("[EVIL-QUERY] mentioned_posts")
logger.debug("[EVIL-QUERY] mentioned_posts")
StatusMessage.where_person_is_mentioned(@user.person)
end
......
......@@ -3,6 +3,7 @@
# the COPYRIGHT file.
class HydraWrapper
include Diaspora::Logging
OPTS = {
maxredirs: 3,
......@@ -90,13 +91,8 @@ class HydraWrapper
end
unless response.success?
message = {
event: "http_multi_fail",
sender_id: @user.id,
url: response.effective_url,
return_code: response.return_code
}
Rails.logger.info message.to_a.map { |k,v| "#{k}=#{v}" }.join(' ')
logger.warn "event=http_multi_fail sender_id=#{@user.id} url=#{response.effective_url} " \
"return_code=#{response.return_code} response_code=#{response.response_code}"
if @keep_for_retry_proc.call(response)
@people_to_retry += people_for_receive_url.map(&:id)
......
......@@ -4,6 +4,8 @@
class Postzord::Dispatcher
include Diaspora::Logging
require 'postzord/dispatcher/private'
require 'postzord/dispatcher/public'
......@@ -124,7 +126,8 @@ class Postzord::Dispatcher
batch_deliver_to_local(people)
else
people.each do |person|
Rails.logger.info("event=push route=local sender=#{@sender.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{@object.class}")
logger.info "event=push route=local sender=#{@sender.diaspora_handle} recipient=#{person.diaspora_handle} " \
"payload_type=#{@object.class}"
Workers::Receive.perform_async(person.owner_id, @xml, @sender.person_id)
end
end
......@@ -134,11 +137,12 @@ class Postzord::Dispatcher
def batch_deliver_to_local(people)
ids = people.map{ |p| p.owner_id }
Workers::ReceiveLocalBatch.perform_async(@object.class.to_s, @object.id, ids)
Rails.logger.info("event=push route=local sender=#{@sender.diaspora_handle} recipients=#{ids.join(',')} payload_type=#{@object.class}")
logger.info "event=push route=local sender=#{@sender.diaspora_handle} recipients=#{ids.join(',')} " \
"payload_type=#{@object.class}"
end
def deliver_to_hub
Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{@sender.diaspora_handle}")
logger.debug "event=post_to_service type=pubsub sender_handle=#{@sender.diaspora_handle}"
Workers::PublishToHub.perform_async(@sender.public_url)
end
......
......@@ -16,7 +16,7 @@ class Postzord::Receiver
def author_does_not_match_xml_author?
if (@author.diaspora_handle != xml_author)
logger.info "event=receive status=abort reason='author in xml does not match retrieved person' " \
logger.warn "event=receive status=abort reason='author in xml does not match retrieved person' " \
"payload_type=#{@object.class} sender=#{@author.diaspora_handle}"
return true
end
......
......@@ -44,7 +44,8 @@ class Postzord::Receiver::Private < Postzord::Receiver
def receive_object
obj = @object.receive(@user, @author)
Notification.notify(@user, obj, @author) if obj.respond_to?(:notification_type)
logger.info "user:#{@user.id} successfully received #{@object.class} from person #{@sender.guid}: #{@object.inspect}"
logger.info "user:#{@user.id} successfully received #{@object.class} from person #{@sender.guid}: " \
"#{@object.inspect}"
obj
end
......
......@@ -4,6 +4,7 @@
module Salmon
class EncryptedSlap < Slap
include Diaspora::Logging
# Construct an encrypted header
# @return [String] Header XML
......@@ -28,13 +29,13 @@ HEADER
# @return [String, Boolean] False if RSAError; XML if no error
def xml_for(person)
begin
super
super
rescue OpenSSL::PKey::RSAError => e
Rails.logger.info("event => :invalid_rsa_key, :identifier => #{person.diaspora_handle}")
logger.error "event=invalid_rsa_key identifier=#{person.diaspora_handle}"
false
end
end
# Takes in a doc of the header and sets the author id
# returns an empty hash
# @return [Hash]
......@@ -43,7 +44,7 @@ HEADER
self.aes_key = doc.search('aes_key').text
self.iv = doc.search('iv').text
end
# Decrypts an encrypted magic sig envelope
# @param key_hash [Hash] Contains 'key' (aes) and 'iv' values
# @param user [User]
......
class WebfingerProfile
include Diaspora::Logging
attr_accessor :webfinger_profile, :account, :links, :hcard, :guid, :public_key, :seed_location
def initialize(account, webfinger_profile)
......@@ -20,7 +22,7 @@ class WebfingerProfile
doc.remove_namespaces!
account_string = doc.css('Subject').text.gsub('acct:', '').strip
raise "account in profile(#{account_string}) and account requested (#{@account}) do not match" if account_string != @account
doc.css('Link').each do |l|
......@@ -41,7 +43,7 @@ class WebfingerProfile
pubkey = text_of_attribute( doc.at('Link[rel=diaspora-public-key]'), 'href')
@public_key = Base64.decode64 pubkey
rescue => e
Rails.logger.info("event => :invalid_profile, :identifier => #{@account}")
logger.warn "event=invalid_profile identifier=#{@account}"
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment