Skip to content

Commit

Permalink
doc: typespecs
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Jul 31, 2024
1 parent a5d2946 commit 605f303
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/tower.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions lib/tower/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -57,6 +63,8 @@ defmodule Tower.Event do
}
end

@spec from_message(:logger.level(), term()) :: t()

Check warning on line 66 in lib/tower/event.ex

View workflow job for this annotation

GitHub Actions / main (1.17, 27.0, true)

invalid_contract

Invalid type specification for function from_message.
@spec from_message(:logger.level(), term(), Keyword.t()) :: t()

Check warning on line 67 in lib/tower/event.ex

View workflow job for this annotation

GitHub Actions / main (1.17, 27.0, true)

invalid_contract

Invalid type specification for function from_message.
def from_message(level, message, options \\ []) do
log_event = Keyword.get(options, :log_event)

Expand Down
2 changes: 2 additions & 0 deletions lib/tower/logger_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 605f303

Please sign in to comment.