<commit_before>-module(log).
-behaviour(gen_server).

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

-export([start_link/1, set_debug/1, log/1, debug/1]).

-record(state, {
    filename,
    debug_mode}).


%% ===================================================================
%% API functions
%% ===================================================================

start_link(Filename) ->
    gen_server:start_link({local, ?MODULE}, ?MODULE, [Filename], []).

set_debug(Debug) when is_boolean(Debug) ->
    gen_server:call(?MODULE, {set_debug, Debug}).

log(Text) ->
    gen_server:cast(?MODULE, {log, Text}).

debug(Text) ->
    gen_server:cast(?MODULE, {debug, Text}).


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

init([Filename]) ->
    file:write_file(Filename, "opened log\n"),
    {ok, #state {
        filename = Filename,
        debug_mode = false}}.

handle_call({set_debug, Debug}, _From, State) ->
    case Debug of
        true ->
            log("Enabled debug logging");
        _ ->
            log("Disabled debug logging")
    end,
    {reply, ok, State#state{debug_mode = Debug}}.

handle_cast({log, Text}, State = #state {filename = File}) ->
    file:write_file(File, Text ++ "\n", [append]),
    {noreply, State};
handle_cast({debug, Text}, State = #state {filename = File, debug_mode = Debug}) ->
    case Debug of
        true ->
            file:write_file(File, Text ++ "\n", [append]);
        _ -> []<commit_msg>Small changes to the log server.<commit_after>-module(log).
-behaviour(gen_server).

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

-export([start_link/1, set_debug/1, log/1, debug/1]).

-record(state, {
    filename,
    debug_mode}).


%% ===================================================================
%% API functions
%% ===================================================================

start_link(Filename) ->
    gen_server:start_link({local, ?MODULE}, ?MODULE, [Filename], []).

set_debug(Debug) when is_boolean(Debug) ->
    gen_server:call(?MODULE, {set_debug, Debug}).

log(Text) ->
    gen_server:cast(?MODULE, {log, Text}).

debug(Text) ->
    gen_server:cast(?MODULE, {debug, Text}).


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

init([Filename]) ->
    file:write_file(Filename, "opened log\n"),
    {ok, #state {
        filename = Filename,
        debug_mode = false}}.

handle_call({set_debug, Debug}, _From, State) ->
    case Debug of
        true ->
            log("enabled debug logging");
        _ ->
            log("disabled debug logging")
    end,
    {reply, ok, State#state{debug_mode = Debug}}.

handle_cast({log, Text}, State = #state {filename = File}) ->
    file:write_file(File, Text ++ "\n", [append]),
    {noreply, State};
handle_cast({debug, Text}, State = #state {filename = File, debug_mode = Debug}) ->
    case Debug of
        true ->
            file:write_file(File, Text ++ "\n", [append]);
        _ -> []
{'fraction_non_alphanumeric': 0.31483194572926304, 'fraction_numerical': 0.006167129201356768, 'mean_word_length': 3.907715582450832, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1912199', 'n_tokens_mistral': 974, 'n_tokens_neox': 915, 'n_words': 195}