<commit_before>-module(logger).

-behaviour(gen_server).

-include("parallant.hrl").
%% API
-export([start_link/1, start/2, start/3, start/4, stop/1, log/1]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

-define(SERVER, ?MODULE).

-record(state, {model :: model(),
                step = 1 :: pos_integer(),
                log = false :: boolean(),
                animate = true :: boolean()}).

-define(LOG_DELAY, 0). % ms
-define(MAX_WIDTH_TO_SHOW, 65).

%%%===================================================================
%%% API
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc
%% Starts the server
%%
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
%% @end
%%--------------------------------------------------------------------
start_link(Params) ->
    gen_server:start_link({local, ?SERVER}, ?MODULE, Params, []).

log(Env) ->
    gen_server:cast(?SERVER, {log, Env}).

start(Model, Env) ->
    start(Model, Env, false, true).
start(Model, Env, Log) ->
    start(Model, Env, Log, true).
start(Model, Env, Log, Animate) ->
    start_link([Model, Env, Log, Animate]).

stop(EndEnv) ->
    gen_server:call(?SERVER, {stop, EndEnv}, infinity).


%%%===================================================================
%%% gen_server callbacks
%%%===================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Initializes the server
%%
%% @spec init(Args) -> {ok, State} |
%%                     {ok, State, Timeout} |
%%                     ignore |
%%                     {stop, Reason}
%% @end
%%--------------------------------------------------------------------
init([Model, Env]) ->
    init([Model, Env, false, true]);
init([Model, Env, Log]) ->
    init([Model, Env, Log, true]);
init([Model, Env, Log, Animate]) ->
    print(Model, Env, 1),
    {ok, #state{model = Model, log = Log, animate = Animate}}.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Handling call messages
%%
%% @spec handle_call(Request, From, State) ->
%%                                   {reply, Reply, State} |
%%                                   {reply, Reply, State, Timeout} |
%%                                   {noreply, State} |
%%                                   {noreply, State, Timeout} |
%%                                   {stop, Reason, Reply, State} |
%%                                   {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
handle_call({stop, Env}, _From, State) ->
    print(State#state.model, Env, State#state.step),
    {stop, normal, ok, State};
handle_call(_Request, _From, State) ->
    Reply = ok,
    {reply, Reply, State}.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Handling cast messages
%%
%% @spec handle_cast(Msg, State) -> {noreply, State} |
%%                                  {noreply, State, Timeout} |
%%                                  {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
handle_cast({log, _Env}, S = #state{log = false}) ->
    {noreply, S#state{step = S#state.step+1}};
handle_cast({log, Env}, S) ->
    log(S#state.model, Env, S#state.step, S#state.animate),
    {noreply, S#state{step = S#state.step+1}};
handle_cast(_Msg, S) ->
    {noreply, S}.<commit_msg>Store environment in state of logger gen_server<commit_after>-module(logger).

-behaviour(gen_server).

-include("parallant.hrl").
%% API
-export([start_link/1, start/2, start/3, start/4, stop/1, log/1]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

-define(SERVER, ?MODULE).

-record(state, {model :: model(),
                env :: environment(),
                step = 1 :: pos_integer(),
                log = false :: boolean(),
                animate = true :: boolean()}).

-define(LOG_DELAY, 0). % ms
-define(MAX_WIDTH_TO_SHOW, 65).

%%%===================================================================
%%% API
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc
%% Starts the server
%%
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
%% @end
%%--------------------------------------------------------------------
start_link(Params) ->
    gen_server:start_link({local, ?SERVER}, ?MODULE, Params, []).

log(Env) ->
    gen_server:cast(?SERVER, {log, Env}).

start(Model, Env) ->
    start(Model, Env, false, true).
start(Model, Env, Log) ->
    start(Model, Env, Log, true).
start(Model, Env, Log, Animate) ->
    start_link([Model, Env, Log, Animate]).

stop(EndEnv) ->
    gen_server:call(?SERVER, {stop, EndEnv}, infinity).


%%%===================================================================
%%% gen_server callbacks
%%%===================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Initializes the server
%%
%% @spec init(Args) -> {ok, State} |
%%                     {ok, State, Timeout} |
%%                     ignore |
%%                     {stop, Reason}
%% @end
%%--------------------------------------------------------------------
init([Model, Env]) ->
    init([Model, Env, false, true]);
init([Model, Env, Log]) ->
    init([Model, Env, Log, true]);
init([Model, Env, Log, Animate]) ->
    print(Model, Env, 1),
    {ok, #state{model = Model, log = Log, animate = Animate, env = Env}}.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Handling call messages
%%
%% @spec handle_call(Request, From, State) ->
%%                                   {reply, Reply, State} |
%%                                   {reply, Reply, State, Timeout} |
%%                                   {noreply, State} |
%%                                   {noreply, State, Timeout} |
%%                                   {stop, Reason, Reply, State} |
%%                                   {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
handle_call({stop, Env}, _From, State) ->
    print(State#state.model, Env, State#state.step),
    {stop, normal, ok, State};
handle_call(_Request, _From, State) ->
    Reply = ok,
    {reply, Reply, State}.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Handling cast messages
%%
%% @spec handle_cast(Msg, State) -> {noreply, State} |
%%                                  {noreply, State, Timeout} |
%%                                  {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
handle_cast({log, Env}, S = #state{log = false}) ->
    noreply_log(S#state{env = Env});
handle_cast({log, Env}, S) ->
    log(S#state.model, Env, S#state.step, S#state.animate),
    noreply_log(S#state{env = Env});
handle_cast(_Msg, S) ->
    {noreply, S}.

noreply_log(S) ->
    {noreply, S#state{step = S#state.step + 1}}.
{'fraction_non_alphanumeric': 0.3700081499592502, 'fraction_numerical': 0.005025808204292312, 'mean_word_length': 1.5971781305114638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6561687', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1927, 'n_words': 446}