[207] | 1 | package de.ugoe.cs.eventbench.log4j;
|
---|
| 2 |
|
---|
| 3 | import org.apache.log4j.Logger;
|
---|
| 4 | import org.apache.log4j.PropertyConfigurator;
|
---|
| 5 |
|
---|
| 6 | import de.ugoe.cs.util.console.Console;
|
---|
| 7 | import de.ugoe.cs.util.console.listener.ICommandListener;
|
---|
| 8 | import de.ugoe.cs.util.console.listener.IErrorListener;
|
---|
| 9 | import de.ugoe.cs.util.console.listener.IExceptionListener;
|
---|
| 10 | import de.ugoe.cs.util.console.listener.ITraceListener;
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * <p>
|
---|
| 14 | * Implements logging based on the log4j API.
|
---|
| 15 | * </p>
|
---|
| 16 | *
|
---|
| 17 | * @author Steffen Herbold
|
---|
| 18 | * @version 1.0
|
---|
| 19 | */
|
---|
| 20 | public class Log4JLogger implements IErrorListener, ITraceListener,
|
---|
| 21 | IExceptionListener, ICommandListener {
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * <p>
|
---|
| 25 | * Reference to the logger.
|
---|
| 26 | * </p>
|
---|
| 27 | */
|
---|
| 28 | Logger logger;
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * <p>
|
---|
| 32 | * Constructor. Creates a new Log4JLogger and registers the implemented
|
---|
| 33 | * listener with the {@link Console}.
|
---|
| 34 | * </p>
|
---|
| 35 | */
|
---|
| 36 | public Log4JLogger() {
|
---|
| 37 | PropertyConfigurator.configure("misc/log4j.properties");
|
---|
| 38 | logger = Logger.getLogger("de.ugoe.cs.eventbench");
|
---|
| 39 | Console.getInstance().registerErrorListener(this);
|
---|
| 40 | Console.getInstance().registerTraceListener(this);
|
---|
| 41 | Console.getInstance().registerExceptionListener(this);
|
---|
| 42 | Console.getInstance().registerCommandListener(this);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | /*
|
---|
| 46 | * (non-Javadoc)
|
---|
| 47 | *
|
---|
| 48 | * @see
|
---|
| 49 | * de.ugoe.cs.util.console.listener.ICommandListener#commandNotification
|
---|
| 50 | * (java.lang.String)
|
---|
| 51 | */
|
---|
| 52 | @Override
|
---|
| 53 | public void commandNotification(String command) {
|
---|
| 54 | logger.info("Command executed: " + command);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /*
|
---|
| 58 | * (non-Javadoc)
|
---|
| 59 | *
|
---|
| 60 | * @see
|
---|
| 61 | * de.ugoe.cs.util.console.listener.IExceptionListener#printStacktrace(java
|
---|
| 62 | * .lang.Exception)
|
---|
| 63 | */
|
---|
| 64 | @Override
|
---|
[211] | 65 | public void logException(Exception e) {
|
---|
[207] | 66 | logger.error("", e);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /*
|
---|
| 70 | * (non-Javadoc)
|
---|
| 71 | *
|
---|
| 72 | * @see
|
---|
| 73 | * de.ugoe.cs.util.console.listener.ITraceListener#traceMsg(java.lang.String
|
---|
| 74 | * )
|
---|
| 75 | */
|
---|
| 76 | @Override
|
---|
| 77 | public void traceMsg(String traceMessage) {
|
---|
| 78 | logger.trace(traceMessage);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /*
|
---|
| 82 | * (non-Javadoc)
|
---|
| 83 | *
|
---|
| 84 | * @see
|
---|
| 85 | * de.ugoe.cs.util.console.listener.IErrorListener#errorMsg(java.lang.String
|
---|
| 86 | * )
|
---|
| 87 | */
|
---|
| 88 | @Override
|
---|
| 89 | public void errorMsg(String errMessage) {
|
---|
| 90 | logger.error(errMessage);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|