Path: blob/master/sourcetools/com.ibm.jpp.preprocessor/com/ibm/jpp/commandline/CommandlineLogger.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.commandline;2223import java.io.File;24import java.io.PrintStream;2526import com.ibm.jpp.om.Logger;2728/**29* Commandline implementation of the Preprocessor logger. This implementation simply30* printers the preprocessor errors to the screen in a organized fashion.31*/32public class CommandlineLogger extends Logger {3334/**35* Logs a preprocessor message.36*37* @param message the message to be logged38* @param messageSource the message source39* @param severity the message severity40*41* @see Logger#log(String, String, int)42*/43@Override44public void logImpl(String message, String messageSource, int severity) {45@SuppressWarnings("resource")46PrintStream out = createOutputStream(severity);4748out.print("[");49out.print(messageSource);50out.print("] ");51out.print(message);52out.println();53out.flush();54}5556/**57* Logs a throwable preprocessor message.58*59* @param message the message to be logged60* @param messageSource the message source61* @param severity the message severity62* @param rootThrowable the message throwable63*64* @see Logger#log(String, String, int, Throwable)65*/66@Override67public void logImpl(String message, String messageSource, int severity, Throwable rootThrowable) {68@SuppressWarnings("resource")69PrintStream out = createOutputStream(severity);7071out.print("[");72out.print(messageSource);73out.print("] ");74out.print(message);75out.println();76out.println("---------- START STACK TRACE ----------");77rootThrowable.printStackTrace(out);78out.println("----------- END STACK TRACE -----------");79out.flush();80}8182protected PrintStream createOutputStream(int severity) {83PrintStream out;84if (severity >= SEVERITY_ERROR) {85out = System.err;86out.print("ERROR ");87} else {88out = System.out;89}90return out;91}9293/**94* Logs a preprocessor message.95*96* @param message the message to be logged97* @param messageSource the message source98* @param severity the message severity99* @param file the file in which the message occurs100*101* @see Logger#log(String, String, int, File)102*/103@Override104public void logImpl(String message, String messageSource, int severity, File file) {105@SuppressWarnings("resource")106PrintStream out = createOutputStream(severity);107108out.print("[");109out.print(messageSource);110out.print("] ");111out.print(message);112out.println();113out.print(" file: ");114out.print(file.getAbsolutePath());115out.println();116out.flush();117}118119/**120* Logs a preprocessor message.121*122* @param message the message to be logged123* @param messageSource the message source124* @param severity the message severity125* @param file the file in which the message occurs126* @param line the line in which the message occurs127* @param charStart the character in which the message starts128* @param charEnd the character in which the message ends129*130* @see Logger#log(String, String, int, File, int, int, int)131*/132@Override133public void logImpl(String message, String messageSource, int severity, File file, int line, int charStart, int charEnd) {134@SuppressWarnings("resource")135PrintStream out = createOutputStream(severity);136137out.print("[");138out.print(messageSource);139out.print("] ");140out.print(message);141out.println();142143out.print(" file: ");144out.print(file.getAbsolutePath());145out.println();146147out.print(" line: ");148out.print(line);149out.print(" (char ");150out.print(charStart);151out.print(" to ");152out.print(charEnd);153out.print(")");154out.println();155156out.flush();157}158159/**160* Logs a throwable preprocessor message.161*162* @param message the message to be logged163* @param messageSource the message source164* @param severity the message severity165* @param file the file in which the message occurs166* @param rootThrowable the message throwable167*168* @see Logger#logImpl(String, String, int, File, Throwable)169*/170@Override171protected void logImpl(String message, String messageSource, int severity, File file, Throwable rootThrowable) {172@SuppressWarnings("resource")173PrintStream out = createOutputStream(severity);174175out.print("[");176out.print(messageSource);177out.print("] ");178out.print(message);179out.println();180out.print(" file: ");181out.print(file.getAbsolutePath());182out.println();183out.println("---------- START STACK TRACE ----------");184rootThrowable.printStackTrace(out);185out.println("----------- END STACK TRACE -----------");186out.flush();187}188189}190191192