From 605f30349ea38dc0971577a242d79e54b7e8c39a Mon Sep 17 00:00:00 2001 From: Gonzalo <456459+grzuy@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:12:25 -0300 Subject: [PATCH] doc: typespecs --- lib/tower.ex | 10 ++++++++++ lib/tower/event.ex | 8 ++++++++ lib/tower/logger_handler.ex | 2 ++ 3 files changed, 20 insertions(+) diff --git a/lib/tower.ex b/lib/tower.ex index 4758a61..0dbd221 100644 --- a/lib/tower.ex +++ b/lib/tower.ex @@ -7,30 +7,40 @@ defmodule Tower do @default_reporters [Tower.EphemeralReporter] + @spec attach() :: :ok def attach do :ok = Tower.LoggerHandler.attach() end + @spec detach() :: :ok def detach do :ok = Tower.LoggerHandler.detach() end + @spec handle_exception(Exception.t(), Exception.stacktrace()) :: :ok + @spec handle_exception(Exception.t(), Exception.stacktrace(), Keyword.t()) :: :ok def handle_exception(exception, stacktrace, options \\ []) when is_exception(exception) and is_list(stacktrace) do Event.from_exception(exception, stacktrace, options) |> report_event() end + @spec handle_throw(term(), Exception.stacktrace()) :: :ok + @spec handle_throw(term(), Exception.stacktrace(), Keyword.t()) :: :ok def handle_throw(reason, stacktrace, options \\ []) do Event.from_throw(reason, stacktrace, options) |> report_event() end + @spec handle_exit(term(), Exception.stacktrace()) :: :ok + @spec handle_exit(term(), Exception.stacktrace(), Keyword.t()) :: :ok def handle_exit(reason, stacktrace, options \\ []) do Event.from_exit(reason, stacktrace, options) |> report_event() end + @spec handle_message(:logger.level(), term()) :: :ok + @spec handle_message(:logger.level(), term(), Keyword.t()) :: :ok def handle_message(level, message, options \\ []) do Event.from_message(level, message, options) |> report_event() diff --git a/lib/tower/event.ex b/lib/tower/event.ex index d19ff3d..34376af 100644 --- a/lib/tower/event.ex +++ b/lib/tower/event.ex @@ -12,6 +12,8 @@ defmodule Tower.Event do metadata: metadata() } + @spec from_exception(Exception.t(), Exception.stacktrace()) :: t() + @spec from_exception(Exception.t(), Exception.stacktrace(), Keyword.t()) :: t() def from_exception(exception, stacktrace, options \\ []) do log_event = Keyword.get(options, :log_event) @@ -27,6 +29,8 @@ defmodule Tower.Event do } end + @spec from_exit(term(), Exception.stacktrace()) :: t() + @spec from_exit(term(), Exception.stacktrace(), Keyword.t()) :: t() def from_exit(reason, stacktrace, options \\ []) do log_event = Keyword.get(options, :log_event) @@ -42,6 +46,8 @@ defmodule Tower.Event do } end + @spec from_throw(term(), Exception.stacktrace()) :: t() + @spec from_throw(term(), Exception.stacktrace(), Keyword.t()) :: t() def from_throw(reason, stacktrace, options \\ []) do log_event = Keyword.get(options, :log_event) @@ -57,6 +63,8 @@ defmodule Tower.Event do } end + @spec from_message(:logger.level(), term()) :: t() + @spec from_message(:logger.level(), term(), Keyword.t()) :: t() def from_message(level, message, options \\ []) do log_event = Keyword.get(options, :log_event) diff --git a/lib/tower/logger_handler.ex b/lib/tower/logger_handler.ex index 2824b72..be38bd0 100644 --- a/lib/tower/logger_handler.ex +++ b/lib/tower/logger_handler.ex @@ -2,10 +2,12 @@ defmodule Tower.LoggerHandler do @default_log_level :critical @handler_id Tower + @spec attach() :: :ok | {:error, term()} def attach do :logger.add_handler(@handler_id, __MODULE__, %{level: :all}) end + @spec detach() :: :ok | {:error, term()} def detach do :logger.remove_handler(@handler_id) end