Merge branch 'feld-Logger' into 'develop'

Logging cleanup

See merge request pleroma/pleroma!76
This commit is contained in:
lambda 2018-03-20 05:57:47 +00:00
commit 9b97b023c5
12 changed files with 22 additions and 22 deletions

View File

@ -417,7 +417,7 @@ def get_or_fetch_by_ap_id(ap_id) do
_ -> _ ->
case OStatus.make_user(ap_id) do case OStatus.make_user(ap_id) do
{:ok, user} -> user {:ok, user} -> user
_ -> {:error, "Could not fetch by ap id"} _ -> {:error, "Could not fetch by AP id"}
end end
end end
end end

View File

@ -301,7 +301,7 @@ def fetch_and_prepare_user_from_ap_id(ap_id) do
{:ok, data} <- Poison.decode(body) do {:ok, data} <- Poison.decode(body) do
user_data_from_user_object(data) user_data_from_user_object(data)
else else
e -> Logger.error("Could not user at fetch #{ap_id}, #{inspect(e)}") e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
end end
end end
@ -321,7 +321,7 @@ def make_user_from_nickname(nickname) do
with {:ok, %{"ap_id" => ap_id}} when not is_nil(ap_id) <- WebFinger.finger(nickname) do with {:ok, %{"ap_id" => ap_id}} when not is_nil(ap_id) <- WebFinger.finger(nickname) do
make_user_from_ap_id(ap_id) make_user_from_ap_id(ap_id)
else else
_e -> {:error, "No ap id in webfinger"} _e -> {:error, "No AP id in WebFinger"}
end end
end end

View File

@ -36,9 +36,9 @@ def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
def inbox(conn, params) do def inbox(conn, params) do
headers = Enum.into(conn.req_headers, %{}) headers = Enum.into(conn.req_headers, %{})
if !(String.contains?(headers["signature"] || "", params["actor"])) do if !(String.contains?(headers["signature"] || "", params["actor"])) do
Logger.info("Signature not from author, relayed message, ignoring.") Logger.info("Signature not from author, relayed message, ignoring")
else else
Logger.info("Signature error.") Logger.info("Signature error")
Logger.info("Could not validate #{params["actor"]}") Logger.info("Could not validate #{params["actor"]}")
Logger.info(inspect(conn.req_headers)) Logger.info(inspect(conn.req_headers))
end end

View File

@ -48,10 +48,10 @@ def handle(:publish, activity) do
with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do
{:ok, actor} = WebFinger.ensure_keys_present(actor) {:ok, actor} = WebFinger.ensure_keys_present(actor)
if ActivityPub.is_public?(activity) do if ActivityPub.is_public?(activity) do
Logger.info(fn -> "Sending #{activity.data["id"]} out via websub" end) Logger.info(fn -> "Sending #{activity.data["id"]} out via WebSub" end)
Websub.publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity) Websub.publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity)
Logger.info(fn -> "Sending #{activity.data["id"]} out via salmon" end) Logger.info(fn -> "Sending #{activity.data["id"]} out via Salmon" end)
Pleroma.Web.Salmon.publish(actor, activity) Pleroma.Web.Salmon.publish(actor, activity)
end end
@ -61,7 +61,7 @@ def handle(:publish, activity) do
end end
def handle(:verify_websub, websub) do def handle(:verify_websub, websub) do
Logger.debug(fn -> "Running websub verification for #{websub.id} (#{websub.topic}, #{websub.callback})" end) Logger.debug(fn -> "Running WebSub verification for #{websub.id} (#{websub.topic}, #{websub.callback})" end)
@websub.verify(websub) @websub.verify(websub)
end end
@ -71,7 +71,7 @@ def handle(:incoming_doc, doc) do
end end
def handle(:incoming_ap_doc, params) do def handle(:incoming_ap_doc, params) do
Logger.info("Handling incoming ap activity") Logger.info("Handling incoming AP activity")
with {:ok, _user} <- ap_enabled_actor(params["actor"]), with {:ok, _user} <- ap_enabled_actor(params["actor"]),
nil <- Activity.get_by_ap_id(params["id"]), nil <- Activity.get_by_ap_id(params["id"]),
{:ok, activity} <- Transmogrifier.handle_incoming(params) do {:ok, activity} <- Transmogrifier.handle_incoming(params) do
@ -105,7 +105,7 @@ def handle(:publish_single_websub, %{xml: xml, topic: topic, callback: callback,
def handle(type, _) do def handle(type, _) do
Logger.debug(fn -> "Unknown task: #{type}" end) Logger.debug(fn -> "Unknown task: #{type}" end)
{:error, "Don't know what do do with this"} {:error, "Don't know what to do with this"}
end end
def enqueue(type, payload, priority \\ 1) do def enqueue(type, payload, priority \\ 1) do

View File

@ -36,7 +36,7 @@ def validate_conn(conn) do
if validate_conn(conn, public_key) do if validate_conn(conn, public_key) do
true true
else else
Logger.debug("Could not validate, re-fetching user and trying one more time.") Logger.debug("Could not validate, re-fetching user and trying one more time")
# Fetch user anew and try one more time # Fetch user anew and try one more time
with actor_id <- conn.params["actor"], with actor_id <- conn.params["actor"],
{:ok, _user} <- ActivityPub.make_user_from_ap_id(actor_id), {:ok, _user} <- ActivityPub.make_user_from_ap_id(actor_id),

View File

@ -40,8 +40,8 @@ def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do
if NaiveDateTime.diff(NaiveDateTime.utc_now, valid_until) < 0 do if NaiveDateTime.diff(NaiveDateTime.utc_now, valid_until) < 0 do
Repo.update(use_changeset(auth, %{used: true})) Repo.update(use_changeset(auth, %{used: true}))
else else
{:error, "token expired"} {:error, "Token expired"}
end end
end end
def use_token(%Authorization{used: true}), do: {:error, "already used"} def use_token(%Authorization{used: true}), do: {:error, "Already used"}
end end

View File

@ -291,8 +291,8 @@ def get_atom_url(body) do
[[_, match]] = Regex.scan(@gs_classic_regex, body) [[_, match]] = Regex.scan(@gs_classic_regex, body)
{:ok, match} {:ok, match}
true -> true ->
Logger.debug(fn -> "Couldn't find atom link in #{inspect(body)}" end) Logger.debug(fn -> "Couldn't find Atom link in #{inspect(body)}" end)
{:error, "Couldn't find the atom link"} {:error, "Couldn't find the Atom link"}
end end
end end

View File

@ -150,7 +150,7 @@ defp send_to_user(%{info: %{"salmon" => salmon}}, feed, poster) do
with {:ok, %{status_code: code}} <- poster.(salmon, feed, [{"Content-Type", "application/magic-envelope+xml"}], timeout: 10000, recv_timeout: 20000, hackney: [pool: :default]) do with {:ok, %{status_code: code}} <- poster.(salmon, feed, [{"Content-Type", "application/magic-envelope+xml"}], timeout: 10000, recv_timeout: 20000, hackney: [pool: :default]) do
Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end) Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end)
else else
e -> Logger.debug(fn -> "Pushing salmon to #{salmon} failed, #{inspect(e)}" end) e -> Logger.debug(fn -> "Pushing Salmon to #{salmon} failed, #{inspect(e)}" end)
end end
end end
@ -178,7 +178,7 @@ def publish(%{info: %{"keys" => keys}} = user, %{data: %{"type" => type}} = acti
remote_users(activity) remote_users(activity)
|> Enum.each(fn(remote_user) -> |> Enum.each(fn(remote_user) ->
Task.start(fn -> Task.start(fn ->
Logger.debug(fn -> "sending salmon to #{remote_user.ap_id}" end) Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end)
send_to_user(remote_user, feed, poster) send_to_user(remote_user, feed, poster)
end) end)
end) end)

View File

@ -100,7 +100,7 @@ def find_lrdd_template(domain) do
with {:ok, %{body: body}} <- @httpoison.get("https://#{domain}/.well-known/host-meta", []) do with {:ok, %{body: body}} <- @httpoison.get("https://#{domain}/.well-known/host-meta", []) do
get_template_from_xml(body) get_template_from_xml(body)
else else
e -> {:error, "Can't find lrdd template: #{inspect(e)}"} e -> {:error, "Can't find LRDD template: #{inspect(e)}"}
end end
end end
end end
@ -122,7 +122,7 @@ def finger(account) do
{:ok, data} {:ok, data}
else else
e -> e ->
Logger.debug(fn -> "Couldn't finger #{account}." end) Logger.debug(fn -> "Couldn't finger #{account}" end)
Logger.debug(fn -> inspect(e) end) Logger.debug(fn -> inspect(e) end)
{:error, e} {:error, e}
end end

View File

@ -98,7 +98,7 @@ def incoming_subscription_request(user, %{"hub.mode" => "subscribe"} = params) d
{:ok, websub} {:ok, websub}
else {:error, reason} -> else {:error, reason} ->
Logger.debug("Couldn't create subscription.") Logger.debug("Couldn't create subscription")
Logger.debug(inspect(reason)) Logger.debug(inspect(reason))
{:error, reason} {:error, reason}

View File

@ -20,7 +20,7 @@ def websub_subscription_request(conn, %{"nickname" => nickname} = params) do
# TODO: Extract this into the Websub module # TODO: Extract this into the Websub module
def websub_subscription_confirmation(conn, %{"id" => id, "hub.mode" => "subscribe", "hub.challenge" => challenge, "hub.topic" => topic} = params) do def websub_subscription_confirmation(conn, %{"id" => id, "hub.mode" => "subscribe", "hub.challenge" => challenge, "hub.topic" => topic} = params) do
Logger.debug("Got websub confirmation") Logger.debug("Got WebSub confirmation")
Logger.debug(inspect(params)) Logger.debug(inspect(params))
lease_seconds = if params["hub.lease_seconds"] do lease_seconds = if params["hub.lease_seconds"] do
String.to_integer(params["hub.lease_seconds"]) String.to_integer(params["hub.lease_seconds"])

View File

@ -21,7 +21,7 @@ def parse_document(text) do
doc doc
catch catch
:exit, _error -> :exit, _error ->
Logger.debug("Couldn't parse xml: #{inspect(text)}") Logger.debug("Couldn't parse XML: #{inspect(text)}")
:error :error
end end
end end