@Override protected void subAppend(LoggingEvent event) { LogLog.debug("subAppend"); long now = System.currentTimeMillis(); if( now >= nextRollTime ) { LogLog.debug("Have to roll directory"); calculateRollOverTime(); rollDirectory(); } else if( getFile() != null && ((CountingQuietWriter) qw).getCount() >= maxFileSize ) { LogLog.debug("Have to roll file"); rollFile(); } LogLog.debug("Calling Super Sub Append"); super.subAppend(event); }
/** * Handles append time behavior for CompositeRollingAppender. This checks * if a roll over either by date (checked first) or time (checked second) * is need and then appends to the file last. */ protected void subAppend(LoggingEvent event) { if (rollDate) { long n = System.currentTimeMillis(); if (n >= nextCheck) { now.setTime(n); nextCheck = rc.getNextCheckMillis(now); rollOverTime(); } } if (rollSize) { if ((fileName != null) && ((CountingQuietWriter) qw).getCount() >= maxFileSize) { rollOverSize(); } } super.subAppend(event); }
/** * This method differentiates RollingFileAppender from its super class. * * @since 0.9.0 */ protected void subAppend(LoggingEvent event) { super.subAppend(event); if (fileName != null && qw != null) { String nowDate = sdf.format(new Date()); // 检测日期是否已经变更了,如果变更了就要重创建日期目录 if (!fileMaps.get(fileName).getDate().equals(nowDate)) { rollOver(); return; } long size = ((CountingQuietWriter) qw).getCount(); if (size >= maxFileSize && size >= nextRollover) { rollOver(); } } }
/** * Handles append time behavior for CompositeRollingAppender. This checks if a roll over either by date (checked * first) or time (checked second) is need and then appends to the file last. */ protected void subAppend(LoggingEvent event) { if (rollDate) { long n = System.currentTimeMillis(); if (n >= nextCheck) { now.setTime(n); nextCheck = rc.getNextCheckMillis(now); rollOverTime(); } } if (rollSize) { if ((fileName != null) && (((CountingQuietWriter) qw).getCount() >= maxFileSize)) { rollOverSize(); } } super.subAppend(event); }
/** * Creates and opens the file for logging. If <code>staticLogFileName</code> is false then the fully qualified name * is determined and used. */ public synchronized void setFile(String fileName, boolean append) throws IOException { if (!staticLogFileName) { scheduledFilename = fileName = fileName.trim() + sdf.format(now); } super.setFile(fileName, append, bufferedIO, bufferSize); if (append) { File f = new File(fileName); ((CountingQuietWriter) qw).setCount(f.length()); } }
/** * Implements the usual roll over behaviour. * <p> * <code>File</code> is renamed <code>File.yyyyMMddHHmmss</code> and closed. A * new <code>File</code> is created to receive further log output. */ // synchronization not necessary since doAppend is alreasy synched public void rollOver() { if (qw != null) { long size = ((CountingQuietWriter) qw).getCount(); LogLog.debug("rolling over count=" + size); // if operation fails, do not roll again until // maxFileSize more bytes are written nextRollover = size + maxFileSize; } this.closeFile(); // keep windows happy. String newFileName = getLogFileName(fileName); try { // This will also close the file. This is OK since multiple // close operations are safe. this.setFile(newFileName, false, bufferedIO, bufferSize); nextRollover = 0; } catch (IOException e) { if (e instanceof InterruptedIOException) { Thread.currentThread().interrupt(); } LogLog.error("setFile(" + newFileName + ", false) call failed.", e); } }
/** This method differentiates RollingFileAppender from its super class. @since 0.9.0 */ @Override protected void subAppend( LoggingEvent event ) { super.subAppend(event); if (fileName != null && qw != null) { long size = ((CountingQuietWriter) qw).getCount(); if (size >= maxFileSize && size >= nextRollover) { rollOver(); } } }
@Override public synchronized void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException { super.setFile(fileName, append, this.bufferedIO, this.bufferSize); if( append ) { File f = new File(fileName); ((CountingQuietWriter) qw).setCount(f.length()); } }
protected void subAppend(LoggingEvent event) { if (event.getLevel().toInt() <= currentLevel) { super.subAppend(event); if (fileName != null && qw != null) { long size = ((CountingQuietWriter) qw).getCount(); if (size >= maxFileSize && size >= nextRollover) { rollOver(); } } } }
@SuppressWarnings("resource") protected void subAppend(CountingQuietWriterEx qw, LoggingEvent event) throws IOException { // 此句不加可以节省20%的资源,但程序退出时日志会缺少 if (!bufferedIO) qw.flush(); // 超过大小备份日志文件,并创建新文件 if (qw != null) { long size = ((CountingQuietWriter) qw).getCount(); if (size >= maxFileSize) {// 超过单个日志大小 final String fileName = qw.getFileName(); String idx = fileName.substring(fileName.lastIndexOf(".") + 1); qw = rollOver(qw, Integer.parseInt(idx) + 1); } else { String logDate = qw.getLogDate(); String today = format.format(new Date(event.timeStamp)); if (!logDate.equals("") && !logDate.equals(today)) {// 日切情况 qw = rollOver(qw, 0); } } } // 写日志,一定要调用write(string)方法,因为只有它才会累加count qw.write(this.layout.format(event)); if (layout.ignoresThrowable()) { // layout中忽略异常的处理,由此处写异常信息 String[] s = event.getThrowableStrRep(); if (s != null) { int len = s.length; for (int i = 0; i < len; i++) { qw.write(s[i]); qw.write(Layout.LINE_SEP); } } } }
public synchronized void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException { super.setFile(fileName, append, this.bufferedIO, this.bufferSize); if(append) { File f = new File(fileName); ((CountingQuietWriter) qw).setCount(f.length()); } }
/** This method differentiates RollingFileAppender from its super class. @since 0.9.0 */ protected void subAppend(LoggingEvent event) { super.subAppend(event); if(fileName != null && qw != null) { long size = ((CountingQuietWriter) qw).getCount(); if (size >= maxFileSize && size >= nextRollover) { rollOver(); } } }
/** * Creates and opens the file for logging. If <code>staticLogFileName</code> * is false then the fully qualified name is determined and used. */ public synchronized void setFile(String fileName, boolean append) throws IOException { if (!staticLogFileName) { scheduledFilename = fileName = fileName.trim() + sdf.format(now); if (countDirection > 0) { scheduledFilename = fileName = fileName + '.' + (++curSizeRollBackups); } } super.setFile(fileName, append); if(append) { File f = new File(fileName); ((CountingQuietWriter) qw).setCount(f.length()); } }
public synchronized void setFile(boolean append) throws IOException { long len = res.length();// this is done here, because in the location used the file is already locked super.setFile(append); if(append) { ((CountingQuietWriter) qw).setCount(len); } }
/** This method differentiates RollingFileAppender from its super class. @since 0.9.0 */ protected void subAppend(LoggingEvent event) { super.subAppend(event); if(res != null && qw != null) { long size = ((CountingQuietWriter) qw).getCount(); if (size >= maxFileSize && size >= nextRollover) { rollOver(); } } }
@Override public synchronized void setFile(boolean append) throws IOException { long len = res.length();// this is done here, because in the location used the file is already locked super.setFile(append); if(append) { ((CountingQuietWriter) qw).setCount(len); } }
/** This method differentiates RollingFileAppender from its super class. @since 0.9.0 */ @Override protected void subAppend(LoggingEvent event) { super.subAppend(event); if(res != null && qw != null) { long size = ((CountingQuietWriter) qw).getCount(); if (size >= maxFileSize && size >= nextRollover) { rollOver(); } } }
/** This method differentiates RollingFileAppender from its super class. @since 0.9.0 */ protected void subAppend(LoggingEvent event) { super.subAppend(event); if((fileName != null) && ((CountingQuietWriter) qw).getCount() >= maxFileSize) this.rollOver(); }
/** * Implements roll overs base on file size. * * <p>If the maximum number of size based backups is reached (<code>curSizeRollBackups == maxSizeRollBackups</code) * then the oldest file is deleted -- it's index determined by the sign of countDirection.<br> If * <code>countDirection</code> < 0, then files {<code>File.1</code>, ..., <code>File.curSizeRollBackups -1</code>} * are renamed to {<code>File.2</code>, ..., <code>File.curSizeRollBackups</code>}. Moreover, <code>File</code> is * renamed <code>File.1</code> and closed.<br> * * A new file is created to receive further log output. * * <p>If <code>maxSizeRollBackups</code> is equal to zero, then the <code>File</code> is truncated with no backup * files created. * * <p>If <code>maxSizeRollBackups</code> < 0, then <code>File</code> is renamed if needed and no files are deleted. */ // synchronization not necessary since doAppend is alreasy synched protected void rollOverSize() { File file; this.closeFile(); // keep windows happy. LogLog.debug("rolling over count=" + ((CountingQuietWriter) qw).getCount()); LogLog.debug("maxSizeRollBackups = " + maxSizeRollBackups); LogLog.debug("curSizeRollBackups = " + curSizeRollBackups); LogLog.debug("countDirection = " + countDirection); // If maxBackups <= 0, then there is no file renaming to be done. if (maxSizeRollBackups != 0) { rollFile(); } try { // This will also close the file. This is OK since multiple // close operations are safe. this.setFile(baseFileName, false); } catch (IOException e) { LogLog.error("setFile(" + fileName + ", false) call failed.", e); } }
public synchronized void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize) throws IOException { super.setFile(fileName, append, this.bufferedIO, this.bufferSize); if (append) { File f = new File(fileName); ((CountingQuietWriter) qw).setCount(f.length()); } }
/** * This method differentiates RollingFileAppender from its super class. */ protected void subAppend(LoggingEvent event) { super.subAppend(event); if (fileName != null && qw != null) { long size = ((CountingQuietWriter) qw).getCount(); if (size >= maxFileSize && size >= nextRollover) { rollOver(); } } }
@Override protected void setQWForFiles(Writer writer) { qw = new CountingQuietWriter(writer, errorHandler); }
protected void setQWForFiles(Writer writer) { this.qw = new CountingQuietWriter(writer, errorHandler); }
protected void setQWForFiles(Writer writer) { qw = new CountingQuietWriter(writer, errorHandler); }
@Override protected void setQWForFiles(Writer writer) { this.qw = new CountingQuietWriter(writer, errorHandler); }
/** Implements the usual roll over behaviour. <p>If <code>MaxBackupIndex</code> is positive, then files {<code>File.1</code>, ..., <code>File.MaxBackupIndex -1</code>} are renamed to {<code>File.2</code>, ..., <code>File.MaxBackupIndex</code>}. Moreover, <code>File</code> is renamed <code>File.1</code> and closed. A new <code>File</code> is created to receive further log output. <p>If <code>MaxBackupIndex</code> is equal to zero, then the <code>File</code> is truncated with no backup files created. */ public // synchronization not necessary since doAppend is alreasy synched void rollOver() { File target; File file; if (qw != null) { LogLog.debug("rolling over count=" + ((CountingQuietWriter) qw).getCount()); } LogLog.debug("maxBackupIndex="+maxBackupIndex); // If maxBackups <= 0, then there is no file renaming to be done. if(maxBackupIndex > 0) { // Delete the oldest file, to keep Windows happy. file = new File(fileName + '.' + maxBackupIndex); if (file.exists()) file.delete(); // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} for (int i = maxBackupIndex - 1; i >= 1; i--) { file = new File(fileName + "." + i); if (file.exists()) { target = new File(fileName + '.' + (i + 1)); LogLog.debug("Renaming file " + file + " to " + target); file.renameTo(target); } } // Rename fileName to fileName.1 target = new File(fileName + "." + 1); this.closeFile(); // keep windows happy. file = new File(fileName); LogLog.debug("Renaming file " + file + " to " + target); file.renameTo(target); } try { // This will also close the file. This is OK since multiple // close operations are safe. this.setFile(fileName, false, bufferedIO, bufferSize); } catch(IOException e) { LogLog.error("setFile("+fileName+", false) call failed.", e); } }