Source code: org/alicebot/server/core/util/Trace.java
1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.geocities.com/kpdus/jad.html
3 // Decompiler options: packimports(3)
4
5 package org.alicebot.server.core.util;
6
7 import java.io.PrintStream;
8 import java.util.StringTokenizer;
9 import org.alicebot.server.core.Globals;
10
11 // Referenced classes of package org.alicebot.server.core.util:
12 // StackParser, MessagePrinter
13
14 public class Trace
15 {
16
17 public Trace()
18 {
19 }
20
21 public static void setOut(PrintStream printstream)
22 {
23 outStream = printstream;
24 }
25
26 public static void userfail(String s)
27 {
28 if(EMIT_USER_ERRORS)
29 {
30 if(!METHOD_NAMES_ALWAYS)
31 emit(s, USER_ERROR);
32 else
33 emit(StackParser.getStackMethodBefore("org.alicebot.server.core.util.", true) + ": " + s, USER_ERROR);
34 } else
35 {
36 emit("Fatal user error. User error messages are turned off.", USER_ERROR);
37 }
38 }
39
40 public static void userfail(Throwable throwable)
41 {
42 if(EMIT_USER_ERRORS)
43 emit(throwable, USER_ERROR);
44 else
45 emit("Fatal user error. User error messages are turned off.", USER_ERROR);
46 }
47
48 public static void userinfo(String s)
49 {
50 if(EMIT_USER_INFO)
51 if(!METHOD_NAMES_ALWAYS)
52 emit(s, USER_INFO);
53 else
54 emit(StackParser.getStackMethodBefore("org.alicebot.server.core.util.", true) + ": " + s, USER_INFO);
55 }
56
57 public static void userinfo(String as[])
58 {
59 if(EMIT_USER_INFO)
60 if(!METHOD_NAMES_ALWAYS)
61 emit(as, USER_INFO);
62 else
63 emit(as, StackParser.getStackMethodBefore("org.alicebot.server.core.util.", true) + ": ", USER_INFO);
64 }
65
66 public static void devfail(String s)
67 {
68 if(EMIT_DEVELOPER_ERRORS)
69 emit(StackParser.getStackMethodBefore("org.alicebot.server.core.util.", true) + ": " + s, DEVELOPER_ERROR);
70 else
71 emit("Fatal developer error. Developer error messages are turned off.", DEVELOPER_ERROR);
72 }
73
74 public static void devfail(String s, Throwable throwable)
75 {
76 if(EMIT_DEVELOPER_ERRORS)
77 {
78 emit(s, DEVELOPER_ERROR);
79 emit(throwable, DEVELOPER_ERROR);
80 } else
81 {
82 emit("Fatal developer error. Developer error messages are turned off.", DEVELOPER_ERROR);
83 }
84 }
85
86 public static void devfail(Throwable throwable)
87 {
88 if(EMIT_DEVELOPER_ERRORS)
89 emit(throwable, DEVELOPER_ERROR);
90 else
91 emit("Fatal developer error. Developer error messages are turned off.", DEVELOPER_ERROR);
92 }
93
94 public static void devinfo(String s)
95 {
96 if(EMIT_DEVELOPER_INFO)
97 emit(StackParser.getStackMethodBefore("org.alicebot.server.core.util.", true) + ": " + s, DEVELOPER_INFO);
98 }
99
100 public static void devinfo(Throwable throwable)
101 {
102 if(EMIT_DEVELOPER_ERRORS)
103 emit(throwable, DEVELOPER_ERROR);
104 }
105
106 public static void insist(String s)
107 {
108 emit(s, INSIST);
109 }
110
111 public static void insist(String as[])
112 {
113 emit(as, INSIST);
114 }
115
116 private static void emit(String s, String s1)
117 {
118 MessagePrinter.println(s, s1, outStream, 1);
119 }
120
121 private static void emit(String as[], String s)
122 {
123 for(int i = 0; i < as.length; i++)
124 MessagePrinter.println(as[i], s, outStream, 1);
125
126 }
127
128 private static void emit(String as[], String s, String s1)
129 {
130 for(int i = 0; i < as.length; i++)
131 MessagePrinter.println(s + as[i], s1, outStream, 1);
132
133 }
134
135 private static void emit(Throwable throwable, String s)
136 {
137 String s1 = throwable.getMessage();
138 if(s1 != null)
139 emit(s1, s);
140 for(StringTokenizer stringtokenizer = StackParser.getStackTraceFor(throwable); stringtokenizer.hasMoreElements();)
141 if(!METHOD_NAMES_ALWAYS)
142 emit(stringtokenizer.nextToken(), s);
143 else
144 emit(StackParser.getStackMethodBefore("org.alicebot.server.core.util.", true) + ": " + stringtokenizer.nextToken(), s);
145
146 }
147
148 private static final boolean EMIT_USER_INFO;
149 private static final boolean EMIT_USER_ERRORS;
150 private static final boolean EMIT_DEVELOPER_INFO;
151 private static final boolean METHOD_NAMES_ALWAYS;
152 private static final boolean EMIT_DEVELOPER_ERRORS;
153 private static final boolean SHOW_MESSAGE_FLAGS;
154 private static final String THIS_PACKAGE = "org.alicebot.server.core.util.";
155 private static final String FATAL_USER_UNINFORMATIVE = "Fatal user error. User error messages are turned off.";
156 private static final String FATAL_DEVELOPER_UNINFORMATIVE = "Fatal developer error. Developer error messages are turned off.";
157 private static final String EXITING = "Exiting.";
158 public static final String NO_FLAG = "";
159 public static final String PROGRAM_MESSAGE;
160 public static final String USER_INFO;
161 public static final String USER_ERROR;
162 public static final String DEVELOPER_INFO;
163 public static final String DEVELOPER_ERROR;
164 public static final String INSIST;
165 public static final String COLON_SPACE = ": ";
166 private static PrintStream outStream;
167
168 static
169 {
170 EMIT_USER_INFO = Globals.showConsole();
171 EMIT_USER_ERRORS = EMIT_USER_INFO;
172 EMIT_DEVELOPER_INFO = EMIT_USER_INFO ? Boolean.valueOf(Globals.getProperty("programd.console.developer", "false")).booleanValue() : false;
173 METHOD_NAMES_ALWAYS = EMIT_DEVELOPER_INFO ? Boolean.valueOf(Globals.getProperty("programd.console.developer.method-names-always", "false")).booleanValue() : false;
174 EMIT_DEVELOPER_ERRORS = EMIT_DEVELOPER_INFO;
175 SHOW_MESSAGE_FLAGS = Boolean.valueOf(Globals.getProperty("programd.console.message-flags", "true")).booleanValue();
176 PROGRAM_MESSAGE = SHOW_MESSAGE_FLAGS ? "P " : "";
177 USER_INFO = SHOW_MESSAGE_FLAGS ? "u " : "";
178 USER_ERROR = SHOW_MESSAGE_FLAGS ? "U " : "";
179 DEVELOPER_INFO = SHOW_MESSAGE_FLAGS ? "d " : "";
180 DEVELOPER_ERROR = SHOW_MESSAGE_FLAGS ? "D " : "";
181 INSIST = SHOW_MESSAGE_FLAGS ? "! " : "";
182 outStream = System.out;
183 }
184 }