LogRecord getLevel() method in Java with Examples

The getLevel() method of java.util.logging.LogRecord is used to get the logging message level of this current LogRecord object, for example Level.Info.

Syntax:

public Level getLevel()

Parameters: This method accepts nothing.



Return: This method returns the logging message level.

Below programs illustrate getLevel() method:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate getLevel() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("400"),
            "Hi message");
  
        // get level of LogRecord
        Level lvl = logRecord.getLevel();
  
        // print result
        System.out.println("Level of Log Record = "
                           + lvl);
    }
}

chevron_right


Output:

Level of Log Record = FINER

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate getLevel() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("WARNING"),
            "Some Warning Message");
  
        // get level of LogRecord
        Level lvl = logRecord.getLevel();
  
        // print result
        System.out.println("Level of Log Record = "
                           + lvl);
    }
}

chevron_right


Output:

Level of Log Record = WARNING

References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#getLevel()



My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.