aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/LoggingUtils.java
blob: 3e8219d53a6ef97e4599efd9b4105fc2717739a4 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package gtPlusPlus.core.util;

import java.io.*;
import java.util.Date;

public class LoggingUtils {

	public static void profileLog(final Object o){
		try {
			String content;
			final File file = new File("GregtechTimingsTC.txt");
			// if file doesnt exists, then create it
			if (!file.exists()) {
				file.createNewFile();
				final FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
				final BufferedWriter bw = new BufferedWriter(fw);
				bw.write("============================================================");
				bw.write(System.lineSeparator());
				bw.close();
			}
			if (o instanceof String){
				content = (String) o;
			}
			else {
				content = o.toString();
			}
			final FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
			final BufferedWriter bw = new BufferedWriter(fw);
			bw.write(content);
			bw.write(System.lineSeparator());
			bw.close();
			System.out.println("Data Logged.");

		} catch (final IOException e) {
			System.out.println("Data logging failed.");
		}
	}

	public static boolean logCurrentSystemTime(final String message){
		final Date date = new Date(System.currentTimeMillis());
		try {
			profileLog(message+" | "+date.toString());
			return true;
		}
		catch (final Throwable r) {
			return false;
		}

	}

}