From: Vincent Hennebert Date: Tue, 30 Jul 2013 20:10:35 +0000 (+0000) Subject: Removed obsolete CommandLineLogger. X-Git-Tag: fop-2_0~191 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cb742f91f7809f8a15157ceb2ed79f0473946c56;p=xmlgraphics-fop.git Removed obsolete CommandLineLogger. The Jdk14Logger is guaranteed to be there by default now that the minimal Java requirement is 1.5. Also, CommandLineLogger messes up the output when rendering to stdout. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1508599 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index 080fe7930..627b95a47 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -58,7 +58,6 @@ import org.apache.fop.render.pdf.PDFEncryptionOption; import org.apache.fop.render.print.PagesMode; import org.apache.fop.render.print.PrintRenderer; import org.apache.fop.render.xml.XMLRenderer; -import org.apache.fop.util.CommandLineLogger; /** * Options parses the commandline arguments @@ -146,15 +145,6 @@ public class CommandLineOptions { */ public CommandLineOptions() { LogFactory logFactory = LogFactory.getFactory(); - - // Enable the simple command line logging when no other logger is - // defined. - if (System.getProperty("org.apache.commons.logging.Log") == null) { - logFactory.setAttribute("org.apache.commons.logging.Log", - CommandLineLogger.class.getName()); - setLogLevel("info"); - } - log = LogFactory.getLog("FOP"); } @@ -292,7 +282,7 @@ public class CommandLineOptions { } else if (args[i].equals("-s")) { suppressLowLevelAreas = Boolean.TRUE; } else if (args[i].equals("-d")) { - setLogOption("debug", "debug"); + // nop. Left there for backwards compatibility } else if (args[i].equals("-r")) { strictValidation = false; } else if (args[i].equals("-conserve")) { @@ -304,7 +294,7 @@ public class CommandLineOptions { } else if (args[i].equals("-dpi")) { i = i + parseResolution(args, i); } else if (args[i].equals("-q") || args[i].equals("--quiet")) { - setLogOption("quiet", "error"); + // nop. Left there for backwards compatibility } else if (args[i].equals("-fo")) { i = i + parseFOInputOption(args, i); } else if (args[i].equals("-xsl")) { @@ -904,27 +894,6 @@ public class CommandLineOptions { } } - private void setLogOption(String option, String level) { - if (log instanceof CommandLineLogger - || System.getProperty("org.apache.commons.logging.Log") == null) { - setLogLevel(level); - } else if (log != null) { - log.warn("The option " + option + " can only be used"); - log.warn("with FOP's command line logger,"); - log.warn("which is the default on the command line."); - log.warn("Configure other loggers using Java system properties."); - } - } - - private void setLogLevel(String level) { - // Set the level for future loggers. - LogFactory.getFactory().setAttribute("level", level); - if (log instanceof CommandLineLogger) { - // Set the level for the logger created already. - ((CommandLineLogger) log).setLogLevel(level); - } - } - private void setInputFormat(int format) throws FOPException { if (inputmode == NOT_SET || inputmode == format) { inputmode = format; @@ -1208,9 +1177,7 @@ public class CommandLineOptions { + "[-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] \n" + " [OPTIONS] \n" + " -version print FOP version and exit\n" - + " -d debug mode \n" + " -x dump configuration settings \n" - + " -q quiet mode \n" + " -c cfg.xml use additional configuration file cfg.xml\n" + " -l lang the language to use for user information \n" + " -nocs disable complex script features\n" diff --git a/src/java/org/apache/fop/fonts/apps/AbstractFontReader.java b/src/java/org/apache/fop/fonts/apps/AbstractFontReader.java index 39f7e14a4..3da33ec3f 100644 --- a/src/java/org/apache/fop/fonts/apps/AbstractFontReader.java +++ b/src/java/org/apache/fop/fonts/apps/AbstractFontReader.java @@ -32,8 +32,6 @@ import javax.xml.transform.TransformerFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.util.CommandLineLogger; - /** * Abstract base class for the PFM and TTF Reader command-line applications. */ @@ -90,10 +88,6 @@ public abstract class AbstractFontReader { protected static void setLogLevel(String level) { // Set the evel for future loggers. LogFactory.getFactory().setAttribute("level", level); - if (log instanceof CommandLineLogger) { - // Set the level for the logger creates already. - ((CommandLineLogger) log).setLogLevel(level); - } } /** diff --git a/src/java/org/apache/fop/fonts/apps/PFMReader.java b/src/java/org/apache/fop/fonts/apps/PFMReader.java index e5e8ca524..8ee6ff9b6 100644 --- a/src/java/org/apache/fop/fonts/apps/PFMReader.java +++ b/src/java/org/apache/fop/fonts/apps/PFMReader.java @@ -33,7 +33,6 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.Version; import org.apache.fop.fonts.type1.PFMFile; -import org.apache.fop.util.CommandLineLogger; /** * A tool which reads PFM files from Adobe Type 1 fonts and creates @@ -92,14 +91,7 @@ public class PFMReader extends AbstractFontReader { Map options = new java.util.HashMap(); String[] arguments = parseArguments(options, args); - // Enable the simple command line logging when no other logger is - // defined. LogFactory logFactory = LogFactory.getFactory(); - if (System.getProperty("org.apache.commons.logging.Log") == null) { - logFactory.setAttribute("org.apache.commons.logging.Log", - CommandLineLogger.class.getName()); - } - determineLogLevel(options); PFMReader app = new PFMReader(); diff --git a/src/java/org/apache/fop/fonts/apps/TTFReader.java b/src/java/org/apache/fop/fonts/apps/TTFReader.java index 900417350..db858e285 100644 --- a/src/java/org/apache/fop/fonts/apps/TTFReader.java +++ b/src/java/org/apache/fop/fonts/apps/TTFReader.java @@ -39,7 +39,6 @@ import org.apache.fop.fonts.CMapSegment; import org.apache.fop.fonts.FontUtil; import org.apache.fop.fonts.truetype.FontFileReader; import org.apache.fop.fonts.truetype.TTFFile; -import org.apache.fop.util.CommandLineLogger; // CSOFF: InnerAssignmentCheck // CSOFF: LineLengthCheck @@ -123,14 +122,7 @@ public class TTFReader extends AbstractFontReader { Map options = new java.util.HashMap(); String[] arguments = parseArguments(options, args); - // Enable the simple command line logging when no other logger is - // defined. LogFactory logFactory = LogFactory.getFactory(); - if (System.getProperty("org.apache.commons.logging.Log") == null) { - logFactory.setAttribute("org.apache.commons.logging.Log", - CommandLineLogger.class.getName()); - } - determineLogLevel(options); TTFReader app = new TTFReader(); diff --git a/src/java/org/apache/fop/util/CommandLineLogger.java b/src/java/org/apache/fop/util/CommandLineLogger.java deleted file mode 100644 index a9e59158f..000000000 --- a/src/java/org/apache/fop/util/CommandLineLogger.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * This is a commons-logging logger for command line use. - */ -public class CommandLineLogger implements Log { - /** "Trace" level logging. */ - public static final int LOG_LEVEL_TRACE = 1; - /** "Debug" level logging. */ - public static final int LOG_LEVEL_DEBUG = 2; - /** "Info" level logging. */ - public static final int LOG_LEVEL_INFO = 3; - /** "Warn" level logging. */ - public static final int LOG_LEVEL_WARN = 4; - /** "Error" level logging. */ - public static final int LOG_LEVEL_ERROR = 5; - /** "Fatal" level logging. */ - public static final int LOG_LEVEL_FATAL = 6; - - private int logLevel; - private String logName; - - /** - * Construct the logger with a default log level taken from the LogFactory - * attribute "level". - * @param logName the logger name. - */ - public CommandLineLogger(String logName) { - this.logName = logName; - setLogLevel((String) LogFactory.getFactory().getAttribute("level")); - } - - /** - * Set a log level for the logger. - * @param level the log level - */ - public void setLogLevel(String level) { - if ("fatal".equals(level)) { - logLevel = LOG_LEVEL_FATAL; - } else if ("error".equals(level)) { - logLevel = LOG_LEVEL_ERROR; - } else if ("warn".equals(level)) { - logLevel = LOG_LEVEL_WARN; - } else if ("info".equals(level)) { - logLevel = LOG_LEVEL_INFO; - } else if ("debug".equals(level)) { - logLevel = LOG_LEVEL_DEBUG; - } else if ("trace".equals(level)) { - logLevel = LOG_LEVEL_TRACE; - } else { - logLevel = LOG_LEVEL_INFO; - } - } - - /** - * {@inheritDoc} - */ - public final boolean isTraceEnabled() { - return logLevel <= LOG_LEVEL_TRACE; - } - - /** - * {@inheritDoc} - */ - public final boolean isDebugEnabled() { - return logLevel <= LOG_LEVEL_DEBUG; - } - - /** - * {@inheritDoc} - */ - public final boolean isInfoEnabled() { - return logLevel <= LOG_LEVEL_INFO; - } - - /** - * {@inheritDoc} - */ - public final boolean isWarnEnabled() { - return logLevel <= LOG_LEVEL_WARN; - } - - /** - * {@inheritDoc} - */ - public final boolean isErrorEnabled() { - return logLevel <= LOG_LEVEL_ERROR; - } - - /** - * {@inheritDoc} - */ - public final boolean isFatalEnabled() { - return logLevel <= LOG_LEVEL_FATAL; - } - - /** - * {@inheritDoc} - */ - public final void trace(Object message) { - if (isTraceEnabled()) { - log(LOG_LEVEL_TRACE, message, null); - } - } - - /** - * {@inheritDoc} - */ - public final void trace(Object message, Throwable t) { - if (isTraceEnabled()) { - log(LOG_LEVEL_TRACE, message, t); - } - } - - /** - * {@inheritDoc} - */ - public final void debug(Object message) { - if (isDebugEnabled()) { - log(LOG_LEVEL_DEBUG, message, null); - } - } - - /** - * {@inheritDoc} - */ - public final void debug(Object message, Throwable t) { - if (isDebugEnabled()) { - log(LOG_LEVEL_DEBUG, message, t); - } - } - - /** - * {@inheritDoc} - */ - public final void info(Object message) { - if (isInfoEnabled()) { - log(LOG_LEVEL_INFO, message, null); - } - } - - /** - * {@inheritDoc} - */ - public final void info(Object message, Throwable t) { - if (isInfoEnabled()) { - log(LOG_LEVEL_INFO, message, t); - } - } - - /** - * {@inheritDoc} - */ - public final void warn(Object message) { - if (isWarnEnabled()) { - log(LOG_LEVEL_WARN, message, null); - } - } - - /** - * {@inheritDoc} - */ - public final void warn(Object message, Throwable t) { - if (isWarnEnabled()) { - log(LOG_LEVEL_WARN, message, t); - } - } - - /** - * {@inheritDoc} - */ - public final void error(Object message) { - if (isErrorEnabled()) { - log(LOG_LEVEL_ERROR, message, null); - } - } - - /** - * {@inheritDoc} - */ - public final void error(Object message, Throwable t) { - if (isErrorEnabled()) { - log(LOG_LEVEL_ERROR, message, t); - } - } - - /** - * {@inheritDoc} - */ - public final void fatal(Object message) { - if (isFatalEnabled()) { - log(LOG_LEVEL_FATAL, message, null); - } - } - - /** - * {@inheritDoc} - */ - public final void fatal(Object message, Throwable t) { - if (isFatalEnabled()) { - log(LOG_LEVEL_FATAL, message, t); - } - } - - /** - * Do the actual logging. - * This method assembles the message and prints it to - * and then calls write() to cause it to be written.

- * - * @param type One of the LOG_LEVEL_XXX constants defining the log level - * @param message The message itself (typically a String) - * @param t The exception whose stack trace should be logged - */ - protected void log(int type, Object message, Throwable t) { - StringBuffer buf = new StringBuffer(); - // Append the message - buf.append(String.valueOf(message)); - if (t != null) { - buf.append("\n"); - // Append a stack trace or just the stack trace message. - if (!isDebugEnabled()) { - buf.append(t.toString()); - buf.append("\n"); - } else { - java.io.StringWriter sw = new java.io.StringWriter(1024); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - t.printStackTrace(pw); - pw.close(); - buf.append(sw.toString()); - } - } - - // Print to the appropriate destination - if (type >= LOG_LEVEL_WARN) { - System.err.println(buf); - } else { - System.out.println(buf); - } - - } -}