|
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:
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:
$> cp -Rf log4erl /usr/local/lib/erlang/lib/
$> erl -pz /path/to/log4erl ...
$> erl 1> application:start(log4erl). %% Start log4erl 2> log4erl:add_logger(Logger). %% Add a logger in case you need more than 1 3> log4erl:add_file_appender(Name, Spec). %% This will add a file appender with Name to defautl logger %% and associate Spec to the appender %% Spec could be the specification for appender (see below) %% or a text file with the specification || log4erl:add_file_appender(Logger, Name, Spec). %% This will add a file appender with Name to Logger %% and associate Spec to the appender %% Spec could be the specification for appender (see below) %% or a text file with the specification 4> log4erl:log(Level, Log, Data). %% Log to the default logger || log4erl:log(Logger, Level, Log, Data). %% Log to Logger
API:
**> log4erl:add_logger(Logger) -> ok Logger :: atom() This will create a new logger Example:log4erl:add_logger(messages_log).
**> log4erl:add_file_appender(Name, Spec) -> ok
Name :: atom()
Spec :: string() || {LogDir, LogFileName, {size, Size}, NumOfRotations, Suffix, LogLevel}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:
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
**> log4erl:add_file_appender(Logger, Name, Spec) -> ok
Logger :: atom()
Name :: atom()
Spec :: string() || {LogDir, LogFileName, {size, Size}, NumOfRotations, Suffix, LogLevel}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").
**> log4erl:change_log_level(Level) -> ok
Level :: warn | info | error | fatal | debugThis will change log level for the default logger to Level Exmaple:log4erl:change_log_level(debug).
**> log4erl:change_log_level(Logger, Level) -> ok Logger :: atom() Level :: warn | info | error | fatal | debug This will change log level for Logger to Level Exmaple:log4erl:change_log_level(msgs_logger, debug).
**> log4erl:change_format(Appender, Format) -> ok Appender :: atom() Format :: string() 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(Logger, Appender, Format) -> ok Logger :: atom() Appender :: atom() Format :: string() 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:get_appenders() -> [Appender]
Appender :: {Type, Name}
Type :: atom()
Name :: atom()This will return a list of all appenders added to the default logger. Exmaple:
**> log4erl:get_appenders(Logger) -> [Appender]
Logger :: atom()
Appender :: {Type, Name}
Type :: atom()
Name :: atom()This will return a list of all appenders added to Logger. Exmaple:
**> log4erl:log(Level, Log) -> ok
Level :: atom()
Log :: string()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").
**> log4erl:log(Level, Log, Data) -> ok
Level :: atom()
Log :: string()
Data :: list()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]).
**> log4erl:log(Logger, Level, Log, Data) -> ok
Logger :: atom()
Level :: atom()
Log :: string()
Data :: list()This will log the (Log, Data) to Logger with level Level Example:log4erl:log(chat_log, debug, "user entered chat text: ~p", [Chat]).
**> log4erl:Level(Log) -> ok
log4erl:Level(Log, Data) -> ok
log4erl:Level(Logger, Data) -> ok
log4erl:Level(Logger, Log, Data) -> ok
Level :: warn | info | error | fatal | debug
Logger :: atom()
Log :: string()
Data :: list()Exmaple:
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. |
Sign in to add a comment
Great job... Thank you.
kunthar,
Thanks for support. Please let me know if you have feedback.
Ahmed
Nice, Great job.
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