The severe() method of a Logger class used to Log a SEVERE message.This method is used to pass SEVERE types logs to all the registered output Handler objects.
SEVERE Message: Severe occurs when something terrible has occurred and the application cannot continue further. Ex like database unavailable, out of memory.
There are two types of severe() method depending upon no of parameter passed.
- severe(String msg): This method is used to log a SEVERE message.If the logger is enabled for logging SEVERE level message then the given message is forwarded to all the registered output Handler objects.
Syntax:
public void severe(String msg)
Parameters: This method accepts a single parameter String which is the string message.
Return value: This method returns nothing.
Below programs illustrate severe(String msg) method:
Program 1:
// Java program to demonstrate
// Logger.severe(String msg) method
import
java.io.IOException;
import
java.util.logging.*;
public
class
GFG {
public
static
void
main(String[] args)
throws
SecurityException, IOException
{
// Create a Logger
Logger logger
= Logger.getLogger(
GFG.
class
.getName());
// Set Logger level()
logger.setLevel(Level.SEVERE);
// Call severe method
logger.severe(
"Set SERVE=SOME ISSUE"
);
}
}
The output printed on console is shown below.
Output: - severe(Supplier msgSupplier): This method is used Log a SEVERE message, constructed only if the logging level is such that the message will actually be logged. It means If the logger is enabled for the SEVERE message level then the message is constructed by invoking the provided supplier function and forwarded to all the registered output Handler objects.
Syntax:
public void severe(Supplier msgSupplier)
Parameters: This method accepts a single parameter msgSupplier which is a function, which when called, produces the desired log message.
Return value: This method returns nothing.
Below programs illustrate severe(Supplier msgSupplier) method:
Program 1:
// Java program to demonstrate
// Logger.severe(Supplier<String>) method
import
java.io.IOException;
import
java.util.function.Supplier;
import
java.util.logging.*;
public
class
GFG {
public
static
void
main(String[] args)
throws
SecurityException, IOException
{
// Create a Logger
Logger logger
= Logger.getLogger(
GFG.
class
.getName());
// Set Logger level()
logger.setLevel(Level.SEVERE);
// Create a supplier<String> method
Supplier<String> StrSupplier
= () ->
new
String(
"Welcome to GFG"
);
// Call severe(Supplier<String>)
logger.severe(StrSupplier);
}
}
The output printed on console is shown below.
Output:
References: