Posts Tagged ‘Logging’
How to Use jLo
1) Create the JloSample.java file:
import org.jzonic.jlo.Logger;
import org.jzonic.jlo.LogManager;
public final class JloSample {
public static void main(final String[] args) {
final Logger logger = LogManager.getLogger(JloSample.class.getName());
logger.info("Hello World!");
}
private JloSample() {
}
}2) Create the jlo.properties file:
processor=direct
3) Compile the JloSample.java file.
4) Launch the JloSample class.
How to Use SLF4J with log4j
1) Create the Slf4jSample.java file:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class Slf4jSample {
public static void main(final String[] args) {
final Logger logger = LoggerFactory.getLogger(Slf4jSample.class);
logger.info("Hello World!");
}
private Slf4jSample() {
}
}2) Create the log4j.properties file:
log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.logger.Slf4jSample=INFO, A1
3) Compile the Slf4jSample.java file.
4) Add the slf4j-log4j.jar file to the class path.
5) Launch the Slf4jSample class.
How to Use Log Bridge with log4j
1) Create the LogBridgeSample.java file:
import org.grlea.logBridge.LogBridge;
import org.grlea.logBridge.LogBridgeManager;
public final class LogBridgeSample {
public static void main(final String[] args) {
final LogBridge bridge = LogBridgeManager.createLogBridge(LogBridgeSample.class);
bridge.info("Hello World");
}
private LogBridgeSample() {
}
}2) Create the logBridge.properties file:
org.grlea.logBridge.LogBridgeFactory=org.grlea.logBridge.impl.Log4JLogBridgeFactory # default is org.grlea.logBridge.impl.NullLogBridgeFactory
3) Create the log4j.properties file:
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.logger.LogBridgeSample=INFO, A1
4) Compile the LogBridgeSample.java file.
5) Launch the LogBridgeSample class.
How to Use Simple Log
1) Create the SimpleLogSample.java file:
import org.grlea.log.SimpleLogger;
public final class SimpleLogSample {
public static void main(final String[] args) {
final SimpleLogger logger = new SimpleLogger(SimpleLogSample.class);
logger.info("Hello World");
}
private SimpleLogSample() {
}
}
2) Create an empty simplelog.properties file.
3) Compile the SimpleLogSample.java file.
4) Launch the SimpleLogSample class.
How to Use Jakarta Commons Logging with log4j
1) Create the CommonsSample.java file:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public final class CommonsSample {
public static void main(final String[] args) {
final LogFactory factory = LogFactory.getFactory();
final Log log = factory.getInstance(CommonsSample.class);
log.info("Hello World!");
}
private CommonsSample() {
}
}
2) Create the commons-logging.properties file:
org.apache.commons.logging.Log= org.apache.commons.logging.impl.Log4JLogger # default is org.apache.commons.logging.impl.SimpleLog
3) Create the log4j.properties file:
log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.logger.CommonsSample=INFO, A1
4) Compile the CommonsSample.java file.
5) Launch the CommonsSample class.
How to Use Chainsaw
1) Create the ChainsawSample.java file:
import org.apache.log4j.Logger;
public final class ChainsawSample {
public static void main(final String[] args) {
final Logger logger = Logger.getLogger(ChainsawSample.class);
logger.info("Hello World!");
}
private ChainsawSample() {
}
}
2) Create the log4j.properties file:
log4j.appender.A1=org.apache.log4j.net.SocketAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.RemoteHost=localhost # use the default port log4j.logger.ChainsawSample=INFO, A1
3) Compile the ChainsawSample.java file.
4) Launch Chainsaw.
5) Launch the ChainsawSample class.
How to Use log4j
1) Create the Log4jSample.java file:
import org.apache.log4j.Logger;
public final class Log4jSample {
public static void main(final String[] args) {
final Logger logger = Logger.getLogger(Log4jSample.class);
logger.info("Hello World!");
}
private Log4jSample() {
}
}2) Create the log4j.properties file:
log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.logger.Log4jSample=INFO, A1
3) Compile the Log4jSample.java file.
4) Launch the Log4jSample class.
How to Use Logfeeder
1) Create the LogfeederSample.java file:
import java.util.logging.Logger;
public final class LogfeederSample{
public static void main(final String[] args) {
final Logger logger = Logger.getLogger(LogfeederSample.class.getName());
logger.info("Hello World!");
}
private LogfeederSample() {
}
}2) Create the logging.properties file:
java.util.logging.SocketHandler.host=localhost java.util.logging.SocketHandler.port=4446 # no default LogfeederSample.handlers=java.util.logging.SocketHandler
3) Compile the LogfeederSample.java file.
4) Launch Logfeeder.
5) Launch the LogfeederSample class.
How to Use the JUL API
1) Create the LoggingSample.java file:
import java.util.logging.Logger;
public final class LoggingSample{
public static void main(final String[] args) {
final Logger logger = Logger.getLogger(LoggingSample.class.getName());
logger.info("Hello World!");
}
private LoggingSample() {
}
}2) Compile the LoggingSample.java file.
3) Launch the LoggingSample class.
Enterprise AOP
The project also provides and demonstrates effective use of a proposed common support library for AspectJ, which provides flexible support for exception handling, security, logging, tracing, transaction and persistent session management, and virtual mock objects for testing. This library will allow Java projects to implement significant new functionality with just a few lines of code. Further, it will substantially reduce the learning curve to productively apply AOP.