diff options
Diffstat (limited to 'lib/kernel/src/logger_h_common.erl')
-rw-r--r-- | lib/kernel/src/logger_h_common.erl | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/lib/kernel/src/logger_h_common.erl b/lib/kernel/src/logger_h_common.erl index e96d2b28f3..f0db587af1 100644 --- a/lib/kernel/src/logger_h_common.erl +++ b/lib/kernel/src/logger_h_common.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2017-2020. All Rights Reserved. +%% Copyright Ericsson AB 2017-2022. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -260,17 +260,39 @@ handle_call(filesync, _From, State = #{id := Name, {Result,HandlerState1} = Module:filesync(Name,sync,HandlerState), {reply, Result, State#{handler_state=>HandlerState1, last_op=>sync}}. +handle_cast({config_changed, CommonConfig, HConfig}, + State = #{id := Name, + module := Module, + handler_state := HandlerState, + filesync_repeat_interval := OldFSyncInt}) -> + State1 = + case maps:get(filesync_repeat_interval,CommonConfig) of + OldFSyncInt -> + State; + FSyncInt -> + set_repeated_filesync( + cancel_repeated_filesync( + State#{filesync_repeat_interval=>FSyncInt})) + end, + HS = try Module:config_changed(Name, HConfig, HandlerState) + catch error:undef -> HandlerState + end, + {noreply, State1#{handler_state => HS}}. + %% If FILESYNC_REPEAT_INTERVAL is set to a millisec value, this %% clause gets called repeatedly by the handler. In order to %% guarantee that a filesync *always* happens after the last log %% event, the repeat operation must be active! -handle_cast(repeated_filesync,State = #{filesync_repeat_interval := no_repeat}) -> +handle_info({timeout, TRef, repeated_filesync}, + State = #{rep_sync_tref := TRef, + filesync_repeat_interval := no_repeat}) -> %% This clause handles a race condition which may occur when %% config changes filesync_repeat_interval from an integer value %% to no_repeat. {noreply,State}; -handle_cast(repeated_filesync, +handle_info({timeout, TRef, repeated_filesync}, State = #{id := Name, + rep_sync_tref := TRef, module := Module, handler_state := HandlerState, last_op := LastOp}) -> @@ -282,25 +304,6 @@ handle_cast(repeated_filesync, State#{handler_state => HS, last_op => sync} end, {noreply,set_repeated_filesync(State1)}; -handle_cast({config_changed, CommonConfig, HConfig}, - State = #{id := Name, - module := Module, - handler_state := HandlerState, - filesync_repeat_interval := OldFSyncInt}) -> - State1 = - case maps:get(filesync_repeat_interval,CommonConfig) of - OldFSyncInt -> - State; - FSyncInt -> - set_repeated_filesync( - cancel_repeated_filesync( - State#{filesync_repeat_interval=>FSyncInt})) - end, - HS = try Module:config_changed(Name, HConfig, HandlerState) - catch error:undef -> HandlerState - end, - {noreply, State1#{handler_state => HS}}. - handle_info(Info, #{id := Name, module := Module, handler_state := HandlerState} = State) -> {noreply,State#{handler_state => Module:handle_info(Name,Info,HandlerState)}}. @@ -396,7 +399,7 @@ do_log_to_binary(Log,Config) -> {config,FormatterConfig}, {log_event,Log}, {bad_return_value,String}, - {catched,{C2,R2,S2}}]), + {caught,{C2,R2,S2}}]), <<"FORMATTER ERROR: bad return value\n">> end. @@ -445,8 +448,7 @@ get_default_config() -> set_repeated_filesync(#{filesync_repeat_interval:=FSyncInt} = State) when is_integer(FSyncInt) -> - {ok,TRef} = timer:apply_after(FSyncInt, gen_server, cast, - [self(),repeated_filesync]), + TRef = erlang:start_timer(FSyncInt, self(), repeated_filesync), State#{rep_sync_tref=>TRef}; set_repeated_filesync(State) -> State. @@ -454,7 +456,15 @@ set_repeated_filesync(State) -> cancel_repeated_filesync(State) -> case maps:take(rep_sync_tref,State) of {TRef,State1} -> - _ = timer:cancel(TRef), + case erlang:cancel_timer(TRef) of + false -> + %% Flush the timer message + receive + {timeout, TRef, _} -> ok + end; + _ -> + ok + end, State1; error -> State |