#!/usr/bin/env --split-string=${JDK_HOME}/bin/java @Makeshift/java_arguments @Makeshift/java_javac_arguments \c [SS] // This command runs directly from the present source file, it needs no compiling. import java.util.logging.Level; import java.util.logging.Logger; import static java.util.logging.Level.*; /** A shell command to issue test messages to a runtime event logger. * * @see * The `test-logging` command */ public final class LoggingTestCommand { // [AFN] private LoggingTestCommand( final String loggerName ) { logger = Logger.getLogger( loggerName ); } /** Takes a `test-logging` command from the shell and executes it. */ public static void main( final String[] arguments ) { if( arguments.length != 1 ) abortWithUsage(); final String a = arguments[0]; if( a.startsWith( "-" )) abortWithUsage(); // Allowing e.g. for a deliberate `-?`. new LoggingTestCommand( a ).run(); } //// P r i v a t e //////////////////////////////////////////////////////////////////////////////////// private static void abortWithUsage() { System.err.println( "Usage: test-logging " ); System.exit( 1 ); } private final Logger logger; private void run() { logger.log( OFF, "Logging at levels `OFF`, `SEVERE`, `WARNING`, `INFO`, `CONFIG`, " + "`FINE`, `FINER`, `FINEST` and `ALL`:" ); test( OFF ); test( SEVERE ); test( WARNING ); test( INFO ); test( CONFIG ); test( FINE ); test( FINER ); test( FINEST ); test( ALL ); } /** Logs a test message at the given level. */ private void test( final Level level ) { logger.log( level, () -> "Testing at level " + level ); }} // NOTES // ───── // AFN Atypical file naming is allowed here. ‘The compiler does not enforce the optional restriction // defined at the end of JLS §7.6, that a type in a named package should exist in a file whose // name is composed from the type name followed by the .java extension.’ // // // // No longer, however, does this allowance extend to the package name. While in JDK releases // prior to 22 “the launcher's source-file mode was permissive about which package, if any, // was declared”, current releases enforce a correspondence between the declared package name // and the file path. Failing this, the launcher aborts with “end of path to source file // does not match its package name”. // // SS · Here the long form `--split-string` (as opposed to `-S`) enables Emacs to recognize this file // as Java source code. See the note apropos of ‘source-launch files encoded with a shebang’ at // `http://reluk.ca/project/Java/Emacs/jmt-mode.el`. // Copyright © 2020-2022, 2024 Michael Allan. Licence MIT.