/* * Copyright 1999 Phil Burk, Mobileer Inc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.softsynth.util; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; /** * Logger logs output to a file if enabled. * * @author Phil Burk (C) 1999 SoftSynth.com */ public class Logger { FileOutputStream fileStream = null; BufferedOutputStream stream = null; int column = 0; boolean enabled; String lineTerminator; public Logger() { lineTerminator = System.getProperty("line.separator", "\n"); // System.out.println("lineTerminator.length = " + lineTerminator.length() ); // for( int i=0; i 0) logln(""); } /** * Open a log file. */ public void open(String logFileName) throws IOException, SecurityException { open(new File(logFileName)); } /** * Open a log file by name. */ public void open(File logFile) throws IOException, SecurityException { // Close any existing log file. close(); // Open a new log file. fileStream = new FileOutputStream(logFile); // Buffer it so it isn't awfully slow. stream = new BufferedOutputStream(fileStream); column = 0; } public void close() throws IOException { if (stream != null) { stream.flush(); stream.close(); } if (fileStream != null) fileStream.close(); stream = null; } }