Browse Source

Made ScriptingExample log to Console

kindlich 4 years ago
parent
commit
59f5cb9a0a
No known key found for this signature in database

+ 2
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java View File

@@ -21,11 +21,13 @@ import org.openzen.zenscript.parser.SimpleBracketParser;
21 21
 import org.openzen.zenscript.scriptingexample.events.EventManager;
22 22
 import org.openzen.zenscript.scriptingexample.events.IEvent;
23 23
 import org.openzen.zenscript.scriptingexample.events.impl.CTStringedEvent;
24
+import org.openzen.zenscript.scriptingexample.logging.StreamLogger;
24 25
 
25 26
 public class Main {
26 27
 	public static void main(String[] args) throws CompileException, ParseException, IOException, NoSuchMethodException {
27 28
 		ScriptingEngine scriptingEngine = new ScriptingEngine();
28 29
 		scriptingEngine.debug = true;
30
+		scriptingEngine.logger = new StreamLogger();
29 31
 
30 32
 		JavaNativeModule example = scriptingEngine.createNativeModule("example", "org.openzen.zenscript.scriptingexample");
31 33
 		example.addGlobals(Globals.class);

+ 58
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/logging/StreamLogger.java View File

@@ -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
+}

Loading…
Cancel
Save