Skip to content

Commit 88b4adf

Browse files
authored
Add filename and line number in DatadogLogger formatter (#85)
1 parent f8e49f3 commit 88b4adf

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/logger_json/formatters/datadog_logger.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ defmodule LoggerJSON.Formatters.DatadogLogger do
1919
logger:
2020
json_map(
2121
thread_name: inspect(Keyword.get(md, :pid)),
22-
method_name: method_name(md)
22+
method_name: method_name(md),
23+
file_name: Keyword.get(md, :file),
24+
line: Keyword.get(md, :line)
2325
),
2426
message: IO.chardata_to_string(msg),
2527
syslog:

test/unit/logger_json_datadog_test.exs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,20 +249,27 @@ defmodule LoggerJSONDatadogTest do
249249
end
250250

251251
test "contains source location" do
252-
%{module: mod, function: {name, arity}, file: _file, line: _line} = __ENV__
252+
%{module: mod, function: {name, arity}, file: file, line: before_log_line_num} = __ENV__
253253

254254
log =
255255
fn -> Logger.debug("hello") end
256256
|> capture_log()
257257
|> Jason.decode!()
258258

259+
%{line: after_log_line_num} = __ENV__
260+
259261
function = "Elixir.#{inspect(mod)}.#{name}/#{arity}"
260262

261263
assert %{
262264
"logger" => %{
263-
"method_name" => ^function
265+
"method_name" => ^function,
266+
"line" => log_line_num,
267+
"file_name" => ^file,
268+
"thread_name" => _
264269
}
265270
} = log
271+
272+
assert log_line_num > before_log_line_num and log_line_num < after_log_line_num
266273
end
267274

268275
test "may configure level" do

0 commit comments

Comments
 (0)