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/om/Logger.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.om;
23
24
import java.io.File;
25
26
/**
27
* The J9 JCL Preprocessor logging class.
28
*/
29
public abstract class Logger {
30
/** The default message source ID */
31
public static final String DEFAULT_MESSAGE_SOURCE = "builder";
32
33
/** Info severity constant (value 0) indicating information only. */
34
public static final int SEVERITY_INFO = 1;
35
/** Warning severity constant (value 1) indicating a warning. */
36
public static final int SEVERITY_WARNING = 2;
37
/** Error severity constant (value 2) indicating an error state. */
38
public static final int SEVERITY_ERROR = 3;
39
/** Fatal error severity constant (value 2) indicating an fatal state. */
40
public static final int SEVERITY_FATAL = 4;
41
42
/* The current source of error messages */
43
private String messageSource = DEFAULT_MESSAGE_SOURCE;
44
45
private int errorCount = 0;
46
47
/**
48
* Sets the message source.
49
*
50
* @param messageSource the message source
51
*/
52
public void setMessageSource(String messageSource) {
53
if (messageSource == null) {
54
messageSource = DEFAULT_MESSAGE_SOURCE;
55
}
56
this.messageSource = messageSource;
57
}
58
59
/**
60
* Returns the logger's error count.
61
*
62
* @return the error count
63
*/
64
public int getErrorCount() {
65
return this.errorCount;
66
}
67
68
/**
69
* Logs a preprocessor message.
70
*
71
* @param message the message to be logged
72
* @param severity the message severity
73
*/
74
public void log(String message, int severity) {
75
log(message, this.messageSource, severity);
76
}
77
78
/**
79
* Logs a throwable preprocessor message.
80
*
81
* @param message the message to be logged
82
* @param severity the message severity
83
* @param rootThrowable the message throwable
84
*/
85
public void log(String message, int severity, Throwable rootThrowable) {
86
log(message, this.messageSource, severity, rootThrowable);
87
}
88
89
/**
90
* Logs a preprocessor message.
91
*
92
* @param message the message to be logged
93
* @param messageSource the message source
94
* @param severity the message severity
95
*/
96
public void log(String message, String messageSource, int severity) {
97
if (severity >= SEVERITY_ERROR) {
98
errorCount++;
99
}
100
logImpl(message, messageSource, severity);
101
}
102
103
/**
104
* Logs a throwable preprocessor message.
105
*
106
* @param message the message to be logged
107
* @param messageSource the message source
108
* @param severity the message severity
109
* @param rootThrowable the message throwable
110
*/
111
public void log(String message, String messageSource, int severity, Throwable rootThrowable) {
112
if (severity >= SEVERITY_ERROR) {
113
errorCount++;
114
}
115
logImpl(message, messageSource, severity, rootThrowable);
116
}
117
118
/**
119
* Logs a preprocessor message.
120
*
121
* @param message the message to be logged
122
* @param messageSource the message source
123
* @param severity the message severity
124
* @param file the file in which the message occurs
125
*/
126
public void log(String message, String messageSource, int severity, File file) {
127
if (severity >= SEVERITY_ERROR) {
128
errorCount++;
129
}
130
logImpl(message, messageSource, severity, file);
131
}
132
133
/**
134
* Logs a throwable preprocessor message.
135
*
136
* @param message the message to be logged
137
* @param messageSource the message source
138
* @param severity the message severity
139
* @param file the file in which the message occurs
140
* @param rootThrowable the message throwable
141
*/
142
public void log(String message, String messageSource, int severity, File file, Throwable rootThrowable) {
143
if (severity >= SEVERITY_ERROR) {
144
errorCount++;
145
}
146
logImpl(message, messageSource, severity, file, rootThrowable);
147
}
148
149
/**
150
* Logs a preprocessor message.
151
*
152
* @param message the message to be logged
153
* @param messageSource the message source
154
* @param severity the message severity
155
* @param file the file in which the message occurs
156
* @param line the line in which the message occurs
157
* @param charStart the character in which the message starts
158
* @param charEnd the character in which the message ends
159
*/
160
public void log(String message, String messageSource, int severity, File file, int line, int charStart, int charEnd) {
161
if (severity >= SEVERITY_ERROR) {
162
errorCount++;
163
}
164
logImpl(message, messageSource, severity, file, line, charStart, charEnd);
165
}
166
167
protected abstract void logImpl(String message, String messageSource, int severity);
168
169
protected abstract void logImpl(String message, String messageSource, int severity, Throwable rootThrowable);
170
171
protected abstract void logImpl(String message, String messageSource, int severity, File file);
172
173
protected abstract void logImpl(String message, String messageSource, int severity, File file, Throwable rootThrowable);
174
175
protected abstract void logImpl(String message, String messageSource, int severity, File file, int line, int charStart, int charEnd);
176
177
}
178
179