Permalink
Browse files

version 0.8.4 final

  • Loading branch information...
1 parent 66dd20e commit 8f5bd180c4b1df2d95d844a4b9724c8c8624c4f5 @ahmednawras ahmednawras committed Mar 1, 2009
Showing with 163 additions and 246 deletions.
  1. +10 −0 CHANGELOG.txt
  2. +10 −171 README.txt
  3. +1 −1 ebin/log4erl.app
  4. +5 −0 include/log4erl.hrl
  5. +16 −27 src/Makefile
  6. +1 −4 src/file_appender.erl
  7. +46 −27 src/log4erl.erl
  8. +1 −1 src/log4erl_sup.erl
  9. +57 −11 src/log_manager.erl
  10. +16 −4 src/logger_guard.erl
View
@@ -1,3 +1,13 @@
+log4erl 0.8.4:
+==============
+* Added smtp_appender (new functions add_smtp_appender/2,3)
+* Added change_level/2,3 for changing level of specific Appender
+* Immproved feedback in case of errors
+* Seperated API documentation into 2 files: API.txt & Appenders_API.txt.
+ The first includes general functions and the other includes appenders
+ specific API, such as file appenders and SMTP appenders API.
+* Created a github.com repository (http://github.com/ahmednawras/log4erl/).
+
log4erl 0.8.3:
==============
* Added console_appender
View
@@ -18,17 +18,21 @@ TOC:
- Support default logger if no logger specified
- 5 predifined log levels (debug, info, warn, error, fatal)
- Support for user-specified log levels
-- Support for simple log formatter (similar to Layouts in Log4J)
+- Support for a log formatter (similar to Layouts in Log4J)
- Support for console log
+- Support for smtp formatter
+- Support for changing format and level of appender during run-time
2. INSTALLATION:
================
To compile & install log4erl, download source from google code's website
-(http://code.google.com/p/log4erl/) or from svn:
+(http://code.google.com/p/log4erl/) or from svn:
$> svn checkout http://log4erl.googlecode.com/svn/trunk/ log4erl
+
+or from github public repository (http://github.com/ahmednawras/log4erl/).
+
$> cd log4erl
$> make
-or from github public repository.
or you can run the below from erlang shell:
@@ -55,13 +59,9 @@ you need to run:
> log4erl:add_logger(messages_log).
> log4erl:add_file_appender(messages_log, file_logs, Conf).
where Conf is the configuration file or erlang term describing how the log is to be handled
+ You can also add more types of appenders, which is explained in API.txt and Appneders_API.txt.
-4- Additionally, you can change format of file logs
-> log4erl:change_format(messages_log, file_logs, Format).
- where Format is formatting string as described in API. Note that you can also set the format
- in the Conf tuple in log4erl:add_file_appender.
-
-5- Now, you can log whatever messages you like as per logging functions described in API.
+4- Now, you can log whatever messages you like as per logging functions described in API.
Precedance of log levels are:
all = debug < info < warn < error < fatal < none
@@ -70,168 +70,7 @@ User defined levels are always written except when none level is specified in th
4. API:
=======
-NOTE:
------
-Please be informed that the API below as of now is not stable and any of the functions/parameters below
-may be changed without prior notice.
-
-**> log4erl:add_logger(Name) -> ok | {error, E}
- Name :: atom() name of the logger
-
- Example:
- log4erl:add_logger(chat_logger)
- This will create a new logger with name 'chat_logger"
-
-**> log4erl:add_file_appender(Name, Spec) -> ok | {error, E}
- Name :: atom() name of the appender. This value will be used
- to uniquely references this file appender and can be used to
- change log level and format of the appended file. This appender
- will be added to the default_logger
-
- Spec :: tuple() of the form
- {LogDir, LogFileName, {size, Size}, NumOfRotations, Suffix, LogLevel}
- or
- {LogDir, LogFileName, {size, Size}, NumOfRotations, Suffix, LogLevel, Format}
- This tuple defines the appender's attributes.
-
- Example:
- log4erl:add_file_appender(chat_room1, {"../logs", "room1", {size, 100000}, 4, "txt", warn}).
- This will directs log4erl to create a file appender and add it to the default
- logger. all log messages towards default logger will be written to file
- "../logs/room1.txt". The file will have a 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 will not be written. Format is a list of specifiers. The meanin of these
- specifiers can be found in description of log4erl:change_format/2 below.
-
- 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, Appender, SpecFile) -> ok
- Logger :: atom()
- Appender :: atom()
-
- This will create a new appender and associate spec in Spec or in SpecFile to it. Spec and
- content of SpecFile are the same as in add_file_appender/2
-
- Example:
- log4erl:add_file_appender(chat_log, file_logger, "../priv/chat_logs.conf").
- This will add another logger with the name "chat_log" and use configuration in
- the file "../priv/chat_logs.conf" for it. To write to this log, you need to specify
- the name of the logger.
-
-**> log4erl:add_console_appender(Appender, Spec) -> ok
- log4erl:add_console_appender(Logger, Appender, Spec) -> ok
- Logger :: atom()
- Appender :: atom()
- Spec :: tuple()
-
- This will create a new console appender to either Logger or default logger and associate spec in Spec to it.
- Spec is in the form {Level, Format}, which means exactly as it is in file_appender Spec
-
- Example:
- log4erl:add_console_appender(cmd_logs, {info, "%j %T [%L] %l%n"}).
-
-**> log4erl:change_log_level(Level) -> ok
- log4erl:change_log_level(Logger, Level) -> ok
- Level::atom() = {all, debug, info, error, warn, fatal, none}
- Logger::atom()
-
- This will change log level for default logger or named logger to the level
- specified.
-
- Example:
- log4erl:change_log_level(info). %% This will change level of default logger to info
- log4erl:change_log_level(test_log, warn) %% This will change level of test_log logger to warn
-
-**> log4erl:change_format(Appender, Format) -> ok
- log4erl:change_format(Logger, Appender, Format) -> ok
- Appender :: atom()
- Logger :: atom()
- Format :: string()
-
- @since version 0.8.3
-
- This will change the output format to the specified Format. Format is a pattern string similar to
- PatternLayout in Log4j. patterns is an arbitrary string with specifiers (proceeded by '%').
- 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,811637)
- y - year in YY format (08)
- Y - year in YYYY format (2008)
- M - month (2)
- b - short name of month (Feb)
- B - long name of month (February)
- D - day
- h - hour
- m - minute
- s - second
- i - milli-seconds
- l - the actual log message
- L - log level
- n - new line
- % - the percentage sign (%)
-
- Example:
- 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,98621 [warn] hello
-
-**> 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:
- 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").
+Please look at API.txt file for more information about the API.
5. KNOWN ISSUES:
================
View
@@ -2,7 +2,7 @@
%% application.
{application, log4erl,
[{description, "Logger for erlang in the spirit of Log4J"},
- {vsn, "0.8.3"},
+ {vsn, "0.8.4"},
{modules, [log4erl]},
{registered,[log4erl]},
{applications, [kernel,stdlib]},
View
@@ -42,5 +42,10 @@
-record(rotation_state, {state, timer}).
+-record(smtp_appender, {level, srvr_opts, auth_opts, msg_opts}).
+-record(srvr_opts, {ip, port}).
+-record(auth_opts, {username, password}).
+-record(msg_opts, {from, to, title, msg}).
+
%% log record
-record(log, {level, msg, data, time, millis}).
View
@@ -1,46 +1,35 @@
+EBIN_DIR=../ebin
+INCLUDE_DIR=../include
+ERLS=$(wildcard *.erl)
+ERLC=erlc -o $(EBIN_DIR) -I ${INCLUDE_DIR}
+BEAMS=$(ERLS:.erl=.beam)
+
# leave these lines alone
.SUFFIXES: .erl .beam .yrl
.erl.beam:
- erlc -o $(EBIN_DIR) -W $<
+ $(ERLC) -W $<
.yrl.erl:
- erlc -o $(EBIN_DIR) -W $<
+ $(ERLC)-W $<
-SOURCE_DIR=src
-EBIN_DIR=../ebin
-INCLUDE_DIR=include
-#SRC=$(wildcard $(SOURCE_DIR)/*)
-ERL = erl -o $(EBIN_DIR) -I ${INCLUDE_DIR}
-SRC = src
# Here's a list of the erlang modules you want compiling
# If the modules don't fit onto one line add a \ character
# to the end of the line and continue on the next line
# Edit the lines below
-MODS = log4erl_sup log4erl file_appender console_appender log_manager logger_guard log4erl_utils dummy_appender log_formatter
+#MODS = log4erl_sup log4erl file_appender console_appender log_manager logger_guard log4erl_utils dummy_appender log_formatter smtp_fsm.erl email_msg.erl
+#MODS = $(ERLS)
+BEAMS = $(ERLS:.erl=.beam)
+MODS = $(BEAMS:.beam=)
all: compile
-#compile: ${MODS:%=%.beam} #application
-#compile: ${SRC}/${MODS:%=%.beam}
-compile: ${MODS:%=%.beam}
+%.beam: %.erl
+ @echo ">>" compiling: $<
+ @$(ERLC) $<
-## special compilation requirements are added here
-#.beam:
-# ${ERL} -W0 *.erl
-
-application: compile
-# ${ERL} -pa ebin -o ${EBIN_DIR} -s application start Arg1 Arg2
-
-run:
- ${ERL} -pa ebin -s test test
-# the subdirs target compiles any code in
-# sub-directories
-#subdirs:
-# cd dir1; make
+compile: ${MODS:%=%.beam}
-# remove all the code
clean:
rm -rf ../ebin/*.beam erl_crash.dump
-# cd dir1; make clean
View
@@ -47,10 +47,7 @@ init(Conf) when is_list(Conf) ->
{error, file:format_error(Reason)};
{ok, [Terms]} ->
init(Terms)
- end;
-init(_N) ->
- ?LOG2("file_appender:init() with parameter ~p~n",[_N]),
- {ok, #file_appender{}}.
+ end.
handle_event({change_level, Level}, State) ->
State2 = State#file_appender{level = Level},
Oops, something went wrong.

0 comments on commit 8f5bd18

Please sign in to comment.