anchor.diff:  %% ====================================================================
   
   check_logs(ExpectedLogNumber) ->
  -  {StartTime, _} = statistics(wall_clock),
  -  {UnknownSourceLogs, ErrorLoggerLogs, LagerLogs} = count_logs(0, 0, 0, ExpectedLogNumber, StartTime),
  -
  -  %% 4/10 of logs should have been classified as of unknown source
  -  ?assertEqual(ExpectedLogNumber div 10 * 4, UnknownSourceLogs),
  -
  -  %% 2/10 of logs should have been classified as error_logger logs
  -  ?assertEqual(ExpectedLogNumber div 10 * 2, ErrorLoggerLogs),
  -
  -  %% 4/10 of logs should have been classified as standard lager logs
  -  ?assertEqual(ExpectedLogNumber div 10 * 4, LagerLogs).
  -
  -
  -count_logs(UnknownSourceLogs, ErrorLoggerLogs, LagerLogs, Expected, StartTime) -> 
  -  {CurrentTime, _} = statistics(wall_clock),
  -  case CurrentTime - StartTime < 5000 of
  -    false -> 
  -      {UnknownSourceLogs, ErrorLoggerLogs, LagerLogs};
  -    true ->
  -      case UnknownSourceLogs + ErrorLoggerLogs + LagerLogs of
  -        Expected -> 
  -          {UnknownSourceLogs, ErrorLoggerLogs, LagerLogs};
  -        _ ->
  -          receive 
  -            {log, {"test_log", _, _, [{node, _}, {source, unknown}]}} -> 
  -              count_logs(UnknownSourceLogs + 1, ErrorLoggerLogs, LagerLogs, Expected, StartTime);
  -
  -            {log, {"test_log", _, _, [{node, _}, {source, error_logger}, {pid, _}]}} -> 
  -              count_logs(UnknownSourceLogs, ErrorLoggerLogs + 1, LagerLogs, Expected, StartTime);
  -
  -            {log, {"test_log", _, _, Metadata}} -> 
  -              true = (proplists:get_value(node, Metadata) /= undefined), 
  -              count_logs(UnknownSourceLogs, ErrorLoggerLogs, LagerLogs + 1, Expected, StartTime)
  -
  -          after 100 ->
  -              count_logs(UnknownSourceLogs, ErrorLoggerLogs, LagerLogs, Expected, StartTime)
  -          end
  -      end
  -  end.
  -
  -
  +    {StartTime, _} = statistics(wall_clock),
  +    {ErrorLoggerLogs, LagerLogs} = count_logs(0, 0, ExpectedLogNumber, StartTime),
  +
  +    %% 4/10 of logs should have been classified as error_logger logs
  +    ?assertEqual(ExpectedLogNumber div 10 * 4, ErrorLoggerLogs),
  +
  +    %% 6/10 of logs should have been classified as standard lager logs
  +    ?assertEqual(ExpectedLogNumber div 10 * 6, LagerLogs).
  +
  +
  +count_logs(ErrorLoggerLogs, LagerLogs, Expected, StartTime) ->
  +    {CurrentTime, _} = statistics(wall_clock),
  +    case CurrentTime - StartTime < 5000 of
  +        false ->
  +            {ErrorLoggerLogs, LagerLogs};
  +        true ->
  +            case ErrorLoggerLogs + LagerLogs of
  +                Expected ->
  +                    {ErrorLoggerLogs, LagerLogs};
  +                _ ->
  +                    receive
  +                        {log, {"test_log", _, _, [{node, _}, {pid, _}]}} ->
  +                            count_logs(ErrorLoggerLogs + 1, LagerLogs, Expected, StartTime);
  +
  +                        {log, {"test_log", _, _, Metadata}} ->
  +                            true = (proplists:get_value(node, Metadata) /= undefined),
  +                            count_logs(ErrorLoggerLogs, LagerLogs + 1, Expected, StartTime)
  +
  +                    after 100 ->
  +                        count_logs(ErrorLoggerLogs, LagerLogs, Expected, StartTime)
  +                    end
  +            end
  +    end.
   
   
   %% ====================================================================
  
positive.code: %% central_logger subscribing and log stream
  
  logging_test(Config) ->
    nodes_manager:check_start_assertions(Config),
  
    NodesUp = ?config(nodes, Config),
    [CCM, W1, W2, W3, W4] = NodesUp,
  
    % Init cluster
    gen_server:cast({?Node_Manager_Name, CCM}, do_heart_beat),
    gen_server:cast({global, ?CCM}, {set_monitoring, on}),
    nodes_manager:wait_for_cluster_cast(),
    nodes_manager:wait_for_nodes_registration(length(NodesUp) - 1),
    gen_server:cast({global, ?CCM}, init_cluster),
    nodes_manager:wait_for_cluster_init(),
  
    % Subscribe for log stream
    Pid = self(),
    ?assertEqual(ok, gen_server:call({?Dispatcher_Name, W3}, {central_logger, 1, {subscribe, cluster, Pid}}, 1000)),
  
    % Every call will produce [10 * Arg1] of logs
    ?assertEqual(ok, rpc:call(CCM, ?MODULE, perform_10_logs, [5])),
    ?assertEqual(ok, rpc:call(W1, ?MODULE, perform_10_logs, [3])),
    ?assertEqual(ok, rpc:call(W2, ?MODULE, perform_10_logs, [2])),
    ?assertEqual(ok, rpc:call(W3, ?MODULE, perform_10_logs, [11])),
    ?assertEqual(ok, rpc:call(W4, ?MODULE, perform_10_logs, [4])),
    
    % Assert that logs arrived and are correctly tagged
    check_logs(250),
  
    % Unsubscribe from log stream
    ?assertEqual(ok, gen_server:call({?Dispatcher_Name, W3}, {central_logger, 1, {unsubscribe, cluster, Pid}}, 1000)),
    % Ask for subscribers list
    ?assertEqual(ok, gen_server:call({?Dispatcher_Name, W3}, {central_logger, 1, self(), message_id, get_subscribers}, 1000)),
    % To confirm, that this pid is no longer subscribed
    ?assertEqual([], receive {worker_answer, message_id, Response} -> Response after 1000 -> timeout end).
  
  
  
  
  %% ====================================================================
  
negative.code: %% sets up lager traces and if it cleans up after termination
  
  init_and_cleanup_test(Config) ->
      nodes_manager:check_start_assertions(Config),
  
      NodesUp = ?config(nodes, Config),
      [CCM, W] = NodesUp,
  
      % Get standard trace configuration from worker node
      StandardTraces = rpc:call(W, ?MODULE, get_lager_traces, []),
  
      % Init cluster
      gen_server:cast({?Node_Manager_Name, CCM}, do_heart_beat),
      gen_server:cast({global, ?CCM}, {set_monitoring, on}),
      nodes_manager:wait_for_cluster_cast(),
      gen_server:cast({global, ?CCM}, init_cluster),
      nodes_manager:wait_for_cluster_init(),
  
      % Test logger's console loglevel switching functionalities
      ?assertEqual(ok, rpc:call(W, ?MODULE, check_console_loglevel_functionalities, [])),
      ?assertEqual(ok, rpc:call(CCM, ?MODULE, check_console_loglevel_functionalities, [])),
  
      % Get new trace configuration after start of central_logger module
      NewTraces = rpc:call(W, ?MODULE, get_lager_traces, []),
  
      % Check if new configuration contains standard entries plus global log files
      lists:foreach(
          fun(Trace) ->
              ?assert(lists:member(Trace, NewTraces))
          end, StandardTraces),
      ?assert(lists:member({lager_file_backend, "log/global_error.log"}, NewTraces)),
      ?assert(lists:member({lager_file_backend, "log/global_info.log"}, NewTraces)),
      ?assert(lists:member({lager_file_backend, "log/global_debug.log"}, NewTraces)),
      ?assert(lists:member({lager_file_backend, "log/client_error.log"}, NewTraces)),
      ?assert(lists:member({lager_file_backend, "log/client_info.log"}, NewTraces)),
      ?assert(lists:member({lager_file_backend, "log/client_debug.log"}, NewTraces)),
      % And only those
      ?assertEqual(length(StandardTraces) + 6, length(NewTraces)),
  
      % Terminate central_logger worker
      gen_server:cast({global, ?CCM}, {stop_worker, W, central_logger}),
      nodes_manager:wait_for_cluster_cast(),
  
      % Check if traces were reset to default
      TracesAfterCleanup = rpc:call(W, ?MODULE, get_lager_traces, []),
      ?assertEqual(StandardTraces, TracesAfterCleanup),
  
      % Check if lager still works at worker node
      ?assertEqual(ok, rpc:call(W, lager, log, [info, [], "log"])).
  
  
  %% ====================================================
  