Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe7f137
commit a7dfdd0
Showing
9 changed files
with
217 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/de/quaddy_services/proxy/logging/FileLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package de.quaddy_services.proxy.logging; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* | ||
*/ | ||
public class FileLogger { | ||
private File file; | ||
|
||
FileLogger(File aFile) { | ||
file = aFile; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public synchronized void log(String aPrefix, String aLevel, String aMessage, Throwable aE) { | ||
try { | ||
FileWriter tempFileWriter = new FileWriter(file, true); | ||
try { | ||
String tempText = LocalDateTime.now().toString() + ":" + aLevel + ":" + aPrefix + ":" + aMessage; | ||
System.out.println(tempText); | ||
tempFileWriter.write(tempText); | ||
if (aE != null) { | ||
tempFileWriter.write(System.lineSeparator()); | ||
aE.printStackTrace(new PrintWriter(tempFileWriter)); | ||
aE.printStackTrace(); | ||
} | ||
tempFileWriter.write(System.lineSeparator()); | ||
} finally { | ||
tempFileWriter.close(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
src/main/java/de/quaddy_services/proxy/logging/Logger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package de.quaddy_services.proxy.logging; | ||
|
||
/** | ||
* | ||
*/ | ||
public class Logger { | ||
|
||
private String prefix; | ||
private FileLogger fileLogger; | ||
private Boolean debugEnabled; | ||
private Boolean traceEnabled; | ||
|
||
/** | ||
* | ||
*/ | ||
public Logger(String aPrefix, FileLogger aFile) { | ||
prefix = aPrefix; | ||
fileLogger = aFile; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void info(String aMessage) { | ||
info(aMessage, (Throwable) null); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void error(String aMessage, Throwable aE) { | ||
fileLogger.log(prefix, "error", aMessage, aE); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void debug(String aMessage, Throwable aE) { | ||
if (isDebugEnabled()) { | ||
fileLogger.log(prefix, "debug", aMessage, aE); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void debug(String aString, Object anObject) { | ||
if (isDebugEnabled()) { | ||
debug(aString.replaceFirst("\\{\\}", String.valueOf(anObject))); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public boolean isDebugEnabled() { | ||
if (debugEnabled == null) { | ||
String tempDefaultLevel = System.getProperty("defaultLogLevel"); | ||
debugEnabled = "debug".equalsIgnoreCase(tempDefaultLevel); | ||
} | ||
return debugEnabled; | ||
} | ||
|
||
public boolean isTraceEnabled() { | ||
if (traceEnabled == null) { | ||
String tempDefaultLevel = System.getProperty("defaultLogLevel"); | ||
traceEnabled = "trace".equalsIgnoreCase(tempDefaultLevel); | ||
} | ||
return traceEnabled; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void debug(String aString) { | ||
debug(aString, (Throwable) null); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void info(String aMessage, Throwable aE) { | ||
fileLogger.log(prefix, "info", aMessage, aE); | ||
|
||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void error(String aString) { | ||
error(aString, (Throwable) null); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void debug(String aString, Object aO1, Object aO2) { | ||
debug(aString.replaceFirst("\\{\\}", String.valueOf(aO1)).replaceFirst("\\{\\}", String.valueOf(aO2))); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public void trace(String aString) { | ||
if (isTraceEnabled()) { | ||
fileLogger.log(prefix, "trace", aString, (Throwable) null); | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/de/quaddy_services/proxy/logging/LoggerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.quaddy_services.proxy.logging; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* | ||
*/ | ||
public class LoggerFactory { | ||
|
||
private static LoggerFactory instance; | ||
private FileLogger fileLogger; | ||
|
||
/** | ||
* | ||
*/ | ||
public static Logger getLogger(Class<?> aClass) { | ||
return getInstance().getLoggerFor(aClass); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private Logger getLoggerFor(Class<?> aClass) { | ||
String aName = aClass.getName(); | ||
|
||
return new Logger(aName.substring(aName.lastIndexOf(".") + 1), fileLogger); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private static synchronized LoggerFactory getInstance() { | ||
if (instance == null) { | ||
File temp3 = new File(System.getProperty("java.io.tmpdir") + "/escape-from-intranet-3.log"); | ||
temp3.delete(); | ||
File temp2 = new File(System.getProperty("java.io.tmpdir") + "/escape-from-intranet-2.log"); | ||
temp2.renameTo(temp3); | ||
File temp1 = new File(System.getProperty("java.io.tmpdir") + "/escape-from-intranet-1.log"); | ||
temp1.renameTo(temp2); | ||
File temp0 = new File(System.getProperty("java.io.tmpdir") + "/escape-from-intranet.log"); | ||
temp0.renameTo(temp1); | ||
|
||
instance = new LoggerFactory(); | ||
instance.fileLogger = new FileLogger(temp0); | ||
} | ||
return instance; | ||
} | ||
|
||
} |