I wrote a simple logger for a server I'm writing. Wondering if anyone has any suggestions to improve it. # doom_logger.erl -module(doom_logger). -author('Andrew McRobb'). -include("include/log_types.hrl"). -export([start/1, start/0, terminate/1, log/4, log/3, update_logger_state/3, get_local_time_string/0]). -record(logger_state, { file_pointer = null, write_to_stdout = true, write_to_file = true, file_path = "doom.log", output_level = ?LOG_TYPE_DEBUG }). start()-> start([]). start(Arguments)-> WriteToStdOutState = update_logger_state(#logger_state{}, Arguments, write_to_stdout), WriteToFileState = update_logger_state(WriteToStdOutState, Arguments, write_to_file), FilePathState = update_logger_state(WriteToFileState, Arguments, file_path), OutputLevelState = update_logger_state(FilePathState, Arguments, output_level), if OutputLevelState#logger_state.write_to_file -> case file:open(OutputLevelState#logger_state.file_path, [append, {encoding, utf8}, {delayed_write, 1, 1}]) of {ok, Device} -> {ok, OutputLevelState#logger_state{file_pointer=Device}}; Error -> Error end; true-> {ok, OutputLevelState} end. terminate(#logger_state{file_pointer=File})-> file:close(File). log(#logger_state{output_level=OutputLevel}, Type, _, _) when Type < OutputLevel -> ok; log(#logger_state{write_to_stdout=WriteToConsole, write_to_file=WriteToFile, file_pointer=FilePointer}, Type, Message, FormatList) when ?IS_LOG_TYPE(Type) -> case Type of ?LOG_TYPE_DEBUG-> TypeString = "DEBUG"; ?LOG_TYPE_MESSAGE-> TypeString = "MESSAGE"; ?LOG_TYPE_WARNING-> TypeString = "WARNING"; ?LOG_TYPE_ERROR-> TypeString = "ERROR"; _-> TypeString = "UNKOWN" end, FormatedMessage = binary_to_list(erlang:iolist_to_binary(io_lib:format(Message, FormatList))), OutputMessage = lists:concat(["[", TypeString, "] ", get_local_time_string(), " ", FormatedMessage, "\n"]), case WriteToFile of true -> file:write(FilePointer, OutputMessage); false-> ok end, case WriteToConsole of true -> case Type of warning -> io:format(standard_error, OutputMessage, []); error -> io:format(standard_error, OutputMessage, []); _-> io:fwrite(OutputMessage) end; false-> ok end, ok. log(State, Type, Message)-> ?MODULE:log(State, Type, Message, []). update_logger_state(State, Arguments, Key) -> case proplists:get_value(Key, Arguments) of undefined -> State; Value -> case Key of write_to_stdout-> if erlang:is_boolean(Value) -> State#logger_state{write_to_stdout=Value}; true-> State end; write_to_file-> if erlang:is_boolean(Value) -> State#logger_state{write_to_file=Value}; true-> State end; file_path-> if erlang:is_list(Value) -> State#logger_state{file_path=Value}; true-> State end; output_level-> if erlang:is_integer(Value) -> State#logger_state{output_level=Value}; true-> State end; _-> State end end. get_local_time_string() -> {{Year, Month, Day}, {Hours, Minutes, Seconds}} = calendar:local_time(), lists:concat([Year, "-", Month, "-", Day, " ", Hours, ":", Minutes, ":", Seconds]). # log_types.hrl -define(LOG_TYPE_DEBUG, 1). -define(LOG_TYPE_MESSAGE, 2). -define(LOG_TYPE_WARNING, 3). -define(LOG_TYPE_ERROR, 4). -define(IS_LOG_TYPE(V), ( V =:= ?LOG_TYPE_DEBUG orelse V =:= ?LOG_TYPE_MESSAGE orelse V =:= ?LOG_TYPE_WARNING orelse V =:= ?LOG_TYPE_ERROR )). # example start()-> {ok, L} = doom_logger:start([{write_to_file, false}, {output_level, ?LOG_TYPE_MESSAGE}]), doom_logger:log(L, ?LOG_TYPE_DEBUG, "I won't print output level set too high!"), doom_logger:log(L, ?LOG_TYPE_MESSAGE, "I sure will ~p!", ["print"]), doom_logger:terminate(). My only real concern is how I'm building the `#logger_state` with `update_logger_state/3`. I don't know if there really is a better way.