Skip to content

Commit

Permalink
Merge pull request #12 from calvinjia/master
Browse files Browse the repository at this point in the history
Specific Log rotation
  • Loading branch information
haoyuan committed Mar 18, 2013
2 parents 4195c73 + 30b27dd commit f69481d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
38 changes: 19 additions & 19 deletions conf/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ log4j.appender.Console.Target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %-5p %c{1} (%F:%M) - %m%n

log4j.logger.org.eclipse.jetty=INFO, MasterAppender
log4j.logger.org.eclipse.jetty=INFO, MASTER_LOGGER
log4j.additivity.org.eclipse.jetty=false

# Logger for Master
log4j.logger.MASTER_LOGGER=INFO, MasterAppender
log4j.logger.MASTER_LOGGER=INFO, MASTER_LOGGER
log4j.additivity.MASTER_LOGGER=false
log4j.appender.MasterAppender=tachyon.TachyonFileAppender
log4j.appender.MasterAppender.File=logs/master.log
log4j.appender.MASTER_LOGGER=tachyon.TachyonFileAppender
log4j.appender.MASTER_LOGGER.File=logs/master.log

log4j.appender.MasterAppender.MaxFileSize=10
log4j.appender.MasterAppender.MaxBackupIndex=100
log4j.appender.MasterAppender.DeletionPercentage=10
log4j.appender.MasterAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.MasterAppender.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M) - %m%n
#log4j.appender.MasterAppender.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
log4j.appender.MASTER_LOGGER.MaxFileSize=10
log4j.appender.MASTER_LOGGER.MaxBackupIndex=100
log4j.appender.MASTER_LOGGER.DeletionPercentage=10
log4j.appender.MASTER_LOGGER.layout=org.apache.log4j.PatternLayout
log4j.appender.MASTER_LOGGER.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M) - %m%n
#log4j.appender.MASTER_LOGGER.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n

# Logger for Workers
log4j.logger.WORKER_LOGGER=INFO, WorkerAppender
log4j.logger.WORKER_LOGGER=INFO, WORKER_LOGGER
log4j.additivity.WORKER_LOGGER=false
log4j.appender.WorkerAppender=tachyon.TachyonFileAppender
log4j.appender.WorkerAppender.File=logs/worker.log
log4j.appender.WORKER_LOGGER=tachyon.TachyonFileAppender
log4j.appender.WORKER_LOGGER.File=logs/worker.log

log4j.appender.WorkerAppender.MaxFileSize=10
log4j.appender.WorkerAppender.MaxBackupIndex=100
log4j.appender.WorkerAppender.DeletionPercentage=10
log4j.appender.WorkerAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.WorkerAppender.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M) - %m%n
#log4j.appender.WorkerAppender.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
log4j.appender.WORKER_LOGGER.MaxFileSize=10
log4j.appender.WORKER_LOGGER.MaxBackupIndex=100
log4j.appender.WORKER_LOGGER.DeletionPercentage=10
log4j.appender.WORKER_LOGGER.layout=org.apache.log4j.PatternLayout
log4j.appender.WORKER_LOGGER.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M) - %m%n
#log4j.appender.WORKER_LOGGER.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
28 changes: 15 additions & 13 deletions src/main/java/tachyon/TachyonFileAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ public void setDeletionPercentage(int deletionPercentage) {
@Override
public void activateOptions() {
if (fileName != null) {
if (!fileName.equals(mCurrentFileName)) {
mOriginalFileName = fileName;
} else {
fileName = mOriginalFileName;
}
try {
fileName = getNewLogFileName(fileName);
setFile(fileName, fileAppend, bufferedIO, bufferSize);
} catch (Exception e) {
errorHandler.error("Error while activating log options", e,
ErrorCode.FILE_OPEN_FAILURE);
if (Config.LOGGER_TYPE.equals(getName())) {
if (!fileName.equals(mCurrentFileName)) {
mOriginalFileName = fileName;
} else {
fileName = mOriginalFileName;
}
try {
fileName = getNewLogFileName(fileName);
setFile(fileName, fileAppend, bufferedIO, bufferSize);
} catch (Exception e) {
errorHandler.error("Error while activating log options", e,
ErrorCode.FILE_OPEN_FAILURE);
}
}
}
}
Expand All @@ -61,7 +63,7 @@ public void activateOptions() {
public synchronized void setFile(String fileName, boolean append, boolean bufferedIO,
int bufferSize) throws IOException {
// It does not make sense to have immediate flush and bufferedIO.
if(bufferedIO) {
if (bufferedIO) {
setImmediateFlush(false);
}

Expand All @@ -71,7 +73,7 @@ public synchronized void setFile(String fileName, boolean append, boolean buffer
LazyFileOutputStream ostream = new LazyFileOutputStream(fileName, append);

Writer fw = createWriter(ostream);
if(bufferedIO) {
if (bufferedIO) {
fw = new BufferedWriter(fw, bufferSize);
}
setQWForFiles(fw);
Expand Down

0 comments on commit f69481d

Please sign in to comment.