forked from tushartushar/DesigniteJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.java
More file actions
29 lines (26 loc) · 852 Bytes
/
Logger.java
File metadata and controls
29 lines (26 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package Designite.utils;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
public class Logger {
public static String logFile = null;
public static void log(String str) {
System.out.println(str);
if (logFile == null) {
//Commented the following line just to make the execution non-verbose
//System.out.println("Log file path has been not set. Logging not support.");
return;
}
try (Writer writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(logFile, true), StandardCharsets.UTF_8))) {
writer.write(str + "\n");
writer.close();
} catch (IOException ex) {
System.out.println("Exception during logging. " + ex.getMessage());
}
}
}