Logs: Fix displayed filename when empty (ticket #1386)

- More synchronization
This commit is contained in:
zzz
2014-09-30 12:12:22 +00:00
parent bfd51097c9
commit 49eeb99d43

View File

@ -140,10 +140,13 @@ class LogWriter implements Runnable {
/** /**
* File may not exist or have old logs in it if not opened yet * File may not exist or have old logs in it if not opened yet
*/ */
public String currentFile() { public synchronized String currentFile() {
return _currentFile != null ? _currentFile.getAbsolutePath() if (_currentFile != null)
//: "uninitialized"; return _currentFile.getAbsolutePath();
: getNextFile(_manager.getBaseLogfilename()).getAbsolutePath(); String rv = getNextFile().getAbsolutePath();
// so it doesn't increment every time we call this
_rotationNum = -1;
return rv;
} }
private void rereadConfig() { private void rereadConfig() {
@ -173,7 +176,7 @@ class LogWriter implements Runnable {
} }
} }
private void writeRecord(String val) { private synchronized void writeRecord(String val) {
if (val == null) return; if (val == null) return;
if (_currentOut == null) { if (_currentOut == null) {
rotateFile(); rotateFile();
@ -200,10 +203,10 @@ class LogWriter implements Runnable {
/** /**
* Rotate to the next file (or the first file if this is the first call) * Rotate to the next file (or the first file if this is the first call)
* *
* Caller must synch
*/ */
private void rotateFile() { private void rotateFile() {
String pattern = _manager.getBaseLogfilename(); File f = getNextFile();
File f = getNextFile(pattern);
_currentFile = f; _currentFile = f;
_numBytesInCurrentFile = 0; _numBytesInCurrentFile = 0;
File parent = f.getParentFile(); File parent = f.getParentFile();
@ -242,8 +245,10 @@ class LogWriter implements Runnable {
/** /**
* Get the next file in the rotation * Get the next file in the rotation
* *
* Caller must synch
*/ */
private File getNextFile(String pattern) { private File getNextFile() {
String pattern = _manager.getBaseLogfilename();
File f = new File(pattern); File f = new File(pattern);
File base = null; File base = null;
if (!f.isAbsolute()) if (!f.isAbsolute())
@ -274,6 +279,7 @@ class LogWriter implements Runnable {
/** /**
* Retrieve the first file, updating the rotation number accordingly * Retrieve the first file, updating the rotation number accordingly
* *
* Caller must synch
*/ */
private File getFirstFile(File base, String pattern, int max) { private File getFirstFile(File base, String pattern, int max) {
for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {