[erlang-questions] Newbie MySQL driver question

Yariv Sadan yarivvv@REDACTED
Wed Oct 4 20:54:56 CEST 2006


Hi,

This is an area of the documentation I need to clarify.

The revamped driver has a different logging function from the old
driver. It looks like this:

log(Module::atom(), Line::integer(), Level::atom(), Fun::function()).

Module: name of module
Line: line number
Level: debug | warn | error
Fun: a function that returns {Msg::string(), Params::[Param]}

The default log function is implemented as follows:

log(Module, Line, _Level, FormatFun) ->
    {Format, Arguments} = FormatFun(),
    io:format("~w:~b: "++ Format ++ "~n", [Module, Line] ++ Arguments).

The reason for this interface is that it gives you control over  what
level of logging messages are instantiated, not just displayed. This
can significantly lower the cost of logging, especially when debug
logging is turned off (at the expense of a small overhead of the
function call).

To make life easier, the MySQL driver uses the following macros:

-define(Log(LogFun,Level,Msg),
        LogFun(?MODULE,?LINE,Level,fun()-> {Msg,[]} end)).
-define(Log2(LogFun,Level,Msg,Params),
        LogFun(?MODULE,?LINE,Level,fun()-> {Msg,Params} end)).

(Btw, it just struck me that having explicit parameters for the module
name and line number is unnecessary because they can be added to the
list of parameters -- I guess I didn't notice it earlier because I
always use those macros... :-/ ).

I hope this makes sense. Let me know if you have any problems.

BR
Yariv



On 10/4/06, Todd Gruben <tgruben@REDACTED> wrote:
> Ok so let me preface this question with the fact that this is my first
> erlang application.  I have downloaded the "Re-vamped" mysql driver and have
> successully ran the test code connecting to my database.  My eventual goal
> is to query a whole cluster of databases via an erlang/web services
> interface.  Below is a chunk out of my test module:
>
> log_it(Level,Fmt,Args) ->
>     io:format(Fmt,Args).
>
> test() ->
>
> crypto:start(),
> io:format("Starting ~n"),
>
> {ok,p1} = mysql_conn:start("127.0.0.1 ", 7771,"dummy_user", "EASY_PASSWORD",
> "dbFIRST_DB",   log_it  ),
>  io:format("Phase 1 ~n"),
>
> ----------------------------------------
>
> i get the following message when i try and run test()
> -----------------------------------------
> =ERROR REPORT==== 4-Oct-2006::11:30:44 ===
> Error in process <0.39.0> with exit value:
> {function_clause,[{mysql_conn,do_recv,[log_it,<0.40.0>,undefined]},{mysql_conn,mysql_init,5},{mysql_conn,init,7}]}
> ----------------------------------------
> I am thinking this is an error in construction of my log_it function.  Any
> idea's what I am missing?
>
> thanks
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
>



More information about the erlang-questions mailing list