if (writer == null || !logfile.exists() || !logfile.canWrite()) {  rotateLogFile (); }
    public void write () {	if (entries.isEmpty ())	    return;	try {	    if (logfile != null &&	          (writer == null || !logfile.exists() || !logfile.canWrite())) {	        // rotate the log file if we can't write to it	        rotateLogFile ();	    }	    int l = entries.size();	    // check if writing to printstream or file	    if (out != null) {	        for (int i=0; i<l; i++) {	            String entry = (String) entries.get (0);	            entries.remove (0);	            out.println (entry);	        }	    } else {	        for (int i=0; i<l; i++) {	            String entry = (String) entries.get (0);	            entries.remove (0);	            writer.println (entry);	        }	        writer.flush ();	    }	} catch (Exception x) {	    int e = entries.size();	    if (e > 1000) {	        // more than 1000 entries queued plus exception - something	        // is definitely wrong with this logger. Write a message to std err and	        // discard queued log entries.	        System.err.println ("Error writing log file "+this+": "+x);	        System.err.println ("Discarding "+e+" log entries.");	        entries.clear ();	    }	}    }