Skip to content

Commit

Permalink
version 0.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmednawras committed Mar 24, 2009
1 parent 7b68ed5 commit 497b774
Show file tree
Hide file tree
Showing 21 changed files with 1,872 additions and 50 deletions.
16 changes: 12 additions & 4 deletions API.txt
Expand Up @@ -3,7 +3,12 @@ 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.

Furthermore, you can find the appenders
Furthermore, you can find appenders and their configurations in 'Appenders_API.txt' file included in release.

**> log4erl:conf(File) -> ok | {error, E}
File :: string()

File is the name of the configuration file. Please check CONFIGURATION.txt for the format of this file.

**> log4erl:add_logger(Name) -> ok | {error, E}
Name :: atom() name of the logger
Expand Down Expand Up @@ -49,10 +54,10 @@ Furthermore, you can find the appenders
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)
d - output date (2008-3-7)
j - output date (2008-03-07)
t - time (2:13:9)
T - time (02:28:01,811637)
T - time (02:28:01.811637)
y - year in YY format (08)
Y - year in YYYY format (2008)
M - month (2)
Expand All @@ -64,6 +69,9 @@ Furthermore, you can find the appenders
s - second
i - milli-seconds
l - the actual log message
I - ISO format with universal GMT time (equivilant to "%jT%TZ").
S - ISO format with local time and time zone offset
Z - timezone (+04:00)
L - log level
n - new line
% - the percentage sign (%)
Expand Down
41 changes: 40 additions & 1 deletion Appenders_API.txt
Expand Up @@ -8,7 +8,8 @@
{LogDir, LogFileName, {size, Size}, NumOfRotations, Suffix, LogLevel}
or
{LogDir, LogFileName, {size, Size}, NumOfRotations, Suffix, LogLevel, Format}
This tuple defines the appender's attributes.
This tuple defines the appender's attributes.
If Format is not specified, the default format is "[%L] %l%n".

Example:
log4erl:add_file_appender(chat_room1, {"../logs", "room1", {size, 100000}, 4, "txt", warn}).
Expand Down Expand Up @@ -87,3 +88,41 @@
<warn - 01-03-2009 12:21:09,818534
test smtp appender>

**> log4erl:add_syslog_appender(Appender, Spec) -> ok
log4erl:add_syslog_appender(Logger, Appender, Spec) -> ok
Logger :: atom()
Appender :: atom()
Spec :: tuple() | list()

@since version 0.8.5

This will create a new syslog appender to either Logger of default logger and initialize it to spec in Spec or
file named Spec if Spec is a list. Spec is in the below form. MsgFormat is the format of the message and it
has the same meaning as the format of Format in add_file_logger/2,3.

Note: In for syslog_appender to work, you need to enable syslogd to accept network messages. In linux, you
need to use '-r' switch when running syslogd.

Spec =
{Level, Fac} |
{Level, Fac, Host} |
{Level, Fac, Host, Format} |
{Level, Fac, Host, Port, Format}
where:
Level = atom()
Fac = atom()
Host = string() | tuple()
Port = integer()
Format = string()

Example:
log4erl:add_syslog_appender(appender1, {warn, user, "syslog_srvr", "(%L) - %S %l%n"}}).

This will create a syslog_appender called appender1 with level 'warn' and uses 'user' facility.
The appender will connect to host "syslog_srvr" with default port (514). The messages will be
formatted according to the format "%L - %j %T %n %l%n".

Default host is "localhost".
Default port is 514.
Default Format is the same as default format of file_appender

7 changes: 7 additions & 0 deletions CHANGELOG.txt
@@ -1,3 +1,10 @@
log4erl 0.8.5:
==============
* Added new file configuration (log4erl:conf(File)).
* Added syslog_appender.
* Added support for ISO standard format to appenders (%I, %S & %Z specifiers).
* Changed %d & %j to output the date in YYYY-MM-DD format according to ISO standard format

log4erl 0.8.4:
==============
* Added smtp_appender (new functions add_smtp_appender/2,3)
Expand Down
99 changes: 99 additions & 0 deletions CONFIGURATION.txt
@@ -0,0 +1,99 @@
Configuration Guide:
====================

TOC:
====
* Introduction
* Loggers
- Example
* Appenders
- common properties
- file_appender
- console_appender
- smtp_appender
- syslog_appender

Introduction:
=============
This document explains the format of log4erl configuarion file. The configuration file is simple
and easy to write. At any place in the file, any thing you type after '%' is a comment.
You can find a sample configuration in the file 'log4erl.conf' under 'priv' directory.

* Loggers:
==========
It contains a list of logs with the format below, where
<name> is any name you'd like to call it. <name> can later on be used with any of the log messages
in log4erl API (e.g. log4erl:info/2,3,4). If no value for <name> exists or value of "default" suplied,
then the elements inside '{' and '}' will be applied to the default logger.

logger [<name>] {
...
}

Example:
--------
logger application_logger{
...
}

%% default logger
logger {
...
}

* Appenders:
============
Inside each logger, there can be 1 or more appenders. These appenders can be
added inside loggers according to the format below.

<appender_type> <name> {
...
}

Example:
--------
file_appender file1{
...
}

insider appenders' block, you can add properties for that appender in the format 'property=value'.
Multiple properties are seperated by a comman ','Each appender type has different sets of properties,
which are detailed below.

common properties:
------------------
level = <Level> => level of log (e.g. warn)
format = <F> => format of the output (look at 'Appenders.txt')

file_appender:
--------------
dir = <Dir> => directory of output (e.g. /var/log/my_app)
file = <File> => name of the log file (e.g. my_app_log)
type = <Type> => either size or time. Only size is implemented currently
max = <Max> => Maximum size of each rotation
suffix = <Suf> => Suffix of the log file (e.g. log)
rotation = <R> => number of rotations before over-writing log files

console_appender:
-----------------
Nothing more than common properties.

smtp_appender:
--------------
ip = <IP> => ip of the SMTP server
port = <Port> => SMTP prot [Optional]
no_auth = true|false => if specified, no authentication is performed even if
username or password below is provided
username = <U> => SMTP username
password = <P> => SMTP password
from = <From> => value of the From field [Optional]
to = <To> => email to send to
title = <T> => title of email [Optional]
msg = <Format> => format of the email message [Optional]

syslog_appender:
----------------
facility = <F> => Facility to be used (e.g. ftp)
host = <H> => Host to send syslog messages to [Optional]
port = <P> => syslog port [Optioanl]

30 changes: 20 additions & 10 deletions README.txt
Expand Up @@ -7,9 +7,10 @@ TOC:
2. Installation
3. Usage
4. API
5. Known issues
6. Future development
7. License
5. Configuration
6. Known issues
7. Future development
8. License

1. FEATURES:
============
Expand Down Expand Up @@ -55,13 +56,18 @@ $> erl -pz /path/to/log4erl ...
you need to run:
> application:start(log4erl).

3- Create loggers & add appenders to them as appropriate. You can do this as per the API below.
3- Create a configuration file and load it using log4erl:conf(File)
> log4erl:conf("priv/log4erl.conf").

4- Alternatevly, you can create loggers & add appenders to them programmatically as appropriate.
You can do this as per the API below.
> 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
> log4erl:add_console_appender(messages_log, cmd_logs, {warn, "[%L] %l%n"}).
where Conf is the 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- Now, you can log whatever messages you like as per logging functions described in API.
5- Now, you can log whatever messages you like as per logging functions described in API.
> log4erl:info("Information message").

Precedance of log levels are:
all = debug < info < warn < error < fatal < none
Expand All @@ -72,14 +78,18 @@ User defined levels are always written except when none level is specified in th
=======
Please look at API.txt file for more information about the API.

5. KNOWN ISSUES:
5. CONFIGURATION:
=================
Please look at CONFIGURATION.txt for more information about how to configure log4erl.

6. KNOWN ISSUES:
================
- Name of both loggers & appenders should be unique and not registered since log4erl will try and register
their names. If the name is already registered, nothing will happen. This will be fixed soon.
- If you run change_log_format/1,2 and appender crashed, a restart from the supervisor will not record the latest
format used. It will only use either the default format or the format used in the argument is supplied.

6. FUTURE DEVELOPMENT:
7. FUTURE DEVELOPMENT:
======================
- Add support for extensive file-based configuration
- Add support for different log persistance methods (e.g files, XML, console, DB, SNMP, syslog...etc)
Expand All @@ -89,7 +99,7 @@ Please look at API.txt file for more information about the API.

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

7. LICENSE:
8. 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
Expand Down
6 changes: 3 additions & 3 deletions TODO.txt
Expand Up @@ -7,12 +7,12 @@ default formatting patters [DONE]
* Update manual [DONE (latest for log4erl 0.8.2)]
* Add performance benchmarks
* Add support for file-based configuration to log4erl instead of only
programmable-only configuration that is working now
programmable-only configuration that is working now [DONE]
* Add support for SNMP appender
* Add support for DB appender (MySQL, Postgres?, Mnesia,...etc)
* Add support for SMTP appender
* Add support for SMTP appender [DONE]
* Add support for NT event appender
* Add support for syslog appender
* Add support for syslog appender [DONE]
* Add support for NDC/MDC
* Add support for time-based log rotation (file_appender)

2 changes: 1 addition & 1 deletion ebin/log4erl.app
Expand Up @@ -2,7 +2,7 @@
%% application.
{application, log4erl,
[{description, "Logger for erlang in the spirit of Log4J"},
{vsn, "0.8.4"},
{vsn, "0.8.5"},
{modules, [log4erl]},
{registered,[log4erl]},
{applications, [kernel,stdlib]},
Expand Down
10 changes: 6 additions & 4 deletions include/log4erl.hrl
Expand Up @@ -36,16 +36,18 @@
%% The filename of a log is file_name ++ "_" ++ counter ++ "." ++ suffix
%% e.g. log_1.txt
%% tokens = format tokens generated from log_formatter:parse/1
-record(file_appender, {dir, file_name, fd, counter, log_type, rotation, suffix, level, format}).
-record(file_appender, {dir, file_name, fd, counter, log_type, rotation, suffix, level, format=?DEFAULT_FORMAT}).

-record(console_appender, {level, format}).
-record(console_appender, {level=?DEFAULT_LEVEL, format=?DEFAULT_FORMAT}).

-record(rotation_state, {state, timer}).

-record(smtp_appender, {level, srvr_opts, auth_opts, msg_opts}).
-record(smtp_appender, {level=?DEFAULT_LEVEL, srvr_opts, auth_opts, msg_opts}).
-record(srvr_opts, {ip, port}).
-record(auth_opts, {username, password}).
-record(msg_opts, {from, to, title, msg}).
-record(msg_opts, {from, to, title, msg=?DEFAULT_FORMAT}).

-record(syslog_appender, {level=?DEFAULT_LEVEL, facility=user,host,port=415, socket, format=?DEFAULT_FORMAT}).

%% log record
-record(log, {level, msg, data, time, millis}).
4 changes: 2 additions & 2 deletions src/Makefile
Expand Up @@ -10,8 +10,8 @@ BEAMS=$(ERLS:.erl=.beam)
.erl.beam:
$(ERLC) -W $<

.yrl.erl:
$(ERLC)-W $<
#.yrl.erl:
# $(ERLC)-W $<


# Here's a list of the erlang modules you want compiling
Expand Down
16 changes: 16 additions & 0 deletions src/console_appender.erl
Expand Up @@ -7,6 +7,22 @@
-export([init/1, handle_event/2, handle_call/2,
handle_info/2, terminate/2, code_change/3]).

init({conf, Conf}) when is_list(Conf) ->
CL = lists:foldl(fun(X, List) ->
[proplists:get_value(X,Conf)|List]
end,
[],
[level, format]),

%% in case format doesn't exist
Res = case hd(CL) of
undefined ->
[_|CL2] = CL,
lists:reverse(CL2);
_ ->
lists:reverse(CL)
end,
init(list_to_tuple(Res));
init({Level}) ->
init({Level, ?DEFAULT_FORMAT});
init({Level, Format} = _Args) ->
Expand Down

0 comments on commit 497b774

Please sign in to comment.