Skip to content

Commit

Permalink
Reopens a StringLogger instance where the print writer have encounter…
Browse files Browse the repository at this point in the history
…ed an error, as in HA internal restart
  • Loading branch information
tinwelint committed Aug 30, 2011
1 parent 1460048 commit d969bb2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions kernel/src/main/java/org/neo4j/kernel/impl/util/StringLogger.java
Expand Up @@ -111,6 +111,7 @@ public void logMessage( String msg, Throwable cause )

public synchronized void logMessage( String msg, boolean flush )
{
ensureOpen();
out.println( new Date() + ": " + msg );
if ( flush )
{
Expand All @@ -121,6 +122,7 @@ public synchronized void logMessage( String msg, boolean flush )

public synchronized void logMessage( String msg, Throwable cause, boolean flush )
{
ensureOpen();
out.println( new Date() + ": " + msg + " " + cause.getMessage() );
cause.printStackTrace( out );
if ( flush )
Expand All @@ -130,6 +132,30 @@ public synchronized void logMessage( String msg, Throwable cause, boolean flush
checkRotation();
}

private void ensureOpen()
{
/*
* Since StringLogger has instances in its own static map and HA graph db
* does internal restarts of the database the StringLogger instances are kept
* whereas the actual files can be removed/replaced, making the PrintWriter
* fail at writing stuff and also swallowing those exceptions(!). Since we
* have this layout of static map of loggers we'll have to reopen the PrintWriter
* in such occasions. It'd be better to tie each StringLogger to a GraphDatabaseService.
*/
if ( out.checkError() )
{
out.close();
try
{
instantiateWriter();
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
}
}

private void checkRotation()
{
if ( rotationThreshold != null && file.length() > rotationThreshold.intValue() )
Expand Down

0 comments on commit d969bb2

Please sign in to comment.