|
@@ -0,0 +1,58 @@
|
|
1
|
+package org.openzen.zenscript.scriptingexample.logging;
|
|
2
|
+
|
|
3
|
+import org.openzen.zencode.java.IZSLogger;
|
|
4
|
+
|
|
5
|
+import java.io.PrintStream;
|
|
6
|
+
|
|
7
|
+public class StreamLogger implements IZSLogger {
|
|
8
|
+ private final PrintStream infoStream, debugStream, warningStream, errorStream;
|
|
9
|
+
|
|
10
|
+ public StreamLogger(PrintStream debugStream, PrintStream infoStream, PrintStream warningStream, PrintStream errorStream) {
|
|
11
|
+ this.infoStream = infoStream;
|
|
12
|
+ this.debugStream = debugStream;
|
|
13
|
+ this.warningStream = warningStream;
|
|
14
|
+ this.errorStream = errorStream;
|
|
15
|
+ }
|
|
16
|
+
|
|
17
|
+ public StreamLogger(PrintStream normalStream, PrintStream errorStream) {
|
|
18
|
+ this(normalStream, normalStream, normalStream, errorStream);
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ public StreamLogger(){
|
|
22
|
+ this(System.out, System.err);
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ @Override
|
|
26
|
+ public void info(String message) {
|
|
27
|
+ System.out.println("INFO: " + message);
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ @Override
|
|
31
|
+ public void debug(String message) {
|
|
32
|
+ System.out.println("DEBUG: " + message);
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ @Override
|
|
36
|
+ public void warning(String message) {
|
|
37
|
+ System.out.println("WARNING: " + message);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ @Override
|
|
41
|
+ public void error(String message) {
|
|
42
|
+ System.err.println("ERROR: " + message);
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ @Override
|
|
46
|
+ public void throwingErr(String message, Throwable throwable) {
|
|
47
|
+ System.err.println("ERROR: " + message);
|
|
48
|
+ throwable.printStackTrace(System.err);
|
|
49
|
+ System.err.flush();
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ @Override
|
|
53
|
+ public void throwingWarn(String message, Throwable throwable) {
|
|
54
|
+ System.err.println("WARNING: " + message);
|
|
55
|
+ throwable.printStackTrace(System.out);
|
|
56
|
+ System.out.flush();
|
|
57
|
+ }
|
|
58
|
+}
|