Logs are important in software testing because they provide valuable information about how an application behaves during different testing stages. Knowing logs helps you understand the application's functionality, spot potential issues, and improve your testing process. Logs are crucial for gaining insights into the application's behavior and performance.
What are logs?
Logs are records or messages created by a program while it works. They act like a detailed diary of what is going on inside the program. Logs can include different types of data, such as error messages, warnings, details on user actions, as well as sent and received data, and much more. All programs generate logs, but they do this in various ways and places.
Logs are useful when:
Testing new features.
Releasing the application.
Checking how it works with other systems.
Finding the exact cause of a bug and fixing errors.
Checking how well the application performs.
For testers, logs are very important for making sure the results are as expected. They check if what actually happened matches what was supposed to happen, especially in automated testing where results are checked through code.
Logging levels
Logs can contain a lot of different information. To simplify working with logs, a special classification called logging levels is used. This can help us find information about an application that is of varying levels of importance.
Logging levels in order of importance:
FATAL. The most critical level. It signifies a major issue that could cause the whole application to crash. Logs with the FATAL level usually indicate severe failures that require immediate intervention and correction.
2024-01-18 12:30:45 [FATAL] - Critical error in server configuration. Application cannot start.ERROR. This level is used for recording errors and issues that can cause unexpected behavior in the application. Logs with the ERROR level indicate problems that need to be addressed.
2024-01-18 13:45:22 [ERROR] - Failed to retrieve book information. Database connection timeout.WARNING. This level indicates potential issues that may cause problems, but they are not critical errors. Logs with the WARNING level may include messages about incorrect application usage, inaccurate data, and other situations that require attention.
2024-01-18 14:20:10 [WARNING] - High server load. Some requests may experience delays.INFO. This level provides information on the application's progress and different events. Logs at the INFO level contain messages that help us keep track of the essential operations and the application's overall status. For example, they let us know when specific operations start and finish, when resources are loaded, and when requests are sent and received. These logs are instrumental in tracking changes in the application's state and other events critical to monitoring the program's execution.
2024-01-18 15:05:30 [INFO] - User 'TEST' successfully logged in.DEBUG. This level provides detailed information that developers need during the debugging process. Debug logs capture deep insights into how the application is running, giving you a close-up look at each step. They're helpful for figuring out operational flow, the values of your variables, and all those minor details that simplify troubleshooting, thereby enhancing your development and testing experience.
2024-01-18 16:40:12 [DEBUG] - Variable 'counter' incremented to 5 in the loop.TRACE. The TRACE level is the most detailed level of logging, giving us the most detailed record of every single step and decision made by the application. It is often used for thorough debugging and performance analysis. TRACE logs are like detectives that capture all the details, including variable values, method calls, and other pertinent information while the program is running. They provide all the information needed to understand what's going on inside the application. TRACE-level logs can generate a substantial data volume and are typically used in situations where an intricate understanding of the application's inner workings is required.
2024-01-18 17:55:18 [TRACE] - Method 'calculateDiscount' called with parameters: { productId: 123, quantity: 2 }The logging level can be configured based on the needs of the developer or QA engineer.
Typically, in production, the level of detail is not set to the highest to avoid overloading the logs with a large volume of information. Meanwhile, during development or debugging, more detailed levels like DEBUG or TRACE can be utilised for in-depth analysis and issue tracking.
Types of logs
To effectively check and debug the server or client, understanding different log types is crucial. This knowledge helps us determine which specific log type to refer to. During the testing process, we commonly work with application logs, server logs, and system logs. Let me describe the main types of logs:
Application logs. These logs are created by the application during its operation, including routine activities, user actions, and transactions. They help to understand how the application functions under normal conditions.
Server logs. These logs are generated by servers and contain information about the server's operation, requests, error situations, connections, and other server events. They are used to ensure proper communication between the server and the client.
System logs. These are logs recorded by the operating system. They include information about the operating system's operation, events, errors, system status, processes, network connections, and other system events. System logs help in understanding how the application interacts with the underlying system and in identifying potential system-level issues.
Each type of logs can also be further subdivided. For example, system logs can be divided into error logs, security logs, and more. The same applies to server logs, which can be divided into error logs, access logs, and many other types. These are the main types of logs that QA engineers typically encounter. Additionally, there are other types, such as database logs, network device logs, security logs, and so on.
Log formats
The format of logs usually comprises several parts, each providing specific information about an event or operation within the application. The information in logs also varies based on what the developer includes. Moreover, the developer's decision affects the level of detail and important features of the logs.
Here are the common parts of a log:
Timestamp. This shows when the log entry was made. The date and time are often in a standard format.
Log level. This indicates the logging level.
Source. This identifies the source or part that creates the log. It's usually the name of the class, module, or subsystem.
Message. This provides a brief description or details of the event or operation.
Additional attributes. These include a series of classes and methods that run when an error occurs, or they provide extra information.
Example:
[2024-01-15 12:00:01] [INFO] [LoginModule] User 'USERNAME' successfully logged in. - IP: 192.168.1.100 - Browser: Chrome - Platform: Windows 10
In this example,
Timestamp: 2024-01-15 12:00:01
Log level: INFO
Source: Login Module
Message: User 'USERNAME' successfully logged in.
Additional attributes: IP address, browser, and operating system of the user.
The provided log example is merely for illustration purposes and can vary depending on the logging system used.
Advantages of using logs in testing
Testers extensively use logs for different purposes during application testing. Here are some of these reasons:
Troubleshooting and issue identification. Logs are a valuable tool for troubleshooting and finding issues during testing. They provide a detailed record of events, errors, and other relevant data that can assist in understanding the application's behavior. Analyzing logs may help pinpoint the problem's origin.
Issue reproduction and debugging. Examining logs can yield insights into the sequence of events leading to a problem. This information can be used to reproduce the issue and effectively debug it, leading to a quicker fix.
Performance and stability monitoring. Regular log reviews can help identify performance bottlenecks or stability problems. This allows you to proactively address these issues, ensuring smoother application operation.
Anomaly detection. Logs can aid in recognizing patterns, spotting anomalies, and understanding the application's performance under various conditions. This information can assist in optimizing testing efforts and enhancing the overall quality of the application.
Conclusion
Logs in software development are viewed as a practical need. While discussions about them may not be as exciting as other tech topics, the role of logs in understanding, fixing, and improving software is crucial.