AEM Debugging with logs
Troubleshooting is the most important
part of AEM. So to help in troubleshooting, AEM provides out of the box log
files for different purposes:
1.
Request.log
2.
Access.log
3.
Stdout.log
4.
Stderr.log
5.
Audit.log
6.
History.log
7.
Error.log
8.
Upgrade.log
1. Request.log
This log file contains each request together
with response related to AEM instance. By this log file we can easily monitor
the performance of AEM instance.
Each request contains the following
information:
·
Method (GET, POST,HEAD,PUT,DELETE)
·
Resource Path (/content/we-retail/en.html)
·
Protocol (HTTP/1.1 or HTTPS)
Each response contains the following
information:
·
Status Code (404,200,401etc.)
·
MIME Type: (text/html, image/jpeg etc.)
·
Response Time (518 ms)
By analyzing, we can easily determine that
which request and response is taking too much time. By this we can increase
overall site performance.
1. Access.log
This log file is almost similar to
request.log. It helps us to know the
following things:
·
Who is accessing
·
Which resource is being accessed
·
At what time resource is being accessed
The requests in access.log is exactly half of request.log because the access.log
defines all the request and response in just one line.
Each line in Access.log contains the following information:
·
Access IP - The IP of that system from where the request is coming.
·
Access User - The user who is sending the request.
·
Access Time - At what time resource is being accessed.
·
Request Method- The method of the request like GET, POST, PUT etc.
·
Access Resource - The resource which is accessed by user.
·
Protocol like HTTP/1.1 or HTTPS
·
Response Status Code like - 404, 200, 401 etc.
·
Content Length - It determines the length of response content.
·
Referrer URL - The referrer is the web page
that sends visitors to your site using a link. In other words, it’s the web
page that a person was on right before they landed on your page.
·
User Agent-
It refers to a web browser telling a
website information about the browser and operating system.
2. Stdout.log:
This log file basically contains the startup
log. Here startup log means whenever any AEM instance created or started then
it will hold the information about AEM instance like the sling.home, Apache
sling etc.
Stdout.log is also useful to see the message given in java classes. This can be
done by using System.out.println();
Even we can also able to see the log messages related to
com.day.cq.mail.service.
This log file
contains error messages of varying levels of severity. Some AEM instance
related messages generated during startup Like: The JVM reports a heap size
of 3618 MB, meets our expectation of 1024 MB +/- 20 .
Note: By default the log level is set to Warning (WARN).
4. Audit.log
This log file
is used by Jackrabbit to log changes to the repository. By default this
log file is set to level info. There is not much logging going on at this level
because of which audit.log seems to be empty. If you set this log file
to log level debug you will see log messages every time you make changes to the
repository. For example if you add a component to a page, delete a page
etc.
5. History.log
This log file contains the
information about which action is performed on the content.
It contain high
level logs about the actions performed by editors (actions can be edit, view, delete etc).This log is probably only relevant on author
instances.
Each line contain the following information:
·
TimeStamp
·
Action
·
User
·
Content path
·
Content type(cq:page, dam:asset)
6. Upgrade.log
Provides a log
of all upgrade operations that runs from com.day.compat.code upgrade and
com.adobe.cq.upgradesexecutor package.By default, this log level is set to
info.
7. Error.log
Error messages
(of varying levels of severity like INFO, ERROR, DEBUG, etc.) are registered
here.
Hierarchy of log4j logging levels are as
follows in Highest to Lowest order:
·
TRACE
·
DEBUG
·
INFO
·
WARN
·
ERROR
Note: The high level logs contains all the logs of
lower levels like in case of Trace log level, it will include all the logs of
debug, info, warn and error as well.
As AEM provided
logs are not sufficient for us sometimes. We want separate logs for our
application, so that it will be easy to debug our code.
This is how to create custom loggers in AEM:
1. Go to felix
console configMgr.
2. Go to Apache
Sling Logging Logger Configuration.
3. Click on +
to Add a new configuration.
·
Log level: The log level defines which type of
logs you want to have in your custom log file for ex: trace, debug, info, warn,
error.
·
Log File: Here you can identify the name of
the log file, which needs to be created under the logs folder.
·
Message Pattern: The java.util.MessageFormat pattern
to use for formatting log messages with the root logger.
This is a java.util.MessageFormat pattern supporting up to six
arguments:
o
{0} The timestamp of type java.util.Date,
o
{1} the log marker,
o
{2} the name of the current thread,
o
{3} the name of the logger,
o
{4} the log level and
o
{5} the actual log message.
If the log call includes a Throwable, the stacktrace is just
appended to the message regardless of the pattern.
The Pattern can be like this: {0,date,dd.MM.yyyy HH:mm:ss.SSS}
*{4}* {2} {3}
{5}.
·
Logger: Here we define the package name of the application,for
which we want to print the logs.You can add multiple packages also.
·
Additivity: If set to false then logs from these
loggers would not be sent to any appender attached higher in the hierarchy.
Let's suppose we have one logging configuration for package “com.eclerxaem.*“ and we have created
one more logger for “com.eclerxaem.servlet.TestServlet”,
so by default the TestServlet loggers will not get printed in com.eclerxaem.* logger file but if you
enable the additivity then the loggers will go in both log files.
4. Go to Apache Sling Logging Writer Configuration.
5. Click on + to Add a new configuration.
·
Log File: Here you define the log file Name for
which you want to write a logging writer.
·
Number of Log Files: Here you can define how many logs
file you want to maintain for the specific Log File defined above.
·
Log File Threshold: Defines how the log file is rotated
(by schedule or by size) and when to rotate.Meaning you can define if you want
to rotate the log file on daily,weekly or monthly basis or on the basis of
size.
Log File Rotation
Log files can grow rather quickly and fill up available disk space.
To cope with this growth log files may be rotated in two ways: At specific
times or when the log file reaches a configurable size.
·
The first method is called Scheduled
Rotation and is used by specifying a SimpleDateFormat pattern as the log
file "size".
·
The second method is called Size
Rotation and is used by setting a maximum file size as the log file size.
Scheduled Rotation: The rolling
schedule is specified by setting the org.apache.sling.commons.log.file.size
property to a java.text.SimpleDateFormat pattern. It is possible to specify
monthly, weekly, half-daily, daily, hourly, or minutely rollover schedules. Check
this section to see available Scheduled Rotation.
Do not use the colon ":"
character anywhere in the pattern option. The text before the colon is
interpreted as the protocol specification of a URL which is probably not what
you want.
Size Rotation:Log file rotation by size is
specified by setting the org.apache.sling.commons.log.file.size property to a
plain number or a number plus a size multiplier.
The size multiplier may be any of K, KB, M, MB, G, or GB where
the case is ignored and the meaning is probably obvious.
Important to Know:
Apache Sling Logging logger Configuration is self sufficient to print
the log then the question can come in your mind, what is the need of Apache
Sling Logging Writer Configuration.
There is one more configuration in AEM, which is Apache Sling
Logging Configuration which can be considered a global configuration for
all log files.Here you define a few things like Number of Log Files,Log File
Threshold,Message Pattern etc.
If you don’t override your values in your application related
Logging Logger and Writer Configuration, it will take the value from Global.So
if you don't define writer configuration it will take Number of Log Files and
Threshold Message from global configuration.
Conclusion: if you really need any change in the two properties(Number
of log files and Threshold Message) defined in the logging Writer then only
create a writer configuration else no need.
There are two ways to see the log files in AEM.
1. Go to the felix console ->Sling->Log Support, and search for
your log file. You can directly open the log file from here.
2. The logs files also gets created under crx-quickstart/logs. You can open
your log files and see the logs.
No comments:
Post a Comment