Java System getLogger() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 9+

Definition

In Java 9 and newer, System.getLogger(name) returns a System.Logger, a small logging interface built into the JDK. You log with logger.log(level, message) using the levels TRACE, DEBUG, INFO, WARNING, and ERROR.

System.Logger is only a facade: by default messages go to java.util.logging, which prints INFO and above to System.err with a time stamp. Frameworks can plug in their own backend.

A static method of the java.lang.System class, added in Java 9 (JDK 9). Call it on the class name, as in System.getLogger(...). No import is needed, because classes in java.lang are always visible. Requires Java 9 or newer.

Syntax

Get a logger and log at a level:

Java
System.Logger logger = System.getLogger("com.example.shop");
logger.log(System.Logger.Level.INFO, "Shop opened");
logger.log(System.Logger.Level.DEBUG, () -> "details: " + expensiveDetails());
CallWhat it does
System.getLogger(MyApp.class.getName())Logger named after the class (the usual convention).
logger.isLoggable(Level.DEBUG)true only if DEBUG messages would be output.
logger.log(Level.DEBUG, supplier)Builds the message only if DEBUG is enabled.

Added in Java 9: this method and System.Logger do not exist in Java 8. Level above means System.Logger.Level.

Library declarations
Java
// java.lang.System
public static System.Logger getLogger(String name)
public static System.Logger getLogger(String name, ResourceBundle bundle)

Parameters

ParameterDescription
nameLogger name, often the fully qualified class name.
bundle(Second overload) A ResourceBundle whose keys can be used as messages.

Return Value

Return ValueDescription
System.LoggerA logger for that name, connected to the active logging backend.

Compare with Similar Methods

Other ways to report what a program is doing:

MethodHow it differs
java.util.logging.Logger.getLogger(name)The full JDK logging API that is the default backend.
System.err.printlnPlain error text, no levels or configuration.
getProperty(key)Often used to read a custom log-level setting.

Java Examples

Example 1 — Create a Logger and Ask Which Levels Are On

A logger knows its name and can tell you whether a level is enabled, without writing any log line.

Java
public class SystemGetLoggerBasics {
    public static void main(String[] args) {
        System.Logger logger = System.getLogger("com.example.shop");
        System.out.println("Name: " + logger.getName());
        System.out.println("INFO enabled: " + logger.isLoggable(System.Logger.Level.INFO));
        System.out.println("DEBUG enabled: " + logger.isLoggable(System.Logger.Level.DEBUG));
        System.out.println("ERROR enabled: " + logger.isLoggable(System.Logger.Level.ERROR));
    }
}

How It Works

  1. A named logger. getName() gives back the name passed to getLogger. Dotted names let a configuration file target a whole package.
  2. The default threshold. Without a custom configuration, java.util.logging lets INFO and more serious levels through, so INFO and ERROR report true.
  3. Debugging is off. DEBUG is below INFO and therefore disabled. A logging.properties file with com.example.shop.level = FINE would turn it on.

Example 2 — Skip Building Messages Nobody Will See

Building a log message can be expensive. With a Supplier or an isLoggable guard, the work only happens when the level is enabled.

Java
import java.util.function.Supplier;

public class SystemGetLoggerLazy {
    static int calls = 0;

    static String expensiveReport() {
        calls++;
        return "report number " + calls;
    }

    public static void main(String[] args) {
        System.Logger logger = System.getLogger("SystemGetLoggerLazy");
        Supplier<String> message = SystemGetLoggerLazy::expensiveReport;
        logger.log(System.Logger.Level.DEBUG, message);
        logger.log(System.Logger.Level.TRACE, message);
        System.out.println("Reports built with a Supplier: " + calls);

        if (logger.isLoggable(System.Logger.Level.DEBUG)) {
            logger.log(System.Logger.Level.DEBUG, expensiveReport());
        }
        System.out.println("Reports built after the guard: " + calls);
    }
}

How It Works

  1. A message made on demand. log(level, Supplier) receives a method reference instead of a finished string. The logger calls get() only if it will really output the message.
  2. Never called. DEBUG and TRACE are both disabled by default, so the supplier is never asked and the counter calls stays at 0. Nothing is written to System.err either.
  3. The classic guard. Wrapping the call in if (logger.isLoggable(...)) has the same effect for code that builds a plain string, so expensiveReport() is skipped again and the count is still 0.

Example 3 — List Every Level with Its Severity

Name the logger after the class and walk through the five normal levels, showing each severity number and whether it is enabled.

Java
public class SystemGetLoggerLevels {
    public static void main(String[] args) {
        System.Logger logger = System.getLogger(SystemGetLoggerLevels.class.getName());
        System.out.println("Logger: " + logger.getName());
        System.Logger.Level[] levels = {
            System.Logger.Level.TRACE, System.Logger.Level.DEBUG, System.Logger.Level.INFO,
            System.Logger.Level.WARNING, System.Logger.Level.ERROR
        };
        for (System.Logger.Level level : levels) {
            System.out.println(level + " (" + level.getSeverity() + "): " + logger.isLoggable(level));
        }
    }
}

How It Works

  1. Class name as logger name. SystemGetLoggerLevels.class.getName() is the class's full name; it has no package here, so the logger is simply called "SystemGetLoggerLevels".
  2. Severity numbers. Each Level has a fixed severity from getSeverity(): 400 for TRACE up to 1000 for ERROR. Higher means more serious. The special levels ALL and OFF are left out of the list.
  3. A threshold at 800. Everything from INFO (800) upward is enabled, and TRACE and DEBUG fall below it, matching the default java.util.logging level.

Frequently Asked Questions

A small logging interface added in Java 9. Get one from System.getLogger(name) and log with levels like INFO and ERROR.
With the default backend, java.util.logging prints INFO and higher to System.err, including a time stamp and the source.
The default threshold is INFO. Lower it in a logging.properties file, for example com.example.level = FINE, or configure your logging framework.
No. It was added in Java 9. In Java 8 use java.util.logging.Logger directly.
getLogger(name, bundle) lets you log message keys that are looked up in the bundle, for translated log messages.

Next: getProperties()

Get all system properties as one live Properties object.

getProperties() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful