Skip to content

Commit

Permalink
Sort map by keys
Browse files Browse the repository at this point in the history
  • Loading branch information
reachfh committed Aug 11, 2024
1 parent 1f66835 commit c153cf7
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions test/logger_formatter_json_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ structured(_) ->
)
),
?assertEqual(
<<
"{\"msg\":{\"args\":\"10.10.2.182\",\"label\":\"{error_logger,error_msg}\",\"format\":\"** System NOT running to use fully qualified hostnames **~n** Hostname ~ts is illegal **~n\"},\"level\":\"info\"}\n"
>>,
<<"{\"msg\":{\"args\":\"10.10.2.182\",\"format\":\"** System NOT running to use fully qualified hostnames **~n** Hostname ~ts is illegal **~n\",\"label\":\"{error_logger,error_msg}\"},\"level\":\"info\"}\n">>,
iolist_to_binary(
logger_formatter_json:format(
#{
Expand Down Expand Up @@ -365,17 +363,11 @@ structured(_) ->


metadata(_) ->
Config = #{names => datadog},
?assertEqual(
<<"{\"message\":\"abc\",\"status\":\"info\"}\n">>,
iolist_to_binary(
logger_formatter_json:format(#{level => info, msg => {string, "abc"}, meta => #{}}, Config)
)
),
Config = #{template => [msg, level, conn,crash_reason,domain,error_logger,gl,otel_span_id,
otel_trace_flags,otel_trace_id,pid,time,xray_trace_id]},
Meta = #{error_logger => #{tag => error},pid => c:pid(0, 672, 0),time => 1723325773127320,gl => c:pid(0, 394, 0),domain => [cowboy],otel_trace_id => "66b7dd4d7dad9f9aba84fb43389b4611",otel_span_id => "052d4929d398aec6",xray_trace_id => <<"1-66b7dd4d-dad9f9aba84fb43389b4611@052d4929d398aec6">>,otel_trace_flags => "01",crash_reason => {#{message => <<"bad argument in arithmetic expression">>,'__struct__' => 'Elixir.ArithmeticError','__exception__' => true},[{erlang,'+',[1,a],[{error_info,#{module => erl_erts_errors}}]},{'Elixir.PhoenixContainerExampleWeb.PageController',home,2,[{file,"lib/phoenix_container_example_web/controllers/page_controller.ex"},{line,8}]},{'Elixir.PhoenixContainerExampleWeb.PageController',action,2,[{file,"lib/phoenix_container_example_web/controllers/page_controller.ex"},{line,1}]},{'Elixir.PhoenixContainerExampleWeb.PageController',phoenix_controller_pipeline,2,[{file,"lib/phoenix_container_example_web/controllers/page_controller.ex"},{line,1}]},{'Elixir.Phoenix.Router','__call__',5,[{file,"lib/phoenix/router.ex"},{line,484}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint',plug_builder_call,2,[{file,"lib/phoenix_container_example_web/endpoint.ex"},{line,1}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint','call (overridable 3)',2,[{file,"deps/plug/lib/plug/debugger.ex"},{line,136}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint',call,2,[{file,"lib/phoenix_container_example_web/endpoint.ex"},{line,1}]},{'Elixir.Phoenix.Endpoint.SyncCodeReloadPlug',do_call,4,[{file,"lib/phoenix/endpoint/sync_code_reload_plug.ex"},{line,22}]},{'Elixir.Plug.Cowboy.Handler',init,2,[{file,"lib/plug/cowboy/handler.ex"},{line,11}]},{cowboy_handler,execute,2,[{file,"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_handler.erl"},{line,37}]},{cowboy_stream_h,execute,3,[{file,"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_stream_h.erl"},{line,306}]},{cowboy_stream_h,request_process,3,[{file,"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_stream_h.erl"},{line,295}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,329}]}]},conn => #{owner => c:pid(0,673,0),port => 4000,private => #{},scheme => http,status => nil,script_name => [],state => unset,host => <<"localhost">>,params => #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',aspect => params},'__struct__' => 'Elixir.Plug.Conn',halted => false,adapter => {'Elixir.Plug.Cowboy.Conn',#{pid => c:pid(0,672,0),port => 4000,scheme => <<"http">>,version => 'HTTP/1.1',path => <<"/">>,host => <<"localhost">>,peer => {{127,0,0,1},58196},bindings => #{},ref => 'Elixir.PhoenixContainerExampleWeb.Endpoint.HTTP',cert => undefined,headers => #{<<"accept">> => <<"*/*">>,<<"host">> => <<"localhost:4000">>,<<"user-agent">> => <<"curl/8.6.0">>},sock => {{127,0,0,1},4000},method => <<"GET">>,path_info => undefined,host_info => undefined,streamid => 1,body_length => 0,has_body => false,qs => <<>>}},secret_key_base => nil,cookies => #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',aspect => cookies},request_path => <<"/">>,assigns => #{},method => <<"GET">>,query_string => <<>>,remote_ip => {127,0,0,1},req_headers => [{<<"accept">>,<<"*/*">>},{<<"host">>,<<"localhost:4000">>},{<<"user-agent">>,<<"curl/8.6.0">>}],path_info => [],path_params => #{},resp_headers => [{<<"cache-control">>,<<"max-age=0, private, must-revalidate">>}],resp_cookies => #{},resp_body => nil,body_params => #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',aspect => body_params},query_params => #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',aspect => query_params},req_cookies => #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',aspect => cookies}}},

?assertEqual(
<<"{\"message\":\"abc\",\"error_logger\":{\"tag\":\"error\"},\"logger.thread_name\":\"<0.672.0>\",\"date\":\"1723325773127320\",\"gl\":\"<0.394.0>\",\"domain\":\"[cowboy]\",\"status\":\"info\",\"otel_trace_id\":\"66b7dd4d7dad9f9aba84fb43389b4611\",\"otel_span_id\":\"052d4929d398aec6\",\"xray_trace_id\":\"1-66b7dd4d-dad9f9aba84fb43389b4611@052d4929d398aec6\",\"otel_trace_flags\":\"01\",\"crash_reason\":\"{#{message => <<\\\"bad argument in arithmetic expression\\\">>,'__struct__' => 'Elixir.ArithmeticError','__exception__' => true},[{erlang,'+',[1,a],[{error_info,#{module => erl_erts_errors}}]},{'Elixir.PhoenixContainerExampleWeb.PageController',home,2,[{file,\\\"lib/phoenix_container_example_web/controllers/page_controller.ex\\\"},{line,8}]},{'Elixir.PhoenixContainerExampleWeb.PageController',action,2,[{file,\\\"lib/phoenix_container_example_web/controllers/page_controller.ex\\\"},{line,1}]},{'Elixir.PhoenixContainerExampleWeb.PageController',phoenix_controller_pipeline,2,[{file,\\\"lib/phoenix_container_example_web/controllers/page_controller.ex\\\"},{line,1}]},{'Elixir.Phoenix.Router','__call__',5,[{file,\\\"lib/phoenix/router.ex\\\"},{line,484}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint',plug_builder_call,2,[{file,\\\"lib/phoenix_container_example_web/endpoint.ex\\\"},{line,1}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint','call (overridable 3)',2,[{file,\\\"deps/plug/lib/plug/debugger.ex\\\"},{line,136}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint',call,2,[{file,\\\"lib/phoenix_container_example_web/endpoint.ex\\\"},{line,1}]},{'Elixir.Phoenix.Endpoint.SyncCodeReloadPlug',do_call,4,[{file,\\\"lib/phoenix/endpoint/sync_code_reload_plug.ex\\\"},{line,22}]},{'Elixir.Plug.Cowboy.Handler',init,2,[{file,\\\"lib/plug/cowboy/handler.ex\\\"},{line,11}]},{cowboy_handler,execute,2,[{file,\\\"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_handler.erl\\\"},{line,37}]},{cowboy_stream_h,execute,3,[{file,\\\"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_stream_h.erl\\\"},{line,306}]},{cowboy_stream_h,request_process,3,[{file,\\\"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_stream_h.erl\\\"},{line,295}]},{proc_lib,init_p_do_apply,3,[{file,\\\"proc_lib.erl\\\"},{line,329}]}]}\",\"conn\":{\"owner\":\"<0.673.0>\",\"port\":\"4000\",\"private\":[],\"scheme\":\"http\",\"status\":\"nil\",\"script_name\":\"[]\",\"state\":\"unset\",\"host\":\"localhost\",\"params\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"params\"},\"cookies\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"cookies\"},\"request_path\":\"/\",\"__struct__\":\"Elixir.Plug.Conn\",\"halted\":\"false\",\"adapter\":\"{'Elixir.Plug.Cowboy.Conn',#{pid => <0.672.0>,port => 4000,scheme => <<\\\"http\\\">>,version => 'HTTP/1.1',path => <<\\\"/\\\">>,host => <<\\\"localhost\\\">>,peer => {{127,0,0,1},58196},bindings => #{},cert => undefined,headers => #{<<\\\"accept\\\">> => <<\\\"*/*\\\">>,<<\\\"host\\\">> => <<\\\"localhost:4000\\\">>,<<\\\"user-agent\\\">> => <<\\\"curl/8.6.0\\\">>},ref => 'Elixir.PhoenixContainerExampleWeb.Endpoint.HTTP',sock => {{127,0,0,1},4000},method => <<\\\"GET\\\">>,path_info => undefined,host_info => undefined,streamid => 1,body_length => 0,has_body => false,qs => <<>>}}\",\"method\":\"GET\",\"path_info\":\"[]\",\"secret_key_base\":\"nil\",\"assigns\":[],\"query_string\":\"\",\"remote_ip\":\"{127,0,0,1}\",\"req_headers\":\"[{<<\\\"accept\\\">>,<<\\\"*/*\\\">>},{<<\\\"host\\\">>,<<\\\"localhost:4000\\\">>},{<<\\\"user-agent\\\">>,<<\\\"curl/8.6.0\\\">>}]\",\"path_params\":[],\"resp_headers\":\"[{<<\\\"cache-control\\\">>,<<\\\"max-age=0, private, must-revalidate\\\">>}]\",\"resp_cookies\":[],\"resp_body\":\"nil\",\"body_params\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"body_params\"},\"query_params\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"query_params\"},\"req_cookies\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"cookies\"}}}\n">>,
<<"{\"msg\":\"abc\",\"level\":\"info\",\"conn\":{\"__struct__\":\"Elixir.Plug.Conn\",\"adapter\":\"{'Elixir.Plug.Cowboy.Conn',#{pid => <0.672.0>,port => 4000,scheme => <<\\\"http\\\">>,version => 'HTTP/1.1',path => <<\\\"/\\\">>,host => <<\\\"localhost\\\">>,peer => {{127,0,0,1},58196},bindings => #{},cert => undefined,headers => #{<<\\\"accept\\\">> => <<\\\"*/*\\\">>,<<\\\"host\\\">> => <<\\\"localhost:4000\\\">>,<<\\\"user-agent\\\">> => <<\\\"curl/8.6.0\\\">>},ref => 'Elixir.PhoenixContainerExampleWeb.Endpoint.HTTP',body_length => 0,has_body => false,host_info => undefined,method => <<\\\"GET\\\">>,path_info => undefined,qs => <<>>,sock => {{127,0,0,1},4000},streamid => 1}}\",\"assigns\":[],\"body_params\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"body_params\"},\"cookies\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"cookies\"},\"halted\":\"false\",\"host\":\"localhost\",\"method\":\"GET\",\"owner\":\"<0.673.0>\",\"params\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"params\"},\"path_info\":\"[]\",\"path_params\":[],\"port\":\"4000\",\"private\":[],\"query_params\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"query_params\"},\"query_string\":\"\",\"remote_ip\":\"{127,0,0,1}\",\"req_cookies\":{\"__struct__\":\"Elixir.Plug.Conn.Unfetched\",\"aspect\":\"cookies\"},\"req_headers\":\"[{<<\\\"accept\\\">>,<<\\\"*/*\\\">>},{<<\\\"host\\\">>,<<\\\"localhost:4000\\\">>},{<<\\\"user-agent\\\">>,<<\\\"curl/8.6.0\\\">>}]\",\"request_path\":\"/\",\"resp_body\":\"nil\",\"resp_cookies\":[],\"resp_headers\":\"[{<<\\\"cache-control\\\">>,<<\\\"max-age=0, private, must-revalidate\\\">>}]\",\"scheme\":\"http\",\"script_name\":\"[]\",\"secret_key_base\":\"nil\",\"state\":\"unset\",\"status\":\"nil\"},\"crash_reason\":\"{#{message => <<\\\"bad argument in arithmetic expression\\\">>,'__struct__' => 'Elixir.ArithmeticError','__exception__' => true},[{erlang,'+',[1,a],[{error_info,#{module => erl_erts_errors}}]},{'Elixir.PhoenixContainerExampleWeb.PageController',home,2,[{file,\\\"lib/phoenix_container_example_web/controllers/page_controller.ex\\\"},{line,8}]},{'Elixir.PhoenixContainerExampleWeb.PageController',action,2,[{file,\\\"lib/phoenix_container_example_web/controllers/page_controller.ex\\\"},{line,1}]},{'Elixir.PhoenixContainerExampleWeb.PageController',phoenix_controller_pipeline,2,[{file,\\\"lib/phoenix_container_example_web/controllers/page_controller.ex\\\"},{line,1}]},{'Elixir.Phoenix.Router','__call__',5,[{file,\\\"lib/phoenix/router.ex\\\"},{line,484}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint',plug_builder_call,2,[{file,\\\"lib/phoenix_container_example_web/endpoint.ex\\\"},{line,1}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint','call (overridable 3)',2,[{file,\\\"deps/plug/lib/plug/debugger.ex\\\"},{line,136}]},{'Elixir.PhoenixContainerExampleWeb.Endpoint',call,2,[{file,\\\"lib/phoenix_container_example_web/endpoint.ex\\\"},{line,1}]},{'Elixir.Phoenix.Endpoint.SyncCodeReloadPlug',do_call,4,[{file,\\\"lib/phoenix/endpoint/sync_code_reload_plug.ex\\\"},{line,22}]},{'Elixir.Plug.Cowboy.Handler',init,2,[{file,\\\"lib/plug/cowboy/handler.ex\\\"},{line,11}]},{cowboy_handler,execute,2,[{file,\\\"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_handler.erl\\\"},{line,37}]},{cowboy_stream_h,execute,3,[{file,\\\"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_stream_h.erl\\\"},{line,306}]},{cowboy_stream_h,request_process,3,[{file,\\\"/Users/jake/work/phoenix_container_example/deps/cowboy/src/cowboy_stream_h.erl\\\"},{line,295}]},{proc_lib,init_p_do_apply,3,[{file,\\\"proc_lib.erl\\\"},{line,329}]}]}\",\"domain\":\"[cowboy]\",\"error_logger\":{\"tag\":\"error\"},\"gl\":\"<0.394.0>\",\"otel_span_id\":\"052d4929d398aec6\",\"otel_trace_flags\":\"01\",\"otel_trace_id\":\"66b7dd4d7dad9f9aba84fb43389b4611\",\"pid\":\"<0.672.0>\",\"time\":\"2024-08-10T16:36:13.127320-05:00\",\"xray_trace_id\":\"1-66b7dd4d-dad9f9aba84fb43389b4611@052d4929d398aec6\"}\n">>,
iolist_to_binary(
logger_formatter_json:format(#{level => info, msg => {string, "abc"}, meta => Meta}, Config)
)
Expand Down

0 comments on commit c153cf7

Please sign in to comment.