Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
0241-feat-kernel-allow-binaries-as-parts-of-log...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0241-feat-kernel-allow-binaries-as-parts-of-logger_format.patch of Package erlang
From 8d7ebce65533661d2d3bee15debc6781f736d67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= <lukasz@niemier.pl> Date: Fri, 27 Dec 2019 23:31:55 +0100 Subject: [PATCH 1/4] feat(kernel): allow binaries as parts of logger_formatter template This small change will simplify integration of Erlang's logger with Elixir applications where users are more accustomed to usage of binaries instead of char lists as a "string" type. --- lib/kernel/src/logger_formatter.erl | 5 +- lib/kernel/test/logger_formatter_SUITE.erl | 57 ++++++++++++---------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/lib/kernel/src/logger_formatter.erl b/lib/kernel/src/logger_formatter.erl index 0a145b16d5..4ab043c0fc 100644 --- a/lib/kernel/src/logger_formatter.erl +++ b/lib/kernel/src/logger_formatter.erl @@ -35,7 +35,7 @@ template => template(), time_designator => byte(), time_offset => integer() | [byte()]}. --type template() :: [metakey() | {metakey(),template(),template()} | string()]. +-type template() :: [metakey() | {metakey(),template(),template()} | string() | binary()]. -type metakey() :: atom() | [atom()]. %%%----------------------------------------------------------------- @@ -531,6 +531,9 @@ check_template([Str|T]) when is_list(Str) -> true -> check_template(T); false -> error end; +check_template([Bin|T]) when is_binary(Bin) -> + Str = binary:bin_to_list(Bin), + check_template([Str|T]); check_template([]) -> ok; check_template(_) -> diff --git a/lib/kernel/test/logger_formatter_SUITE.erl b/lib/kernel/test/logger_formatter_SUITE.erl index 5217f76cbc..dc95cbc8e3 100644 --- a/lib/kernel/test/logger_formatter_SUITE.erl +++ b/lib/kernel/test/logger_formatter_SUITE.erl @@ -247,8 +247,13 @@ template(_Config) -> ct:log(String5), "" = String5, - Ref6 = erlang:make_ref(), - Meta6 = #{atom=>some_atom, + Template6 = [<<"binary">>], + String6 = format(info,{"~p",[term]},#{time=>Time},#{template=>Template5}), + ct:log(String6), + "binary" = String6, + + Ref7 = erlang:make_ref(), + Meta7 = #{atom=>some_atom, integer=>632, list=>[list,"string",4321,#{},{tuple}], mfa=>{mod,func,0}, @@ -258,57 +263,57 @@ template(_Config) -> time=>Time, tuple=>{1,atom,"list"}, nested=>#{subkey=>subvalue}}, - Template6 = lists:join(";",lists:sort(maps:keys(maps:remove(nested,Meta6))) ++ + Template7 = lists:join(";",lists:sort(maps:keys(maps:remove(nested,Meta6))) ++ [[nested,subkey]]), - String6 = format(info,{"~p",[term]},Meta6,#{template=>Template6, + String7 = format(info,{"~p",[term]},Meta6,#{template=>Template6, single_line=>true}), ct:log(String6), SelfStr = pid_to_list(self()), - RefStr6 = ref_to_list(Ref6), + RefStr7 = ref_to_list(Ref7), ListStr = "[list,\"string\",4321,#{},{tuple}]", - ExpectedTime6 = default_time_format(Time), + ExpectedTime7 = default_time_format(Time), ["some_atom", "632", ListStr, "mod:func/0", SelfStr, - RefStr6, + RefStr7, "some string", - ExpectedTime6, + ExpectedTime7, "{1,atom,\"list\"}", - "subvalue"] = string:lexemes(String6,";"), + "subvalue"] = string:lexemes(String7,";"), - Meta7 = #{time=>Time, + Meta8 = #{time=>Time, nested=>#{key1=>#{subkey1=>value1}, key2=>value2}}, - Template7 = lists:join(";",[nested, + Template8 = lists:join(";",[nested, [nested,key1], [nested,key1,subkey1], [nested,key2], [nested,key2,subkey2], [nested,key3], [nested,key3,subkey3]]), - String7 = format(info,{"~p",[term]},Meta7,#{template=>Template7, + String8 = format(info,{"~p",[term]},Meta7,#{template=>Template7, single_line=>true}), - ct:log(String7), - [MultipleKeysStr7, + ct:log(String8), + [MultipleKeysStr8, "#{subkey1 => value1}", "value1", "value2", "", "", - ""] = string:split(String7,";",all), + ""] = string:split(String8,";",all), %% Order of keys is not fixed - case MultipleKeysStr7 of + case MultipleKeysStr8 of "#{key2 => value2,key1 => #{subkey1 => value1}}" -> ok; "#{key1 => #{subkey1 => value1},key2 => value2}" -> ok; - _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr7}) + _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr8}) end, - Meta8 = #{time=>Time, + Meta9 = #{time=>Time, nested=>#{key1=>#{subkey1=>value1}, key2=>value2}}, - Template8 = + Template9 = lists:join( ";", [{nested,["exist:",nested],["noexist"]}, @@ -318,21 +323,21 @@ template(_Config) -> {[nested,key2,subkey2],["exist:",[nested,key2,subkey2]],["noexist"]}, {[nested,key3],["exist:",[nested,key3]],["noexist"]}, {[nested,key3,subkey3],["exist:",[nested,key3,subkey3]],["noexist"]}]), - String8 = format(info,{"~p",[term]},Meta8,#{template=>Template8, + String9 = format(info,{"~p",[term]},Meta8,#{template=>Template8, single_line=>true}), - ct:log(String8), - [MultipleKeysStr8, + ct:log(String9), + [MultipleKeysStr9, "exist:#{subkey1 => value1}", "exist:value1", "exist:value2", "noexist", "noexist", - "noexist"] = string:split(String8,";",all), + "noexist"] = string:split(String9,";",all), %% Order of keys is not fixed - case MultipleKeysStr8 of + case MultipleKeysStr9 of "exist:#{key2 => value2,key1 => #{subkey1 => value1}}" -> ok; "exist:#{key1 => #{subkey1 => value1},key2 => value2}" -> ok; - _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr8}) + _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr9}) end, ok. @@ -347,7 +352,7 @@ format_msg(_Config) -> String2 = format(info,{"list",[term]},#{},#{template=>Template}), ct:log(String2), "FORMAT ERROR: \"list\" - [term]" = String2, - + String3 = format(info,{report,term},#{},#{template=>Template}), ct:log(String3), "term" = String3, -- 2.26.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor