1 | package org.etsi.t3d; |
---|
2 | |
---|
3 | import java.io.FileNotFoundException; |
---|
4 | import java.io.FileOutputStream; |
---|
5 | import java.io.PrintStream; |
---|
6 | import java.util.LinkedList; |
---|
7 | |
---|
8 | |
---|
9 | public class T3DLoggingInterface { |
---|
10 | //TODO: reuse statistics |
---|
11 | private PrintStream stream; |
---|
12 | private int LOG_LEVEL = 1; |
---|
13 | private String[] messageTypes = {"Information", "WARNING", "ERROR"}; |
---|
14 | private boolean firstFile = true; |
---|
15 | private LinkedList<String> files = new LinkedList<String>(); |
---|
16 | private LinkedList<String> filesWithoutErrorsWarnings = new LinkedList<String>(); |
---|
17 | |
---|
18 | |
---|
19 | public T3DLoggingInterface(){ |
---|
20 | } |
---|
21 | |
---|
22 | private class T3DLogEvent{ |
---|
23 | private int level; |
---|
24 | private int type; // 0 = info, 1 = warning, 2 = error |
---|
25 | private String event; |
---|
26 | private String lines; |
---|
27 | |
---|
28 | public T3DLogEvent(int level, int type, String event, String lines) { |
---|
29 | this.level = level; |
---|
30 | this.type = type; |
---|
31 | this.event = event; |
---|
32 | this.lines = lines; |
---|
33 | } |
---|
34 | |
---|
35 | public String toString(){ |
---|
36 | return "<" + messageTypes[type].toLowerCase() + " level =\""+ level +"\" lines=\"" + lines.trim() + "\">" + event + "</" + messageTypes[type].toLowerCase() + ">"; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | public void printLog(int LEVEL, String filename, int startLine, int endLine, int type, String output) { |
---|
42 | if (LEVEL <= this.getLOG_LEVEL()) { |
---|
43 | String lines; |
---|
44 | if (startLine >= endLine) { |
---|
45 | lines = " " + startLine; |
---|
46 | } else { |
---|
47 | lines = " " + startLine + "-" + endLine; |
---|
48 | } |
---|
49 | String log = " " + filename + ": " + lines + ": " + messageTypes[type] + ": " + output; |
---|
50 | System.out.println(log); |
---|
51 | setEvent(LEVEL, type, output, lines); |
---|
52 | if(type == 1 || type == 2) |
---|
53 | filesWithoutErrorsWarnings.remove(filename); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | private void setEvent(int level, int type, String event, String lines){ |
---|
59 | writeStream("\n\t\t" + new T3DLogEvent(level, type, event, lines)); |
---|
60 | } |
---|
61 | |
---|
62 | public void setLOG_LEVEL(int lOG_LEVEL) { |
---|
63 | LOG_LEVEL = lOG_LEVEL; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | public int getLOG_LEVEL() { |
---|
68 | return LOG_LEVEL; |
---|
69 | } |
---|
70 | |
---|
71 | public void setCurrentTTCN3File(String currentTTCN3File) { |
---|
72 | if(!firstFile) |
---|
73 | writeStream("\n\t</file>"); |
---|
74 | else |
---|
75 | firstFile = false; |
---|
76 | writeStream("\n\t<file path=\"" + currentTTCN3File + "\">"); |
---|
77 | files.add(currentTTCN3File); |
---|
78 | filesWithoutErrorsWarnings.add(currentTTCN3File); |
---|
79 | } |
---|
80 | |
---|
81 | private void writeStream(String content){ |
---|
82 | stream.print(content); |
---|
83 | } |
---|
84 | |
---|
85 | public void finishXML(){ |
---|
86 | writeStream("\n\t</file>"); |
---|
87 | writeStream("\n</t3dlog>"); |
---|
88 | |
---|
89 | System.out.println("\tINFORMATION:"); |
---|
90 | System.out.println("\t Files parsed:"); |
---|
91 | for(String file : files) |
---|
92 | System.out.println("\t " + file); |
---|
93 | System.out.println("\t Files processed without errors/warnings:"); |
---|
94 | for(String file : filesWithoutErrorsWarnings) |
---|
95 | System.out.println("\t " + file); |
---|
96 | System.out.println("\t Files processed with errors/warnings:"); |
---|
97 | for(String file : files) |
---|
98 | if(!filesWithoutErrorsWarnings.contains(file)) |
---|
99 | System.out.println("\t " + file); |
---|
100 | } |
---|
101 | |
---|
102 | public void setXMLPath(String xmlpath){ |
---|
103 | FileOutputStream file; |
---|
104 | try { |
---|
105 | file = new FileOutputStream(xmlpath); |
---|
106 | stream = new PrintStream(file); |
---|
107 | } catch (FileNotFoundException e) { |
---|
108 | e.printStackTrace(); |
---|
109 | } |
---|
110 | writeStream("\n<t3dlog t3dversion=\"" + T3D.versionNumber + "\">"); |
---|
111 | } |
---|
112 | } |
---|