Fixed issue where multiple threads wrote to log file simultaneously and improved LogEntry

This commit is contained in:
Rohit Awate 2018-02-28 23:55:53 +05:30
parent c249160e1f
commit 2361da62eb
2 changed files with 5 additions and 6 deletions

View file

@ -38,7 +38,7 @@ class Logger {
*
* @param log - The log to be written to file.
*/
void log(Log log) {
synchronized void log(Log log) {
if (log.getLevel().greaterThanEqualTo(this.writerLevel)) {
try {
String logFileContents = readFile(logFilePath);
@ -72,6 +72,8 @@ class Logger {
if (log.getException() != null) {
StackTraceElement[] stackTrace = log.getException().getStackTrace();
builder.append(log.getException().toString());
builder.append("<br>\n");
if (stackTrace.length != 0) {
for (StackTraceElement element : log.getException().getStackTrace()) {
builder.append(" -- ");
@ -79,10 +81,9 @@ class Logger {
builder.append("<br>\n");
}
} else {
builder.append("N/A");
builder.append("Stack trace unavailable.");
}
} else {
logEntry = logEntry.replace("Stack Trace: <br>", "");
builder.append("");
}

View file

@ -1,8 +1,6 @@
<p class="%% LogLevel %%">
<strong>%% LogLevel %%</strong> %% Time %% <br>
<strong>%% Message %%</strong> <br>
Stack Trace: <br>
%% StackTrace %%
</p>
<!-- Placeholder for new log -->
<br>
<!-- Placeholder for new log -->