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.
Code
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
Git Conventional Commit BuilderBuild and validate Conventional Commits v1.0.0 messages with type, scope, breaking markers, 72-char subject counter, body, footers, and git CLI command.Glob Pattern TesterCompile glob patterns with *, **, ?, character classes, and braces into regex and test them against a list of candidate file paths.Tar Archive Command BuilderBuild safe tar create, extract, and list commands for gzip, xz, zstd, and bzip2 archives with excludes, target directory (-C), and flag explanations.
FAQ
- How do you run System Logger Minimal Setup?
- The file is self-contained: run it directly, no dependencies to install beforehand.
Report a problem with this exampleOpens a pre-filled issue on GitHub.