Testing - Log4J
Testing - Log4J
Topic: Log4J
====================================================
1. Document prepared by: Rajat Verma
a. https://www.linkedin.com/in/rajat-v-3b0685128/
b. https://github.com/rajatt95
c. https://rajatt95.github.io/
------------------------------------------------------------------------------------------------------------------------------
====================== Testing - Log4J ======================
------------------------------------------------------------------------------------------------------------------------------
Log4J:
1. Links:
a. https://logging.apache.org/log4j/2.x/
b. https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
2. Log4j is a reliable, fast, and flexible logging framework (APIs) written in Java, which is
distributed under the Apache Software License.
3. Log4j is a popular logging package written in Java. log4j has been ported to the C, C++, C#,
Perl, Python, Ruby, and Eiffel languages.
4. It is an open-source logging API for java.
5. Used for Logging purposes.
6. It helps to generate Log files in various output targets.
7. Main components:
a. Loggers: Responsible for capturing logging information.
b. Appenders: Responsible for publishing logging information to various preferred
destinations.
c. Layouts: Responsible for formatting and logging information in different styles.
—----------
Log4J features:
1. Thread-safe.
2. Optimized for speed.
3. Supports multiple output appenders per logger.
4. Supports Internationalization.
5. It is not restricted to a predefined set of facilities.
6. Logging behavior can be set at runtime using a configuration file.
7. It is designed to handle Java Exceptions from the start.
1
8. It uses multiple levels, namely ALL, TRACE, DEBUG, INFO, WARN, ERROR and FATAL.
9. The format of the log output can be easily changed by extending the Layout class.
10. The target of the log output, as well as the writing strategy, can be altered by
implementations of the Appender interface.
11. It is a fail-stop. However, although it certainly strives to ensure delivery, log4j does not
guarantee that each log statement will be delivered to its destination.
—----------
Logging:
1. Logging is a powerful aid for understanding and debugging the runtime behavior of the
programs. Simply the logging means some way to indicate the state of the system at runtime.
Logs are used to capture and persist the important data and make it available for analysis at
any point in time.
2. logging means some way to indicate the state of the system at runtime. Logs are used to
capture and persist the important data and make it available for analysis at any point in
time.
—----------
Advantages of Logging:
1. Quick Debugging
2. Problem Diagnosis
3. Easy Maintenance
4. Cost and Time Savings
—----------
Log File:
1. The process of storing execution flow step by step is known as Logging.
2. Any file extension that is .log will be considered as a Logfile.
3. Format: HTML, Text, etc.
—----------
Logging levels:
1. All
2. Debug
3. Info
4. Warn
5. Error
6. Fatal
7. Off
8. Trace
—----------
2
--------------------------------------------
1.
—----------
2.
—----------
3.
-------------------------------------------
3
-----------------------------------------------------------------------------------------------------------------------------
CODE - START
------------------------------------------------------------------------------------------------------------------------------
-------------------------------------
1. Log4j.properties:
a.
-------------------------------------
4
-------------------------------------
2. Test script:
-------------------------------------
5
-------------------------------------
3. Reports/Logs :
a.
b.
-------------------------------------
-----------------------------------------------------------------------------------------------------------------------------
CODE - END
------------------------------------------------------------------------------------------------------------------------------
=======================================================================
1. To connect:
a. https://www.linkedin.com/in/rajat-v-3b0685128/
b. https://github.com/rajatt95
c. https://rajatt95.github.io/
6
=======================================================================