Path: blob/master/sourcetools/com.ibm.jpp.preprocessor/com/ibm/jpp/om/Logger.java
6004 views
/*******************************************************************************1* Copyright (c) 1999, 2017 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/21package com.ibm.jpp.om;2223import java.io.File;2425/**26* The J9 JCL Preprocessor logging class.27*/28public abstract class Logger {29/** The default message source ID */30public static final String DEFAULT_MESSAGE_SOURCE = "builder";3132/** Info severity constant (value 0) indicating information only. */33public static final int SEVERITY_INFO = 1;34/** Warning severity constant (value 1) indicating a warning. */35public static final int SEVERITY_WARNING = 2;36/** Error severity constant (value 2) indicating an error state. */37public static final int SEVERITY_ERROR = 3;38/** Fatal error severity constant (value 2) indicating an fatal state. */39public static final int SEVERITY_FATAL = 4;4041/* The current source of error messages */42private String messageSource = DEFAULT_MESSAGE_SOURCE;4344private int errorCount = 0;4546/**47* Sets the message source.48*49* @param messageSource the message source50*/51public void setMessageSource(String messageSource) {52if (messageSource == null) {53messageSource = DEFAULT_MESSAGE_SOURCE;54}55this.messageSource = messageSource;56}5758/**59* Returns the logger's error count.60*61* @return the error count62*/63public int getErrorCount() {64return this.errorCount;65}6667/**68* Logs a preprocessor message.69*70* @param message the message to be logged71* @param severity the message severity72*/73public void log(String message, int severity) {74log(message, this.messageSource, severity);75}7677/**78* Logs a throwable preprocessor message.79*80* @param message the message to be logged81* @param severity the message severity82* @param rootThrowable the message throwable83*/84public void log(String message, int severity, Throwable rootThrowable) {85log(message, this.messageSource, severity, rootThrowable);86}8788/**89* Logs a preprocessor message.90*91* @param message the message to be logged92* @param messageSource the message source93* @param severity the message severity94*/95public void log(String message, String messageSource, int severity) {96if (severity >= SEVERITY_ERROR) {97errorCount++;98}99logImpl(message, messageSource, severity);100}101102/**103* Logs a throwable preprocessor message.104*105* @param message the message to be logged106* @param messageSource the message source107* @param severity the message severity108* @param rootThrowable the message throwable109*/110public void log(String message, String messageSource, int severity, Throwable rootThrowable) {111if (severity >= SEVERITY_ERROR) {112errorCount++;113}114logImpl(message, messageSource, severity, rootThrowable);115}116117/**118* Logs a preprocessor message.119*120* @param message the message to be logged121* @param messageSource the message source122* @param severity the message severity123* @param file the file in which the message occurs124*/125public void log(String message, String messageSource, int severity, File file) {126if (severity >= SEVERITY_ERROR) {127errorCount++;128}129logImpl(message, messageSource, severity, file);130}131132/**133* Logs a throwable preprocessor message.134*135* @param message the message to be logged136* @param messageSource the message source137* @param severity the message severity138* @param file the file in which the message occurs139* @param rootThrowable the message throwable140*/141public void log(String message, String messageSource, int severity, File file, Throwable rootThrowable) {142if (severity >= SEVERITY_ERROR) {143errorCount++;144}145logImpl(message, messageSource, severity, file, rootThrowable);146}147148/**149* Logs a preprocessor message.150*151* @param message the message to be logged152* @param messageSource the message source153* @param severity the message severity154* @param file the file in which the message occurs155* @param line the line in which the message occurs156* @param charStart the character in which the message starts157* @param charEnd the character in which the message ends158*/159public void log(String message, String messageSource, int severity, File file, int line, int charStart, int charEnd) {160if (severity >= SEVERITY_ERROR) {161errorCount++;162}163logImpl(message, messageSource, severity, file, line, charStart, charEnd);164}165166protected abstract void logImpl(String message, String messageSource, int severity);167168protected abstract void logImpl(String message, String messageSource, int severity, Throwable rootThrowable);169170protected abstract void logImpl(String message, String messageSource, int severity, File file);171172protected abstract void logImpl(String message, String messageSource, int severity, File file, Throwable rootThrowable);173174protected abstract void logImpl(String message, String messageSource, int severity, File file, int line, int charStart, int charEnd);175176}177178179