/** * File may not exist or have old logs in it if not opened yet * @return non-null */ public synchronized String currentFile() { if (_currentFile != null) return _currentFile.getAbsolutePath(); String rv = getNextFile().getAbsolutePath(); // so it doesn't increment every time we call this _rotationNum = -1; return rv; }
protected synchronized void writeRecord(int priority, String val) { if (val == null) return; if (_currentOut == null) { rotateFile(); if (_currentOut == null) return; // hosed } try { _currentOut.write(val); // may be a little off if a lot of multi-byte chars, but unlikely _numBytesInCurrentFile += val.length(); } catch (Throwable t) { if (!_write) return; if (++_diskFullMessageCount < MAX_DISKFULL_MESSAGES) System.err.println("Error writing log, disk full? " + t); //t.printStackTrace(); } if (_numBytesInCurrentFile >= _manager.getFileSize()) { rotateFile(); } }
File f = getNextFile(); _currentFile = f; _numBytesInCurrentFile = 0; closeWriter(); try { _currentOut = new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(f), "UTF-8"));
return getFirstFile(base, pattern, max); if (_rotationNum > max) _rotationNum = 0; String newf = replace(pattern, _rotationNum); if (base != null) return new File(base, newf);
protected void writeRecord(LogRecord rec, String formatted) { writeRecord(rec.getPriority(), formatted); }
/** @since 0.8.2 */ private synchronized void startLogWriter() { // yeah, this doesn't always work, _writer should be volatile if (_writer != null) return; if (SystemVersion.isAndroid()) { try { Class<? extends LogWriter> clazz = Class.forName( "net.i2p.util.AndroidLogWriter" ).asSubclass(LogWriter.class); Constructor<? extends LogWriter> ctor = clazz.getDeclaredConstructor(LogManager.class); _writer = ctor.newInstance(this); } catch (ClassNotFoundException e) { } catch (InstantiationException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } } // Default writer if (_writer == null) _writer = new FileLogWriter(this); _writer.setFlushInterval(_flushInterval * 1000); // if you enable logging in I2PThread again, you MUST change this back to Thread Thread t = new I2PThread(_writer, "LogWriter"); t.setDaemon(true); t.start(); }