From 6bc7a3d8aae70eceebadd71e4a968a634c2582c9 Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Sat, 14 Aug 2004 20:57:50 +0000
Subject: [PATCH] handle errors initializing, and deal with logFilePatterns
 that don't include a full path (e.g. log-#.txt instead of logs/log-#.txt)

---
 core/java/src/net/i2p/util/LogWriter.java | 32 ++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/core/java/src/net/i2p/util/LogWriter.java b/core/java/src/net/i2p/util/LogWriter.java
index 0b476ff278..a4c8b34666 100644
--- a/core/java/src/net/i2p/util/LogWriter.java
+++ b/core/java/src/net/i2p/util/LogWriter.java
@@ -46,10 +46,16 @@ class LogWriter implements Runnable {
 
     public void run() {
         _write = true;
-        rotateFile();
-        while (_write) {
-            flushRecords();
-            rereadConfig();
+        try {
+            rotateFile();
+            while (_write) {
+                flushRecords();
+                rereadConfig();
+            }
+            System.err.println("Done writing");
+        } catch (Exception e) {
+            System.err.println("Error writing the logs: " + e.getMessage());
+            e.printStackTrace();
         }
     }
 
@@ -131,17 +137,19 @@ class LogWriter implements Runnable {
         _currentFile = f;
         _numBytesInCurrentFile = 0;
         File parent = f.getParentFile();
-        if (!parent.exists()) {
-            boolean ok = parent.mkdirs();
-            if (!ok) {
-                System.err.println("Unable to create the parent directy: " + parent.getAbsolutePath());
+        if (parent != null) {
+            if (!parent.exists()) {
+                boolean ok = parent.mkdirs();
+                if (!ok) {
+                    System.err.println("Unable to create the parent directy: " + parent.getAbsolutePath());
+                    System.exit(0);
+                }
+            }
+            if (!parent.isDirectory()) {
+                System.err.println("wtf, we cannot put the logs in a subdirectory of a plain file!  we want to stre the log as " + f.getAbsolutePath());
                 System.exit(0);
             }
         }
-        if (!parent.isDirectory()) {
-            System.err.println("wtf, we cannot put the logs in a subdirectory of a plain file!  we want to stre the log as " + f.getAbsolutePath());
-            System.exit(0);
-        }
         try {
             _currentOut = new FileOutputStream(f);
         } catch (IOException ioe) {
-- 
GitLab