-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This module exposes functions to log messages by severity through the extension Logging API
- v2.13.3
- v2.13.2
- v2.13.1
- v2.13.0
- v2.12.3
- v2.12.2
- v2.12.1
- v2.12.0
- v2.11.0
- v2.10.2
- v2.10.1
- v2.10.0
- v2.9.2
- v2.9.1
- v2.9.0
- v2.8.3
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.13
- v2.7.12
- v2.7.11
- v2.7.10
- v2.7.9
- v2.7.8
- v2.7.7
- v2.7.6
- v2.7.5
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.1
- v2.6.0
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
1 parent
cb143d7
commit cd7359c
Showing
6 changed files
with
160 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
defmodule Appsignal.Logger do | ||
require Appsignal.Utils | ||
|
||
@nif Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer_nif, Appsignal.Nif) | ||
@severity %{ | ||
trace: 1, | ||
debug: 2, | ||
info: 3, | ||
warn: 5, | ||
error: 6 | ||
} | ||
|
||
@type log_level :: :trace | :debug | :info | :warn | :error | ||
|
||
@spec trace(String.t(), String.t(), %{}) :: :ok | ||
def trace(group, message, metadata \\ %{}) do | ||
log(:trace, group, message, metadata) | ||
end | ||
|
||
@spec debug(String.t(), String.t(), %{}) :: :ok | ||
def debug(group, message, metadata \\ %{}) do | ||
log(:debug, group, message, metadata) | ||
end | ||
|
||
@spec info(String.t(), String.t(), %{}) :: :ok | ||
def info(group, message, metadata \\ %{}) do | ||
log(:info, group, message, metadata) | ||
end | ||
|
||
@spec warn(String.t(), String.t(), %{}) :: :ok | ||
def warn(group, message, metadata \\ %{}) do | ||
log(:warn, group, message, metadata) | ||
end | ||
|
||
@spec error(String.t(), String.t(), %{}) :: :ok | ||
def error(group, message, metadata \\ %{}) do | ||
log(:error, group, message, metadata) | ||
end | ||
|
||
@spec log(log_level(), String.t(), String.t(), %{}) :: :ok | ||
defp log(log_level, group, message, metadata) do | ||
severity = @severity[log_level] | ||
encoded_metadata = Appsignal.Utils.DataEncoder.encode(metadata) | ||
|
||
@nif.log( | ||
group, | ||
severity, | ||
message, | ||
encoded_metadata | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule Appsignal.LoggerTest do | ||
use ExUnit.Case | ||
alias Appsignal.{Logger, Test} | ||
|
||
setup do | ||
start_supervised(Test.Nif) | ||
:ok | ||
end | ||
|
||
test "trace/3 sends the trace log call through the extension" do | ||
metadata = %{some: "metadata"} | ||
|
||
Logger.trace("app", "This is a trace", metadata) | ||
|
||
assert [{"app", 1, "This is a trace", _encoded_metadata}] = Test.Nif.get!(:log) | ||
end | ||
|
||
test "debug/3 sends the debug log call through the extension" do | ||
metadata = %{some: "metadata"} | ||
|
||
Logger.debug("app", "This is a debug", metadata) | ||
|
||
assert [{"app", 2, "This is a debug", _encoded_metadata}] = Test.Nif.get!(:log) | ||
end | ||
|
||
test "info/3 sends the info call through the extension" do | ||
metadata = %{some: "metadata"} | ||
|
||
Logger.info("app", "This is an info", metadata) | ||
|
||
assert [{"app", 3, "This is an info", _encoded_metadata}] = Test.Nif.get!(:log) | ||
end | ||
|
||
test "warn/3 sends the warn log call through the extension" do | ||
metadata = %{some: "metadata"} | ||
|
||
Logger.warn("app", "This is a warn", metadata) | ||
|
||
assert [{"app", 5, "This is a warn", _encoded_metadata}] = Test.Nif.get!(:log) | ||
end | ||
|
||
test "error/3 sends the error log call through the extension" do | ||
metadata = %{some: "metadata"} | ||
|
||
Logger.error("app", "This is an error", metadata) | ||
|
||
assert [{"app", 6, "This is an error", _encoded_metadata}] = Test.Nif.get!(:log) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters