e_logger
Overview
e_logger is a cross-framework logging facility that allows developers to keep track what, when, from and with what result has been called during the request processing phase. Apart of some built-in logging points e_logger provides an API that gives the programmers a possibility to log some extra data.
Together with e_logger e_logger_viewer is provided: a utility for browsing and filtering the logged messages.
e_logger API
The logger functionality is extremely simple - it provides only one function: e_logger:log/1 which accepts an arbitrary Erlang term. The passed message will be logged into the system for future analysis.
For example, if we want to log someones activity in our controller's function:
1 read(Id) ->
2 e_logger:log({?MODULE, read_request, Id}),
3 wtype_blog:read(Id),
4
5 {template, "/blog/post/post.html"}.
Logging process and built-in logging points
In order to provide user a convenient way to trace its logs, the logging process starts with establishing a mapping between servant process ID and a request ID. From now, each log request will be associated with the registered request ID, so it will be possible to check the log messages only from the interesting particular RID.
Here is a list of the built-in logging points:
e_mod_inets & e_mod_yaws - in parsing the parameters sent to the server (POST + GET)
e_mod_inets & e_mod_yaws - after retrieving URL
e_mod_gen - in case of using old URL naming conventions (see skipping dispatcher section)
e_dispatcher - after specifying the dispatcher result
e_mod_gen - when entering the dataflow list
e_mod_gen - when skipping the dataflow list and entering validate/1 branch
e_mod_gen - when skipping both: the dataflow list and validate branch and accessing the controller directly
e_mod_gen - when using the dataflow - after obtaining the dataflow list
e_mod_gen - when using the dataflow - after retrieving the arguments read by dispatcher
e_mod_gen - after controller response
e_cache - when accessing the HTML template file
Configuring e_logger
Configuration of the e_logger could be done by modifying the project.conf file. The following entries are acceptable by logger:
key |
value |
default value |
description |
example |
{logger, log_dir} |
LogDir :: string() |
"log" |
specifies in which directory logs should be kept |
{{logger, log_dir}, "/var/log/erlangweb_logs/"} |
{logger, max_files} |
N :: integer() |
5 |
sets the maximum number of the log files |
{{logger, max_files}, 10} |
{logger, max_entries} |
N :: integer() |
1024 |
sets the maximum number of log entries per file. When logger saves the Nth message (where N is the maximum number of the entries) it will change the logging file. When the last file has been reached, the logs will wrap. |
{{logger, max_entries}, 100} |
{logger, enabled} |
true | false |
true |
enables/disables the logger |
{{logger, enabled}, false} |
The e_logger logs will be saved inside the log_dir directory with the names starting with e_logger.log. and being suffixed with the log number (e.g. e_logger.log.3 for third log file).
e_logger_viewer
In order to browse the logs, the e_logger_viewer is shipped. Its aim is to read the logs created by e_logger and filter them by RID (request ID).
To start the viewer run e_logger_viewer:start().
Then, the logs should be read. It could be done by running one of the following commands:
e_logger_viewer:read_log_dir() - will read the logs from the directory set in the project.conf file
e_logger_viewer:read_log_dir(Dir) - will read the logs from user-provided directory
e_logger_viewer:read_log_file(File) - will read only the requested log file
After logs are read we are able to list all of the log entries: e_logger_viewer:list() or list the logs only with the particular RID: e_logger_viewer:list(RID).
Moreover, it is possible to set the mode of the viewer. By default the mode is set to shell what means the results will be printed on the shell. In order to get a bare list of logs (in format {RID, Timestamp, Message}) mode should be switched to list: e_logger_viewer:set_mode(list)}.
To clean the viewer's memory run e_logger_viewer:clean().
The shutdown of the logger viewer could be done by triggering e_logger_viewer:stop().
