public synchronized static void setLogFile ( File logfile ) { // Add a file logger that will use the compiler's customized // formatter. This formatter provides a terse representation of the // logging information. try { if ( logfile != null ) { String absolutePath = logfile . getAbsolutePath ( ) ; if ( initializedLogFile == null || ( ! initializedLogFile . equals ( absolutePath ) ) ) { // Remove any existing handlers. initializeLogger ( topLogger ) ; // Set the new handler. FileHandler handler = new FileHandler ( absolutePath ) ; handler . setFormatter ( new LogFormatter ( ) ) ; topLogger . addHandler ( handler ) ; // Make sure we save the name of the log file to avoid // inappropriate reinitialization. initializedLogFile = absolutePath ; } } } catch ( IOException consumed ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "WARNING: unable to open logging file handler\n" ) ; sb . append ( "WARNING: logfile = '" + logfile . getAbsolutePath ( ) + "'" ) ; sb . append ( "\nWARNING: message = " ) ; sb . append ( consumed . getMessage ( ) ) ; System . err . println ( sb . toString ( ) ) ; } }
Define the file that will contain the logging information . If this is called with null then the log file will be removed . The log file and logging parameters are global to the JVM . Interference is possible between multiple threads .