Current section

22 Versions

Jump to

Compare versions

15 files changed
+255 additions
-100 deletions
  @@ -1,6 +1,6 @@
1 1 {<<"links">>,[{<<"Github">>,<<"https://github.com/mrdotb/disco-log">>}]}.
2 2 {<<"name">>,<<"disco_log">>}.
3 - {<<"version">>,<<"2.0.0-rc.0">>}.
3 + {<<"version">>,<<"2.0.0-rc.1">>}.
4 4 {<<"description">>,
5 5 <<"Use Discord as a logging service and error tracking solution">>}.
6 6 {<<"elixir">>,<<"~> 1.17">>}.
  @@ -1,6 +1,12 @@
1 1 defmodule DiscoLog do
2 2 @moduledoc """
3 - Elixir-based built-in error tracking solution.
3 + Send messages to Discord
4 +
5 + All functions in this module accept optional `context` and `config` parameters.
6 + * `context` is the last opportunity to assign some metadata that will be
7 + attached to the message or occurrence. Occurrences will additionally be tagged
8 + if context key names match existing channel tags.
9 + * `config` is important if you're running [advanced configuration](advanced-configuration.md)
4 10 """
5 11 alias DiscoLog.Error
6 12 alias DiscoLog.Config
  @@ -9,6 +15,19 @@ defmodule DiscoLog do
9 15 alias DiscoLog.Discord.API
10 16 alias DiscoLog.Discord.Prepare
11 17
18 + @doc """
19 + Report catched error to occurrences channel
20 +
21 + This function reports an error directly to the occurrences channel, bypassing logging.
22 +
23 + Example:
24 +
25 + try do
26 + raise "Unexpected!"
27 + catch
28 + kind, reason -> DiscoLog.report(kind, reason, __STACKTRACE__)
29 + end
30 + """
12 31 @spec report(Exception.kind(), any(), Exception.stacktrace(), Context.t(), Config.t() | nil) ::
13 32 API.response()
14 33 def report(kind, reason, stacktrace, context \\ %{}, config \\ nil) do
  @@ -30,6 +49,7 @@ defmodule DiscoLog do
30 49 applied_tags =
31 50 context
32 51 |> Map.keys()
52 + |> Enum.map(&to_string/1)
33 53 |> Enum.filter(&(&1 in Map.keys(available_tags)))
34 54 |> Enum.map(&Map.fetch!(available_tags, &1))
35 55
  @@ -49,6 +69,9 @@ defmodule DiscoLog do
49 69 end
50 70 end
51 71
72 + @doc """
73 + Sends text message to the channel configured as `info_channel_id`
74 + """
52 75 @spec log_info(String.t(), Context.t(), Config.t() | nil) :: API.response()
53 76 def log_info(message, context \\ %{}, config \\ nil) do
54 77 config = maybe_read_config(config)
  @@ -57,6 +80,9 @@ defmodule DiscoLog do
57 80 API.post_message(config.discord_client, config.info_channel_id, message)
58 81 end
59 82
83 + @doc """
84 + Sends text message to the channel configures as `error_channel_id`
85 + """
60 86 @spec log_error(String.t(), Context.t(), Config.t() | nil) :: API.response()
61 87 def log_error(message, context \\ %{}, config \\ nil) do
62 88 config = maybe_read_config(config)
  @@ -67,7 +67,7 @@ defmodule DiscoLog.Config do
67 67 ],
68 68 excluded_domains: [
69 69 type: {:list, :atom},
70 - default: [:cowboy],
70 + default: [],
71 71 doc: "Logs with domains from this list will be ignored"
72 72 ],
73 73 discord_client_module: [
  @@ -118,7 +118,33 @@ defmodule DiscoLog.Config do
118 118 #{NimbleOptions.docs(@compiled_schema)}
119 119 """
120 120
121 - @type t() :: map()
121 + @type t() :: %{
122 + otp_app: atom(),
123 + token: String.t(),
124 + guild_id: String.t(),
125 + category_id: String.t(),
126 + occurrences_channel_id: String.t(),
127 + info_channel_id: String.t(),
128 + error_channel_id: String.t(),
129 + enable: boolean(),
130 + enable_logger: boolean(),
131 + enable_discord_log: boolean(),
132 + enable_presence: boolean(),
133 + instrument_oban: boolean(),
134 + metadata: [atom()],
135 + excluded_domains: [atom()],
136 + discord_client_module: module(),
137 + supervisor_name: supervisor_name(),
138 + presence_status: String.t(),
139 + enable_go_to_repo: boolean(),
140 + go_to_repo_top_modules: [module()],
141 + repo_url: String.t(),
142 + git_sha: String.t(),
143 + discord_client: DiscoLog.Discord.API.t(),
144 + in_app_modules: [module()]
145 + }
146 +
147 + @type supervisor_name() :: atom()
122 148
123 149 @doc """
124 150 Reads and validates config from global application configuration
  @@ -1,7 +1,7 @@
1 1 defmodule DiscoLog.Context do
2 2 @moduledoc """
3 3 Context is a map of any terms that DiscoLog attaches to reported occurrences.
4 - The context is stored in `Logger` module metadata.
4 + The context is stored in [logger metadata](`m:Logger#module-metadata`).
5 5
6 6 > #### Using context {: .tip}
7 7 >
  @@ -18,8 +18,9 @@ defmodule DiscoLog.Discord.API do
18 18 """
19 19 @type client() :: any()
20 20 @type response() :: {:ok, %{status: non_neg_integer(), body: any()}} | {:error, Exception.t()}
21 + @type t() :: %__MODULE__{client: client(), module: atom()}
21 22
22 - @callback client(token :: String.t()) :: %__MODULE__{client: client(), module: atom()}
23 + @callback client(token :: String.t()) :: t()
23 24 @callback request(client :: client(), method :: atom(), url :: String.t(), opts :: keyword()) ::
24 25 response()
Loading more files…