System Logger Minimal Setup

Log through the JDK built-in System.Logger facade: zero dependencies, MessageFormat-style placeholders, and Supplier messages built only when the level is on.

JavaCli Tooling

Code

snippet
import java.lang.System.Logger.Level;

public class StdLoggerDemo {

    // JDK 9 内置日志门面:零依赖,默认实现把 INFO 以上写到 stderr
    private static final System.Logger LOG = System.getLogger(StdLoggerDemo.class.getName());

    public static void main(String[] args) {
        LOG.log(Level.INFO, "job {0} finished in {1} ms", "import-7", 812);
        LOG.log(Level.WARNING, "quota at {0,number,percent}", 0.9);

        // Supplier 形式:级别未开时,消息在打印前都不会构造
        LOG.log(Level.DEBUG, () -> "heavy detail only when DEBUG is enabled");
    }
}

What the code does

The working surface is the class StdLoggerDemo and the function main — everything else is wiring.

Statements that matter

LOG.log(Level.DEBUG, () -> "heavy detail only when DEBUG is enabled");
LOG.log(Level.INFO, "job {0} finished in {1} ms", "import-7", 812);
LOG.log(Level.WARNING, "quota at {0,number,percent}", 0.9);

Interactive Tools for This Topic

FAQ

How do you run System Logger Minimal Setup?
The file is self-contained: run it directly, no dependencies to install beforehand.