Java provides the ability to capture the log files.
The need for Log capture
There are multiple reasons why we may need to capture the application activity.
- Recording unusual circumstances or errors that may be happening in the program
- Getting the info about whats going in the application
The details which can be obtained from the logs can vary. Sometimes, we may want a lot of details regarding the issue, or sometimes some light information only.
Like when the application is under development and is undergoing testing phase, we may need to capture a lot of details.
The log levels control the logging details. They determine the extent to which depth the log files are generated. Each level is associated with a numeric value and there are 7 basic log levels and 2 special ones.
We need to specify the desired level of logging every time, we seek to interact with the log system. The basic logging levels are:
|SEVERE||1000||Indicates some serious failure|
|FINE||500||General developer info|
|FINER||400||Detailed developer info|
|FINEST||300||Specialized Developer Info|
Severe occurs when something terrible has occurred and the application cannot continue further. Ex like database unavailable, out of memory.
Warning may occur whenever the user has given wrong input or credentials.
Info is for the use of administrators or advanced users. It denotes mostly the actions that have lead to a change in state for the application.
Configuration Information may be like what CPU the application is running on, how much is the disk and memory space.
Fine Finer and Finest provide tracing information. When what is happening/ has happened in our application.
FINE displays the most important messages out of these.
FINER outputs a detailed tracing message and may include logging calls regarding method entering, exiting, throwing exceptions.
FINEST provides highly detailed tracing message.
Furthermore, there are two special Logging levels
Capturing everything may mean every field declaration, definition, every method call, every assignment performed etc.
Java’s Log System
The log system is centrally managed. There is only one application wide log manager which manages both the configuration of the log system and the objects that do the actual logging.
The Log Manager Class provides a single global instance to interact with log files. It has a static method which is named getLogManager
The logger class provides methods for logging. Since LogManager is the one doing actual logging, its instances are accessed using the LogManager‘s getLogger method.
The global logger instance is accessed through Logger class’ static field GLOBAL_LOGGER_NAME. It is provided as a convenience for making casual use of the Logging package.
May 12, 2018 7:56:33 AM DemoLogger makeSomeLog INFO: My first Log Message May 12, 2018 7:56:33 AM GfG main INFO: This is a log message
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.lang.Short toString() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java Deprecated API Scanner tool (jdepscan) in Java 9 with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.LinkedList.offer(), offerFirst(), offerLast() in Java
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.util.function.LongPredicate interface in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java.util.concurrent.Phaser class in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : RaghuDV