My favorites | Sign in
Project Logo
             
Search
for
Updated Mar 09, 2009 by ahmed.nawras
Labels: Featured, log4erl0.8
Log4erl_Manual_2  

Log4erl v. 0.8 Manual:

Note:

This manual is not up to date and doesn't cover changes for releases after version 0.8.2. For the latest documentation, please check files README.txt and CHANGELOG.txt that comes with latest releases. However, all information mentioned here do apply for later versions.


Table Of Contents:

  1. Features
  2. Installation
  3. Usage
  4. API
  5. Future development
  6. License

FEATURES:


INSTALLATION:

To compile & install log4erl, download source from google code's website http://code.google.com/p/log4erl/ or from svn:

$> svn checkout http://log4erl.googlecode.com/svn/trunk/ log4erl
$> cd log4erl
$> make

or you can run the below from erlang shell:

$> cd src
$> erl
1> make:all([{outdir, "../ebin"}]).

USAGE:

  1. include the "log4erl" directory in erlang's "lib" directory in the target machine (cp -Rf log4erl /where/erlang/is/lib).
  2. $> cp -Rf log4erl /usr/local/lib/erlang/lib/
  1. include the "log4erl" ebin directory in the path when running you program
  2. $> erl -pz /path/to/log4erl ...

API:

This will create a new logger
Example:
  log4erl:add_logger(messages_log).
This will add a new file_appender to the default logger. The specification of the file logger is in the term Spec or the term saved in file Spec.

Example:

   log4erl:add_file_appender(file, {"../logs", "logger1", {size, 100000}, 4, "elog", warn}).
|| log4erl:add_file_appender(file, "log.conf").
where the content of "log.conf" is:
{"../logs", "logger1", {size, 100000}, 4, "elog", warn}
This will inform log4erl to add a file appender to write all logs to default loggers to "../logs/logger1.elog". The file logger will have size limit of 100000, after which the file will be rotated for 4 times. The log level will be warn, which means info & debug messages are not written.
After suffeciantly long time, the directory "../logs" will look like this:
  $> ls -l
  -rw-rw-r--  1 ahmed ahmed 103845 Jun 25 11:41 logger1_2.elog
  -rw-rw-r--  1 ahmed ahmed 102095 Jun 25 11:41 logger1_3.elog
  -rw-rw-r--  1 ahmed ahmed 106435 Jun 25 11:41 logger1_4.elog
  -rw-rw-r--  1 ahmed ahmed 103390 Jun 25 11:41 logger1_1.elog
  -rw-rw-r--  1 ahmed ahmed   7385 Jun 25 11:41 logger1.elog
This produces the same result as log4erl:add_file_appender/2 except that it adds the appender to Logger instead of the default logger

Example:

  log4erl:add_file_appender(messages_logger, file1, "msg_log.conf").
This will change log level for the default logger to Level
Exmaple:
  log4erl:change_log_level(debug).
This will change log level for Logger to Level
Exmaple:
  log4erl:change_log_level(msgs_logger, debug).
This will change log format of the appender to Format. Format is a pattern string similar to PatternLayout in Log4j. patterns is an arbitrary string with specifiers (proceeded by '%').
The default format is: %L %l%n
Possible specifiers are below:
d - output date (1-2-2008)
j - output date (01-02-2008)
t - time (2:13:9)
T - time (02:28:01)
y - year in YY format (08)
Y - year in YYYY format (2008)
M - month
D - day
h - hour
m - minute
s - second
l - the actual log message
L - log level
n - new line
% - the percentage sign (%)
Exmaple:
   log4erl:change_format(file1, "%j %T [%L] %l%n").
   Will result in the following output (on log4erl:warn("hello"))
   
  27-10-2008 15:28:59 [warn] hello
This will change log format of the appender Appender in Logger to Format. The result is the same as log4erl:change_format/2

Exmaple:

  log4erl:change_format(msgs_logger, file1, "%j %T [%L] %l%n").
  Will result in the following output (on log4erl:warn(msgs_logger, "hello"))
     
  27-10-2008 15:28:59 [warn] hello
This will return a list of all appenders added to the default logger.
Exmaple:
   log4erl:get_appenders()
   [{file_appender, file1}]
This will return a list of all appenders added to Logger.
Exmaple:
   log4erl:get_appenders(msgs_logger)
   [{file_appender, file1}]
This will log the text Log to the default logger with level Level.
Example:
  log4erl:log(warn, "Hello there").
  log4erl:log(test_level, "Hello there").
This will log the text Log to the default logger with level Level and will use Data to format the log text.
Example:
  log4erl:log(info, "received message ~p", [Msg]).
This will log the (Log, Data) to Logger with level Level
Example:
  log4erl:log(chat_log, debug, "user entered chat text: ~p", [Chat]).
Exmaple:
  log4erl:info("This is an info msg").
  log4erl:warn("Received error ~p",[Msg]).
  log4erl:fatal(chat_log, "exception occured").
  log4erl:debug(chat_log, "message received is ~p", [Msg]).
  log4erl:error("Error").

FUTURE DEVELOPMENT:

Please send your suggestion to ahmed.nawras <at @ at> gmail <dot . dot> com


LICENSE:

This software is subject to "Mozilla Public License 1.1". You can find the license terms in the file 'LICENSE.txt' shipping along with the source code. You may also get a copy of the license term from the URL: http://www.mozilla.org/MPL/MPL-1.1.html.


Comment by kunthar, Mar 01, 2009

Great job... Thank you.

Comment by ahmed.nawras, Mar 29, 2009

kunthar,

Thanks for support. Please let me know if you have feedback.

Ahmed

Comment by Pisces.Shim, Apr 28, 2009

Nice, Great job.

Comment by ahmed.nawras, May 02, 2009

Thanks Pisces. Check documentation that comes with log4erl latest release to see how to use the latest features. Let me know if you have any comments.

Ahmed


Sign in to add a comment
Hosted by Google Code