/* * [Log.java] * * Summary: Log activities and errors for debugging. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2007-07-28 Created with IntelliJ IDEA. */ package com.mindprod.replicator; import com.mindprod.common18.EIO; import com.mindprod.hunkio.PrintWriterPortable; import java.io.File; import java.io.IOException; import static java.lang.System.*; /** * Log activities and errors for debugging. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2007-07-28 Created with IntelliJ IDEA. * @since 2009 */ final class Log { /** * file where we log activities */ private static PrintWriterPortable log; /** * close log file */ static void close() { if ( log != null ) { log.println( "-30-" ); log.close(); } } /** * print row of dashes as a divider */ static void divider() { if ( log != null ) { log.println( "\n---------------------------------------------------\n" ); } } /** * open the long file. If fails to open, log will be null. * * @param logfileName fully qualified name of log text file. */ static void open( String logfileName ) { // check if already open if ( log != null ) { return; } try { log = new PrintWriterPortable( EIO.getBufferedWriter( new File( logfileName ), 4 * 1024, EIO.UTF8 ) ); } catch ( SecurityException e ) { err.println( "no permission granted to write to disk log " + ConfigForReceiver .RECEIVER_LOG ); log = null; // user will configure a proper directory soon. } catch ( IOException e ) { err.println( "cannot open " + ConfigForReceiver.RECEIVER_LOG ); log = null; // user will configure a proper directory soon. } } /** * print string * * @param s string to log. */ static void print( String s ) { if ( log != null ) { log.print( s ); } } /** * print object as string * * @param s string to log. */ static void print( Object s ) { if ( log != null ) { log.print( s.toString() ); } } /** * log a blank line */ static void println() { if ( log != null ) { log.println(); } } /** * print string, followed by newline * * @param s string to log. */ static void println( String s ) { if ( log != null ) { log.println( s ); } } /** * print object as string, followed by newline * * @param s string to log. */ static void println( Object s ) { if ( log != null ) { log.println( s.toString() ); } } }