Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/com.ibm.jpp.preprocessor/com/ibm/jpp/commandline/CommandlineLogger.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 1999, 2017 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.jpp.commandline;
23
24
import java.io.File;
25
import java.io.PrintStream;
26
27
import com.ibm.jpp.om.Logger;
28
29
/**
30
* Commandline implementation of the Preprocessor logger. This implementation simply
31
* printers the preprocessor errors to the screen in a organized fashion.
32
*/
33
public class CommandlineLogger extends Logger {
34
35
/**
36
* Logs a preprocessor message.
37
*
38
* @param message the message to be logged
39
* @param messageSource the message source
40
* @param severity the message severity
41
*
42
* @see Logger#log(String, String, int)
43
*/
44
@Override
45
public void logImpl(String message, String messageSource, int severity) {
46
@SuppressWarnings("resource")
47
PrintStream out = createOutputStream(severity);
48
49
out.print("[");
50
out.print(messageSource);
51
out.print("] ");
52
out.print(message);
53
out.println();
54
out.flush();
55
}
56
57
/**
58
* Logs a throwable preprocessor message.
59
*
60
* @param message the message to be logged
61
* @param messageSource the message source
62
* @param severity the message severity
63
* @param rootThrowable the message throwable
64
*
65
* @see Logger#log(String, String, int, Throwable)
66
*/
67
@Override
68
public void logImpl(String message, String messageSource, int severity, Throwable rootThrowable) {
69
@SuppressWarnings("resource")
70
PrintStream out = createOutputStream(severity);
71
72
out.print("[");
73
out.print(messageSource);
74
out.print("] ");
75
out.print(message);
76
out.println();
77
out.println("---------- START STACK TRACE ----------");
78
rootThrowable.printStackTrace(out);
79
out.println("----------- END STACK TRACE -----------");
80
out.flush();
81
}
82
83
protected PrintStream createOutputStream(int severity) {
84
PrintStream out;
85
if (severity >= SEVERITY_ERROR) {
86
out = System.err;
87
out.print("ERROR ");
88
} else {
89
out = System.out;
90
}
91
return out;
92
}
93
94
/**
95
* Logs a preprocessor message.
96
*
97
* @param message the message to be logged
98
* @param messageSource the message source
99
* @param severity the message severity
100
* @param file the file in which the message occurs
101
*
102
* @see Logger#log(String, String, int, File)
103
*/
104
@Override
105
public void logImpl(String message, String messageSource, int severity, File file) {
106
@SuppressWarnings("resource")
107
PrintStream out = createOutputStream(severity);
108
109
out.print("[");
110
out.print(messageSource);
111
out.print("] ");
112
out.print(message);
113
out.println();
114
out.print(" file: ");
115
out.print(file.getAbsolutePath());
116
out.println();
117
out.flush();
118
}
119
120
/**
121
* Logs a preprocessor message.
122
*
123
* @param message the message to be logged
124
* @param messageSource the message source
125
* @param severity the message severity
126
* @param file the file in which the message occurs
127
* @param line the line in which the message occurs
128
* @param charStart the character in which the message starts
129
* @param charEnd the character in which the message ends
130
*
131
* @see Logger#log(String, String, int, File, int, int, int)
132
*/
133
@Override
134
public void logImpl(String message, String messageSource, int severity, File file, int line, int charStart, int charEnd) {
135
@SuppressWarnings("resource")
136
PrintStream out = createOutputStream(severity);
137
138
out.print("[");
139
out.print(messageSource);
140
out.print("] ");
141
out.print(message);
142
out.println();
143
144
out.print(" file: ");
145
out.print(file.getAbsolutePath());
146
out.println();
147
148
out.print(" line: ");
149
out.print(line);
150
out.print(" (char ");
151
out.print(charStart);
152
out.print(" to ");
153
out.print(charEnd);
154
out.print(")");
155
out.println();
156
157
out.flush();
158
}
159
160
/**
161
* Logs a throwable preprocessor message.
162
*
163
* @param message the message to be logged
164
* @param messageSource the message source
165
* @param severity the message severity
166
* @param file the file in which the message occurs
167
* @param rootThrowable the message throwable
168
*
169
* @see Logger#logImpl(String, String, int, File, Throwable)
170
*/
171
@Override
172
protected void logImpl(String message, String messageSource, int severity, File file, Throwable rootThrowable) {
173
@SuppressWarnings("resource")
174
PrintStream out = createOutputStream(severity);
175
176
out.print("[");
177
out.print(messageSource);
178
out.print("] ");
179
out.print(message);
180
out.println();
181
out.print(" file: ");
182
out.print(file.getAbsolutePath());
183
out.println();
184
out.println("---------- START STACK TRACE ----------");
185
rootThrowable.printStackTrace(out);
186
out.println("----------- END STACK TRACE -----------");
187
out.flush();
188
}
189
190
}
191
192