Sunday, August 3, 2008

API changes in 0.8

I haven't got a lot of time to explain the API changes in 0.8. I'll get around to this task when possible. For now, I'll quickly introduce some changes.

In 0.7, Log4erl didn't have the concept of appender. For version 0.7, logger and appender where the same things. So, when you add a new logger with specific properties, you basically create a logger, add an appender with the properties. That's why version 0.7 had log4erl:add_file_logger/1,2 functions.

The biggest change in 0.8, is the separation of both. So now, you can create a logger and add as many appenders to it. Currently, there are only file_appender and dummy_appender. Dummy_appender is basically dumps all messages sent to it. It can be useful during development. An example for using the new API, the following code adds 2 appenders to the default logger, one is a file_appender and the other is dummy_appender.

> log4erl:add_appender({file_appeneder, appender1}, {"../logs", "logger1", {size, 100000}, 4, "elog", warn}).
> log4erl:add_appender({dummy_appender, dummy}, "").

As you can see above, developer is required to supply a tuple of name of the module and a name for the appender as the first agrument to add_appender/2. The 2nd item in the tuple is an identifier used by Log4erl. You can get all appenders for a logger using log4erl:get_appenders/0,1

Users can also use add_file_appender/2,3 and add_dummy_appender/2,3 as convenient functios for add_appender.

Another useful function in the API is change_log_level/1,2, by which users can change log level without having to restart Log4erl.

I hope this is useful for all of Log4erl 0.8 users. As I said, I'll get around to modifiying the manual in google code to reflect these changes. Until then, have a nice day :)