Friday, November 16, 2018

4 Types of Java Logs

Log is an important issue in software development, especially if you need to analyze errors and other unexpected events in your production environment. Implementing your registry usually seems easy. But, as you have probably experienced, the creation of log is much more complex than it seems. As an experienced developer, you should know the different Log structures available, the common pitfalls and best practices and, of course, the types of log files used in common deployment scenarios. In this article, I will focus on the last part. I'm going to talk about 4 different types of logs that you can find in almost every development or production environment.

Application Log

Let's start with the most common type of Log: application log
Most developers think about that record when talking about the registry. The reason for this is simple. Your application produces this record. It contains all types of error messages, warnings or other events recorded by the application. These messages can provide high-level logical information connected to specific use cases. Typical examples are:
• The stacktrace of an exception that occurred in a use case.
• Warning messages about slow response times from an external system.
• Information that a use case has been triggered or terminated.
The application record is probably the most important type of record that is mentioned in this article because you have full control over it. This means that you are responsible for writing the messages.
Each log message must provide useful information that helps you understand the behavior of your application. If you want to know more about application logs, take a look at Eric's article, which describes an optimal set of best practices for registering applications.

Web server logs and applications
The next interesting and important type is the Log of your web server or applications.
Most business applications are implemented on a Web server, for example, Apache Tomcat or an application server, for example, Wildfly or WebSphere Liberty. Your log files provide information about technical problems and the current status of the server.
The configuration and resources of each server are different, and I will not explain them in detail in this article. But, please be sure to check the documentation of your server and configure it properly. Obtaining the correct information from your server can make the difference between identifying potential problems over time and a server unavailability.

Garbage collector Log
The garbage collector provides automatic memory management. It controls all the objects instantiated in a JVM and eliminates those that are no longer used. This is a very complex task and there are several different garbage collector implementations available.
In general, the garbage collection process in Java is very efficient. It is so efficient that there are many applications that use the default implementation with their default settings. But if your application has to handle high load or use many complex object structures, the performance of the application may decrease over time. This usually happens when the garbage collector needs to spend more and more time to manage the available memory. The garbage collector record provides the necessary information to analyze all the activities of the garbage collector.
The garbage collector log is disabled by default. You must enable it with a set of command line properties.
If you are using JDK 8 or earlier, you can do so using the following properties:
-XX: + PrintGCDetails -Xloggc:
From JDK 9, you must use the following properties:
class = "prettyprint" -Xlog: gc *: file = <path of file-del-gc-log>
After starting your application with these command line properties, your garbage collector will record detailed information about all the operations. Unfortunately, the content and format of the garbage collector log generated depend on the provider and the version of your JVM and the garbage collection algorithm.

System Logs

All the logs discussed above are written by JVM or a running application in JVM. In addition to these records, you must also be familiar with the Log recorded by your operating system.

As a Java developer, I probably never write in these logs. But your operating system logs certain events in these registers. Other applications, which are part of its implementation, can also do so. Therefore, system records are a good place to get an overview of external events.

If you are running your application on Windows, this is the event log. In Linux, you must know the syslog service and its successors.

Windows Log  wvent

The Windows event log contains important hardware and software events in the categories, security, configuration, system, and forwarded events applications.

Especially the application events and the system category can be useful to understand the events that have occurred outside of your application. The application category contains events reported by other applications that run on the local Windows system. The events related to the hardware and the controller belong to the system category.

Interested in learning Java? Join now:” java training in chennai “

Linux system Logging

The Linux syslog service and its successors provide a highly configurable registration system. It Log messages triggered by applications or by the operating system in a file or sends them to a remote system.

The Log service used and its configuration depend on your Linux distribution. Please check the documentation to know more about your specific operating system.

Interested in learning Java? Join now:” java training in bangalore

Conclusion

Logging is an important issue with many different facets. In this article, I have summarized 4 important Logs that you should know as a Java developer:

• The log of the application is the most obvious. It is written by your application and you are responsible for the content.

• If you deploy your application to a Web or application server, you will also need to know the Logs provided by that server.

• Garbage collector Logs can provide important information if you need to analyze performance problems.

• You can check the system logs to get an overview of all external events that may have affected your application and cause the service incident.




No comments:

Post a Comment

From Java 8 to Java 11

Switching from Java 8 to Java 11 is more complicated than most updates. Here are some of my notes on the process. Modules Java 9 i...