Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:26
erlang
2471-logger-Don-t-print-stdinfo-msg-to-stdout-i...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2471-logger-Don-t-print-stdinfo-msg-to-stdout-in-simple-l.patch of Package erlang
From 570536e6f6b0126d8e140810d6135df3a6d80a4d Mon Sep 17 00:00:00 2001 From: Lukas Larsson <lukas@erlang.org> Date: Tue, 20 Feb 2024 11:40:08 +0100 Subject: [PATCH] logger: Don't print stdinfo msg to stdout in simple logger We only want to replay info messages in the default logger when they happen. If we print them in the simple logger we end up with duplicate log messages and also if the default logger is file based, we print things to stdout no matter what. closes #8117 --- lib/kernel/src/logger_simple_h.erl | 22 +++++++++++------- lib/kernel/test/logger_simple_h_SUITE.erl | 27 ++++++++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/lib/kernel/src/logger_simple_h.erl b/lib/kernel/src/logger_simple_h.erl index 200e60e059..e12959aa60 100644 --- a/lib/kernel/src/logger_simple_h.erl +++ b/lib/kernel/src/logger_simple_h.erl @@ -81,14 +81,15 @@ do_log(#{msg:=_,meta:=#{time:=_}=M}=Log) -> %% Log directly from client just to get it out case maps:get(internal_log_event, M, false) of false -> - do_log(simple, - #{level=>error, - msg=>{report,{error,simple_handler_process_dead}}, - meta=>#{time=>logger:timestamp()}}); + log_internal( + simple, + #{level=>error, + msg=>{report,{error,simple_handler_process_dead}}, + meta=>#{time=>logger:timestamp()}}); true -> ok end, - do_log(simple,Log); + log_internal(simple,Log); _ -> ?MODULE ! {log,Log} end; @@ -120,8 +121,13 @@ loop(Mode, Buffer) -> %% an unexpected EXIT message unlink(whereis(logger)), ok; + {log,#{meta:=#{error_logger:=#{tag:=info_report,type:=Type}}} = Log} + when Type =/= std_info -> + %% When we get a std_info message, we just want to replay it, + %% no need to print it right now + loop(Mode, update_buffer(Buffer,Log)); {log,#{msg:=_,meta:=#{time:=_}}=Log} -> - NewMode = do_log(Mode, Log), + NewMode = log_internal(Mode, Log), loop(NewMode, update_buffer(Buffer,Log)); _ -> %% Unexpected message - flush it! @@ -156,9 +162,9 @@ drop_msg(N) -> %% for each log message that can potentially block. If the logging cannot %% be done within 300ms, we instead log the raw log message to stdout %% and switch mode to always log using the raw format. -do_log(simple, Log) -> +log_internal(simple, Log) -> display_log(Log), simple; -do_log(rich = Mode, Log) -> +log_internal(rich = Mode, Log) -> {Pid, Ref} = spawn_monitor( diff --git a/lib/kernel/test/logger_simple_h_SUITE.erl b/lib/kernel/test/logger_simple_h_SUITE.erl index 63f16c6126..854028af24 100644 --- a/lib/kernel/test/logger_simple_h_SUITE.erl +++ b/lib/kernel/test/logger_simple_h_SUITE.erl @@ -105,14 +105,31 @@ start_stop(cleanup,_Config) -> logger:remove_handler(simple). %% Test that the simple logger works when debug level is used -start_debug(_Config) -> - - Output = os:cmd(ct:get_progname() ++ " -s init stop"), +start_debug(Config) -> + + ConfigFile = filename:join(proplists:get_value(priv_dir, Config), "sys.config"), + LogFile = filename:join(proplists:get_value(priv_dir, Config), "file.log"), + SysConfig = [{kernel,[{logger,[{handler,default,logger_std_h, + #{config => #{file => LogFile}}}]}]}], + ok = file:write_file(ConfigFile, io_lib:format("~p.",[SysConfig])), + + Run = + fun(Args) -> + CmdLine = + lists:flatten( + [ct:get_progname(), " ", Args, + " -config ", filename:rootname(ConfigFile), " -noshell -s init stop"]), + "" = os:cmd(CmdLine), + {ok, Bin} = file:read_file(LogFile), + Bin + end, + + Output = Run(""), LogOutput = re:replace(unicode:characters_to_binary(Output),"\r\n","\n",[global]), ct:log("~ts",[LogOutput]), nomatch = re:run(LogOutput,"^=PROGRESS REPORT====",[global,multiline]), - InfoOutput = os:cmd(ct:get_progname() ++ " -kernel logger_level info -s init stop"), + InfoOutput = Run("-kernel logger_level info"), InfoLogOutput = re:replace(unicode:characters_to_binary(InfoOutput),"\r\n","\n",[global]), ct:log("~ts",[InfoLogOutput]), {match,InfoNumReports} = re:run(InfoLogOutput,"^=PROGRESS REPORT====",[global,multiline]), @@ -120,7 +137,7 @@ start_debug(_Config) -> %% Test that more progress reports are logged for info than default ?assert(0 < length(InfoNumReports)), - DebugOutput = os:cmd(ct:get_progname() ++ " -kernel logger_level debug -s init stop"), + DebugOutput = Run("-kernel logger_level debug"), DebugLogOutput = re:replace(unicode:characters_to_binary(DebugOutput),"\r\n","\n",[global]), ct:log("~ts",[DebugLogOutput]), {match,DebugNumReports} = re:run(DebugLogOutput,"^=PROGRESS REPORT====",[global,multiline]), -- 2.35.3
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