001 package com.croftsoft.core.util.log; 002 003 import java.io.PrintStream; 004 005 import com.croftsoft.core.lang.NullArgumentException; 006 007 /********************************************************************* 008 * Writes log entries out to a PrintStream. 009 * 010 * <p> 011 * All methods are synchronized. 012 * </p> 013 * 014 * <p> 015 * Example: 016 * <pre><code> 017 * Log log = new PrintStreamLog ( System.out ); 018 * </code></pre> 019 * </p> 020 * 021 * @version 022 * 2001-08-02 023 * @since 024 * 2001-02-27 025 * @author 026 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 027 *********************************************************************/ 028 029 public final class PrintStreamLog 030 implements Log 031 ////////////////////////////////////////////////////////////////////// 032 ////////////////////////////////////////////////////////////////////// 033 { 034 035 public static final PrintStreamLog SYSTEM_OUT_INSTANCE 036 = new PrintStreamLog ( System.out ); 037 038 public static final PrintStreamLog SYSTEM_ERR_INSTANCE 039 = new PrintStreamLog ( System.err ); 040 041 private final PrintStream printStream; 042 043 ////////////////////////////////////////////////////////////////////// 044 ////////////////////////////////////////////////////////////////////// 045 046 public PrintStreamLog ( PrintStream printStream ) 047 ////////////////////////////////////////////////////////////////////// 048 { 049 NullArgumentException.check ( this.printStream = printStream ); 050 } 051 052 ////////////////////////////////////////////////////////////////////// 053 ////////////////////////////////////////////////////////////////////// 054 055 public synchronized void record ( String message ) 056 ////////////////////////////////////////////////////////////////////// 057 { 058 printStream.println ( message ); 059 } 060 061 public synchronized void record ( Throwable throwable ) 062 ////////////////////////////////////////////////////////////////////// 063 { 064 throwable.printStackTrace ( printStream ); 065 } 066 067 public synchronized void record ( 068 String message, 069 Throwable throwable ) 070 ////////////////////////////////////////////////////////////////////// 071 { 072 printStream.println ( message ); 073 074 throwable.printStackTrace ( printStream ); 075 } 076 077 ////////////////////////////////////////////////////////////////////// 078 ////////////////////////////////////////////////////////////////////// 079 }