Hi,
the current logging configuration of TCK works fine for implementations
using Log4J logging. In "log4j.properties" vendors may specify appenders
and assign these to loggers, e.g.:
# appenders
log4j.appender.vendor=org.apache.jdo.tck.util.TCKFileAppender
log4j.appender.vendor.File=vendor.txt
log4j.appender.vendor.layout=org.apache.log4j.PatternLayout
log4j.appender.vendor.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t)
%-5p [%c] - %m%n
# loggers
log4j.logger.vendor=INFO, vendor
This ensures that vendor specific logging files are generated as
"target/logs/<timestamp>/<database><identity
type><configuration>-vendor.txt".
Attached you find a patch for review that implements the same feature
for vendors using JDK1.4 logging. In "logging.properties" vendors may
specify handlers and loggers, e.g.:
# loggers
vendor.level = INFO
# default handlers
handlers = org.apache.jdo.tck.util.TCKFileHandler
# handlers
org.apache.jdo.tck.util.TCKFileHandler.fileName = vendor.txt
org.apache.jdo.tck.util.TCKFileHandler.level = FINEST
This ensures that vendor specific logging files appear in the same
directory with the same naming pattern as in the log4j case.
Regards,
Michael
--
-------------------------------------------------------------------
Michael Watzek [EMAIL PROTECTED] Engineering GmbH
mailto:[EMAIL PROTECTED] Buelowstr. 66
Tel.: ++49/30/235 520 36 10783 Berlin - Germany
Fax.: ++49/30/217 520 12 http://www.spree.de/
-------------------------------------------------------------------
Index: test/java/org/apache/jdo/tck/util/TCKFileHandler.java
===================================================================
--- test/java/org/apache/jdo/tck/util/TCKFileHandler.java (Revision 0)
+++ test/java/org/apache/jdo/tck/util/TCKFileHandler.java (Revision 0)
@@ -0,0 +1,341 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+package org.apache.jdo.tck.util;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.logging.ErrorManager;
+import java.util.logging.Filter;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+import java.util.logging.StreamHandler;
+
+/**
+ * A JDK1.4 logging Handler class which delegates to a file handler.
+ * Configuration: By default each TCKFileHandler is initialized using
+ * the following LogManager configuration properties:
+ * <ul>
+ * <li>java.util.logging.TCKFileHandler.level
+ * specifies the default level for the Handler (defaults to Level.ALL).</li>
+ * <li>java.util.logging.FileHandler.filter
+ * specifies the name of a Filter class to use (defaults to no Filter).</li>
+ * <li>java.util.logging.FileHandler.formatter
+ * specifies the name of a Formatter class to use
+ * (defaults to java.util.logging.SimpleFormatter).</li>
+ * <li>java.util.logging.FileHandler.encoding
+ * the name of the character set encoding to use
+ * (defaults to the default platform encoding).</li>
+ * <li>java.util.logging.FileHandler.fileName
+ * specifies a the output file name. See below for details.</li>
+ * <li>java.util.logging.FileHandler.append
+ * specifies whether the FileHandler should append onto any existing files
+ * (defaults to false).</li>
+ * </ul>
+ */
+public class TCKFileHandler extends Handler {
+
+ private static final String defaultName = "";
+ private static final boolean defaultAppend = false;
+ private static final Level defaultLevel = Level.ALL;
+ private static final Filter defaultFilter = null;
+ private static final Formatter defaultFormatter = new SimpleFormatter();
+ private static final String defaultEncoding = null;
+
+ private String fileName;
+ private boolean append;
+
+ private Level level;
+ private Filter filter;
+ private Formatter formatter;
+ private String encoding;
+
+ private FileHandlerDelegate delegate;
+
+ /**
+ * @see Handler#Handler()
+ * @throws IOException
+ * @throws SecurityException
+ */
+ public TCKFileHandler() throws IOException, SecurityException {
+ configure();
+
+ this.delegate = new FileHandlerDelegate();
+
+ OutputStream stream = new FileOutputStream(this.fileName, this.append);
+ this.delegate.setOutputStream(stream);
+
+ this.delegate.setLevel(this.level);
+ this.delegate.setFilter(this.filter);
+ this.delegate.setFormatter(this.formatter);
+ this.delegate.setEncoding(this.encoding);
+ }
+
+ /**
+ * @see Handler#publish(java.util.logging.LogRecord)
+ */
+ public synchronized void publish(LogRecord record) {
+ this.delegate.publish(record);
+ }
+
+ /**
+ * @see Handler#close()
+ */
+ public synchronized void close() throws SecurityException {
+ this.delegate.close();
+ }
+
+
+ /**
+ * @see Handler#flush()
+ */
+ public void flush() {
+ this.delegate.flush();
+ }
+
+ /**
+ * @see Handler#getEncoding()
+ */
+ public String getEncoding() {
+ return this.encoding;
+ }
+
+ /**
+ * @see Handler#getErrorManager()
+ */
+ public ErrorManager getErrorManager() {
+ return this.delegate.getErrorManager();
+ }
+
+ /**
+ * @see Handler#getFilter()
+ */
+ public Filter getFilter() {
+ return this.filter;
+ }
+
+ /**
+ * @see Handler#getFormatter()
+ */
+ public Formatter getFormatter() {
+ return this.formatter;
+ }
+
+ /**
+ * @see Handler#getLevel()
+ */
+ public Level getLevel() {
+ return this.level;
+ }
+
+ /**
+ * @see Handler#reportError(java.lang.String, java.lang.Exception, int)
+ */
+ protected void reportError(String msg, Exception ex, int code) {
+ this.delegate.reportError(msg, ex, code);
+ }
+
+ /**
+ * @see Handler#setErrorManager(java.util.logging.ErrorManager)
+ */
+ public void setErrorManager(ErrorManager em) {
+ this.delegate.setErrorManager(em);
+ }
+
+ /**
+ * @see StreamHandler#isLoggable(java.util.logging.LogRecord)
+ */
+ public boolean isLoggable(LogRecord record) {
+ return this.delegate.isLoggable(record);
+ }
+
+ /**
+ * Sets the file name fileName property.
+ * @param fileName The fileName to set
+ */
+ protected void setPattern(String fileName) {
+ this.fileName = BatchTestRunner.changeFileName(fileName);
+ }
+
+ /**
+ * Sets the append property.
+ * @param append The append to set.
+ */
+ protected void setAppend(boolean append) {
+ this.append = append;
+ }
+
+ /**
+ * Sets the level property.
+ * @param level The level to set.
+ */
+ public void setLevel(Level level) {
+ this.level = level;
+ if (this.delegate != null) {
+ this.delegate.setLevel(level);
+ }
+ }
+
+ /**
+ * Sets the filter property.
+ * @param filter The filter to set.
+ */
+ public void setFilter(Filter filter) {
+ this.filter = filter;
+ if (this.delegate != null) {
+ this.delegate.setFilter(filter);
+ }
+ }
+
+ /**
+ * Sets the formatter property.
+ * @param formatter The formatter to set.
+ */
+ public void setFormatter(Formatter formatter) {
+ this.formatter = formatter;
+ if (this.delegate != null) {
+ this.delegate.setFormatter(formatter);
+ }
+ }
+
+ /**
+ * Sets the encoding property.
+ * @param encoding The encoding to set.
+ * @throws UnsupportedEncodingException
+ * @throws SecurityException
+ */
+ public void setEncoding(String encoding)
+ throws SecurityException, UnsupportedEncodingException {
+ this.encoding = encoding;
+ if (this.delegate != null) {
+ this.delegate.setEncoding(encoding);
+ }
+ }
+
+ /**
+ * Sets the delegate.
+ * @param delegate The delegate to set.
+ */
+ protected void setDelegate(FileHandlerDelegate delegate) {
+ this.delegate = delegate;
+ }
+
+ private void configure() {
+ LogManager manager = LogManager.getLogManager();
+ String className = this.getClass().getName();
+
+ setPattern(getStringProperty(manager, className + ".fileName",
defaultName));
+ setAppend(getBooleanProperty(manager, className + ".append",
defaultAppend));
+
+ setLevel(getLevelProperty(manager, className + ".level",
defaultLevel));
+ setFilter(getFilterProperty(manager, className + ".filter",
defaultFilter));
+ setFormatter(getFormatterProperty(manager, className + ".formatter",
defaultFormatter));
+ try {
+ setEncoding(getStringProperty(manager, className + ".encoding",
defaultEncoding));
+ } catch (Exception e) {
+ try {
+ setEncoding(defaultEncoding);
+ } catch (Exception ex) {
+ }
+ }
+ }
+
+ private boolean getBooleanProperty(LogManager manager, String property,
+ boolean defaultValue) {
+ boolean result = defaultValue;
+ String value = manager.getProperty(property);
+ if ( value != null) {
+ try {
+ result = Boolean.valueOf(value.trim()).booleanValue();
+ } catch (Exception ex) {
+ }
+ }
+ return result;
+ }
+
+ private String getStringProperty(LogManager manager, String property,
+ String defaultValue) {
+ String result = defaultValue;
+ String value = manager.getProperty(property);
+ if ( value != null) {
+ result = value.trim();
+ }
+ return result;
+ }
+
+ private Level getLevelProperty(LogManager manager, String property,
+ Level defaultValue) {
+ Level result = defaultValue;
+ String value = manager.getProperty(property);
+ if (value != null) {
+ try {
+ result = Level.parse(value.trim());
+ } catch (Exception ex) {
+ }
+ }
+ return result;
+ }
+
+ private Filter getFilterProperty(LogManager manager, String property,
+ Filter defaultValue) {
+ return (Filter) newInstanceForProperty(manager, property,
defaultValue);
+ }
+
+ private Formatter getFormatterProperty(LogManager manager, String
property,
+ Formatter defaultValue) {
+ return (Formatter) newInstanceForProperty(manager, property,
defaultValue);
+ }
+
+ private Object newInstanceForProperty(LogManager manager, String property,
+ Object defaultValue) {
+ Object result = defaultValue;
+ String value = manager.getProperty(property);
+ if (value != null) {
+ try {
+ Class clazz =
+ ClassLoader.getSystemClassLoader().loadClass(value);
+ result = clazz.newInstance();
+ } catch (Exception ex) {
+ }
+ }
+ return result;
+ }
+
+ /**
+ * This class has been defined to make method
+ * [EMAIL PROTECTED] Handler#reportError(java.lang.String,
java.lang.Exception, int)}
+ * accessible in the outer class.
+ */
+ private static class FileHandlerDelegate extends StreamHandler {
+
+ protected void setOutputStream(OutputStream out) {
+ super.setOutputStream(out);
+ }
+
+ /**
+ * @see Handler#reportError(java.lang.String, java.lang.Exception, int)
+ */
+ protected void reportError(String msg, Exception ex, int code) {
+ super.reportError(msg, ex, code);
+ }
+ }
+}
Index: test/conf/logging.properties
===================================================================
--- test/conf/logging.properties (Revision 265680)
+++ test/conf/logging.properties (Arbeitskopie)
@@ -30,14 +30,32 @@
#
######################
-# JDO TCK test cases
+# Loggers
######################
+# This is the root logger
+.level = SEVERE
+
+# This is the TCK logger
#org.apache.jdo.tck.level = FINE
+# The loggers below are used by Spring
+org.springframework.level = WARNING
+org.apache.jdo.tck.pc.company.CompanyModelReader.level = WARNING
+
+# Specify loggers used by JDO vendors below, e.g.
+#org.vendor.level = INFO
+
######################
-# JDK 1.4 logging properties
+# Default handlers
######################
-handlers = java.util.logging.ConsoleHandler
-java.util.logging.ConsoleHandler.level = FINEST
+handlers = org.apache.jdo.tck.util.TCKFileHandler
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+org.apache.jdo.tck.util.TCKFileHandler.fileName = vendor.txt
+org.apache.jdo.tck.util.TCKFileHandler.level = FINEST