Replaces log4j 1.x API with 2.8.2. As of now the logger does not use a configuration file which results in warnings all over and the default logging level is set to TRACE.

However it does compile and the application is runnable.

git-svn-id: https://svn.libreccm.org/ccm/trunk@4916 8810af33-2d31-482b-a856-94f89814c4df
master
baka 2017-08-22 17:58:03 +00:00
parent 6bb81cd9ab
commit 9f6a522020
12 changed files with 9 additions and 392 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -88,8 +88,8 @@ public class ErrorReport {
file.mkdir();
}
ErrorReportAppender appender = new ErrorReportAppender(directory);
s_log.addAppender(appender);
//ErrorReportAppender appender = new ErrorReportAppender(directory);
//s_log.addAppender(appender);
}
private Throwable[] m_throwables;

View File

@ -1,58 +0,0 @@
/*
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.logging;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.LoggingEvent;
public class ErrorReportAppender extends FileAppender {
private String m_directory;
public ErrorReportAppender(String directory) {
m_directory = directory;
setLayout(new Layout() {
public void activateOptions() {}
public boolean ignoresThrowable() { return true; }
public String format(LoggingEvent event) {
return ((ErrorReport)event.getMessage()).getReport();
}
});
setName("ErrorReportAppender");
}
public void append(LoggingEvent event) {
if (event.getMessage() instanceof ErrorReport) {
ErrorReport report = (ErrorReport)event.getMessage();
setFile(m_directory + "/" + report.getGuruMeditationCode() + ".txt");
setAppend(false);
setBufferedIO(false);
activateOptions();
super.append(event);
}
}
}

View File

@ -1,78 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.logging;
/**
* <p>
* Defines APIs for logging in addition to those supplied by log4j.
* Mainly, this class defines an API for logging securely.
* </p>
*
* @author Yon Feldman
* @version $Id: Log.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class Log {
// this variable will hold the secure state for this class on a per thread
// basis.
private static ThreadLocal s_secureState = new ThreadLocal() {
public Object initialValue() {
return Boolean.FALSE;
}
};
/**
* Checks whether we are currently logging securely.
*
* @return <code>true</code> if we are logging securely, <code>false</code> otherwise.
*/
public static boolean isSecure() {
return ((Boolean) s_secureState.get()).booleanValue();
}
// begin logging securely.
private static void startSecureLogging() {
s_secureState.set(Boolean.TRUE);
}
// reset the secure logging state to the value passed in.
private static void resetSecureLogging(Boolean inSecureState) {
s_secureState.set(inSecureState);
}
/**
* Any log messages run inside this method will be logged securely.
*
* @param r the class that implements the <code>Runnable</code> interface
*/
public static void secure (Runnable r) {
// store old value so that we can reset to the appropriate value when
// done.
boolean inSecureState = isSecure();
// start logging securely
startSecureLogging();
// run code
r.run();
// reset logging state
resetSecureLogging(new Boolean(inSecureState));
}
}

View File

@ -1,57 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.logging;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;
/**
* <p>
* Defines a log4j filter that will filter out any messages that
* are tagged as secure by the Log class.
* </p>
*
* @author Yon Feldman
* @version $Id: SecureLogFilter.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class SecureLogFilter extends Filter {
/**
* Decides whether to let this log message go through.
*
* @param event a LoggingEvent to decide about letting go through
*/
public int decide(LoggingEvent event) {
// in here we have to check whether secure logging is on or off.
if(Log.isSecure())
return Filter.DENY;
return Filter.NEUTRAL;
}
/**
* Filter that does not support any options.
*/
public String[] getOptionStrings() {
return new String[] {"", ""};
}
/**
* Filter that does not support any options.
*/
public void setOption(String key, String value) {}
}

View File

@ -1,110 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.logging.examples;
import com.arsdigita.logging.Log;
import com.arsdigita.logging.SecureLogFilter;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.RollingFileAppender;
/**
* <p>
* This is an example class that uses the secure logging api.
* </p>
*
* @version $Id: LogExample.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class LogExample {
// get the logger named the same as this class
static final Logger cat = Logger.getLogger(LogExample.class);
private static void configureNewAppender(String filename) {
// try to add an appender that sends log output to
// the file passed in as the first argument to this program
// but only output that is not marked as secure
try {
// create a rolling file appender with standard layout
RollingFileAppender rfa = new RollingFileAppender(
new PatternLayout(
PatternLayout.TTCC_CONVERSION_PATTERN
), filename
);
// add our secure log filter to this appender so that it
// won't get any of the secure log messages
rfa.addFilter(new SecureLogFilter()) ;
// add this appender to the root category.
BasicConfigurator.configure(rfa);
} catch (java.io.IOException e) {
// we should error out here really but who cares for now
}
}
public static void main(String[] argv) {
// lets just use the basic configuration
BasicConfigurator.configure();
int iterations = 3;
switch(argv.length) {
case 0:
break;
case 1:
configureNewAppender(argv[0]);
break;
case 2:
configureNewAppender(argv[0]);
iterations = Integer.parseInt(argv[1]);
break;
default:
String s = System.getProperty("line.separator");
System.out.println(
"Usage:" + s +
"java " + LogExample.class.getName() + s +
"java " + LogExample.class.getName() +
" <insecure-log-file>" + s +
"java " + LogExample.class.getName() +
" <insecure-log-file>" + " <number-of-log-messages>"
);
return;
}
cat.info("Entering " + LogExample.class.getName());
for(int i = 0; i < iterations; i++) {
if(Log.isSecure())
cat.debug("Logging securely");
else
cat.debug("Logging insecurely");
LogExampleThread t = new LogExampleThread();
t.start();
if(Log.isSecure())
cat.debug("Logging securely");
else
cat.debug("Logging insecurely");
}
cat.info("Exiting " + LogExample.class.getName());
}
}

View File

@ -1,66 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.logging.examples;
import com.arsdigita.logging.Log;
import org.apache.log4j.Logger;
/**
* <p>
* This is a helper class to the example class LogExampleThread
* </p>
*
* @version $Id: LogExampleThread.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class LogExampleThread extends Thread {
// get the category named the same as this class
private static final Logger cat = Logger.getLogger(LogExampleThread.class);
public void run() {
Log.secure(new Runnable() {
public void run() {
try {
sleep((new Double(Math.random() * 100.0)).intValue());
} catch (InterruptedException e) {
// do nothing
return;
}
// do everything that needs to be logged securely here
if(Log.isSecure())
cat.info(
"We are running securely in thread " +
Thread.currentThread().getName() +
". There are " +
Thread.currentThread().activeCount() +
" threads currently running."
);
else
cat.info(
"We are not running securely in thread " +
Thread.currentThread().getName() +
". There are " +
Thread.currentThread().activeCount() +
" threads currently running."
);
}
});
}
}

View File

@ -1,14 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>com.arsdigita.logging.examples</title>
</head>
<body bgcolor="white">
<p>Contains example code to demonstrate proper usage of
the ACS Logging system.</p>
</body>
</html>

View File

@ -36,7 +36,7 @@ import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import org.apache.log4j.ConsoleAppender;
//import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
@ -87,11 +87,11 @@ public class ApplyTemplates {
public static void main(String[] args) {
/* Setup logger */
ConsoleAppender log = new ConsoleAppender(
new PatternLayout(
"%d{ISO8601} [%5.5t] %-5p %c{2} - %m%n"));
log.setThreshold(Level.toLevel("warn"));
BasicConfigurator.configure(log);
//ConsoleAppender log = new ConsoleAppender(
// new PatternLayout(
// "%d{ISO8601} [%5.5t] %-5p %c{2} - %m%n"));
//log.setThreshold(Level.toLevel("warn"));
//BasicConfigurator.configure(log);
/* Process command line options and parameter */
@ -102,7 +102,7 @@ public class ApplyTemplates {
String input = args[1];
String output = args[2];
log.setThreshold(Level.toLevel((String)options.get(OPT_LOG)));
//log.setThreshold(Level.toLevel((String)options.get(OPT_LOG)));
s_log.debug("Build xml source " + new Date());
StreamSource xml = new StreamSource(input);