Skip to content

Commit

Permalink
Fix creation of additional log file.
Browse files Browse the repository at this point in the history
  • Loading branch information
manstis committed Dec 6, 2011
1 parent e829675 commit 09d8f56
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ public void writeToDisk() {
for ( LogEvent event : eventsToWrite ) {
fileWriter.write( xstream.toXML( event ) + "\n" );
}
if ( split ) {
fileWriter.write( "</object-stream>" );
this.nbOfFile++;
initialized = false;
}
} catch ( final FileNotFoundException exc ) {
throw new RuntimeException( "Could not create the log file. Please make sure that directory that the log file should be placed in does exist." );
} catch ( final Throwable t ) {
Expand All @@ -144,7 +139,12 @@ public void writeToDisk() {
}
}
if ( terminate ) {
terminateLog();
closeLog();
terminate = true;
} else if ( split ) {
closeLog();
this.nbOfFile++;
initialized = false;
}
}

Expand All @@ -162,15 +162,14 @@ private void initializeLog() {
}
}

private void terminateLog() {
private void closeLog() {
try {
FileWriter writer = new FileWriter( this.fileName + (this.nbOfFile == 0 ? ".log" : this.nbOfFile + ".log"),
true );
writer.append( "</object-stream>\n" );
writer.close();
terminate = false;
} catch ( final FileNotFoundException exc ) {
throw new RuntimeException( "Could not terminate the log file. Please make sure that directory that the log file should be placed in does exist." );
throw new RuntimeException( "Could not close the log file. Please make sure that directory that the log file should be placed in does exist." );
} catch ( final Throwable t ) {
t.printStackTrace( System.err );
}
Expand Down Expand Up @@ -213,6 +212,9 @@ public void setSplit(boolean split) {
}

public void stop() {
if ( terminate ) {
throw new IllegalStateException( "Logger has already been closed." );
}
terminate = true;
writeToDisk();
}
Expand Down

0 comments on commit 09d8f56

Please sign in to comment.