Skip to content

Commit

Permalink
Merge remote branch 'origin/finer_grained_file_locks'
Browse files Browse the repository at this point in the history
  • Loading branch information
robey committed Jan 6, 2011
2 parents bb6c36f + 57e63ee commit c0bf9b3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/scala/net/lag/logging/FileHandler.scala
Expand Up @@ -135,7 +135,7 @@ class FileHandler(val filename: String, val policy: Policy, formatter: Formatter
}
}

def roll() = {
def roll() = synchronized {
stream.close()
val n = filename.lastIndexOf('.')
val newFilename = if (n > 0) {
Expand All @@ -148,13 +148,18 @@ class FileHandler(val filename: String, val policy: Policy, formatter: Formatter
removeOldFiles()
}

def publish(record: javalog.LogRecord) = synchronized {
def publish(record: javalog.LogRecord) = {
try {
if (System.currentTimeMillis > nextRollTime) {
roll
synchronized {
if (System.currentTimeMillis > nextRollTime) {
roll
}
}
val formattedLine = getFormatter.format(record)
synchronized {
stream.write(formattedLine)
stream.flush
}
stream.write(getFormatter.format(record))
stream.flush
} catch {
case e =>
System.err.println(Formatter.formatStackTrace(e, 30).mkString("\n"))
Expand Down

0 comments on commit c0bf9b3

Please sign in to comment.