I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 49eeb99d authored by zzz's avatar zzz
Browse files

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

 - More synchronization
parent bfd51097
No related branches found
No related tags found
No related merge requests found
...@@ -140,10 +140,13 @@ class LogWriter implements Runnable { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment