Developer(s) | Apache Software Foundation |
---|---|
Stable release | 1.3.4 / August 16, 2024 |
Repository | github |
Written in | Java |
Operating system | Cross-platform |
Type | Logging Tool |
License | Apache License 2.0 |
Website | commons |
Apache Commons Logging (previously known as Jakarta Commons Logging or JCL) is a Java-based logging utility and a programming model for logging and for other toolkits. It provides APIs, log implementations, and wrapper implementations over some other tools. [1] [2] [3]
The following table defines the log levels and messages in Apache Commons Logging, in decreasing order of severity. The left column lists the log level designation in and the right column provides a brief description of each log level.
Level | Description |
---|---|
fatal | Severe errors that cause premature termination. Expect these to be immediately visible on a status console. |
error | Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. |
warn | Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. |
info | Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. |
debug | Detailed information on the flow through the system. Expect these to be written to logs only. |
trace | Most detailed information. Expect these to be written to logs only. |
Two basic abstractions, Log and LogFactory, are used in Apache Commons Logging. [3]
Sample code may look like as follows:
packagecom.cascadetg.ch09;importorg.apache.commons.logging.Log;importorg.apache.commons.logging.LogFactory;importorg.apache.commons.logging.impl.Jdk14Logger;publicclassLogGenerator{// Note that you pass in an instance of this class to the// log generator. This allows you to find the messages// generated by this class.privatestaticLoglog=LogFactory.getLog(LogGenerator.class);publicstaticvoidconfigJDKLogger(){try{((Jdk14Logger)log).getLogger().setLevel(java.util.logging.Level.ALL);((Jdk14Logger)log).getLogger().addHandler((java.util.logging.FileHandler)Class.forName("java.util.logging.FileHandler").newInstance());System.out.println("Added JDK 1.4 file handler");}catch(Exceptione){System.out.println("Unable to load JDK 1.4 logging.");e.printStackTrace();}}publicstaticvoidmain(String[]args){configJDKLogger();System.setErr(System.out);System.out.println();System.out.println("Test fatal log");try{Stringfoo=null;intx=0/(newInteger(foo)).intValue();}catch(Exceptione){log.fatal(e.getMessage(),e);}System.out.println();System.out.println("Test error log");try{Objectfoo=null;foo.toString();}catch(Exceptione){log.error(e.getMessage(),e);}System.out.println();System.out.println("Test warn log");try{Class.forName("com.cascadetg.NonexistantClass");}catch(Exceptione){log.warn("Can't find a non-existent class!");}System.out.println();System.out.println("Test info log");log.info("Starting app!");log.info("Quitting app!");System.out.println();System.out.println("Test debug log");if(1>2){log.debug("1 > 2 evaluated true");if(10%2==0)log.debug("10 % 2 is 0");elselog.debug("10 % 2 is not 0");}else{log.debug("1 > 2 evaluated false");}System.out.println();System.out.println("Test trace log");log.trace("Calling trace method.");log.trace("Calling trace method.");log.trace("Calling trace method.");log.trace("Calling trace method.");log.trace("Calling trace method.");System.out.println();System.out.println("Log test complete.");}}
Java Platform, Standard Edition is a computing platform for development and deployment of portable code for desktop and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition (J2SE).
The Java Remote Method Invocation is a Java API that performs remote method invocation, the object-oriented equivalent of remote procedure calls (RPC), with support for direct transfer of serialized Java classes and distributed garbage-collection.
The memento pattern is a software design pattern that exposes the private internal state of an object. One example of how this can be used is to restore an object to its previous state, another is versioning, another is custom serialization.
In software engineering, the mediator pattern defines an object that encapsulates how a set of objects interact. This pattern is considered to be a behavioral pattern due to the way it can alter the program's running behavior.
In software design and engineering, the observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
In computing, type introspection is the ability of a program to examine the type or properties of an object at runtime. Some programming languages possess this capability.
This article compares two programming languages: C# with Java. While the focus of this article is mainly the languages and their features, such a comparison will necessarily also consider some features of platforms and libraries. For a more detailed comparison of the platforms, see Comparison of the Java and .NET platforms.
The syntax of Java is the set of rules defining how a Java program is written and interpreted.
In software engineering, dependency injection is a programming technique in which an object or function receives other objects or functions that it requires, as opposed to creating them internally. Dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs. The pattern ensures that an object or function that wants to use a given service should not have to know how to construct those services. Instead, the receiving "client" is provided with its dependencies by external code, which it is not aware of. Dependency injection makes implicit dependencies explicit and helps solve the following problems:
TestNG is a testing framework for the Java programming language created by Cedric_Beust and inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionalities.
Scala is a strong statically typed high-level general-purpose programming language that supports both object-oriented programming and functional programming. Designed to be concise, many of Scala's design decisions are intended to address criticisms of Java.
Apache Log4j is a Java-based logging utility originally written by Ceki Gülcü. It is part of the Apache Logging Services, a project of the Apache Software Foundation. Log4j is one of several Java logging frameworks.
Exception handling syntax is the set of keywords and/or structures provided by a computer programming language to allow exception handling, which separates the handling of errors that arise during a program's operation from its ordinary processes. Syntax for exception handling varies between programming languages, partly to cover semantic differences but largely to fit into each language's overall syntactic structure. Some languages do not call the relevant concept "exception handling"; others may not have direct facilities for it, but can still provide means to implement it.
In the Java computer programming language, an annotation is a form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and Java packages may be annotated. Like Javadoc tags, Java annotations can be read from source files. Unlike Javadoc tags, Java annotations can also be embedded in and read from Java class files generated by the Java compiler. This allows annotations to be retained by the Java virtual machine at run-time and read via reflection. It is possible to create meta-annotations out of the existing ones in Java.
A Java logging framework is a computer data logging package for the Java platform. This article covers general purpose logging frameworks.
Jakarta Mail is a Jakarta EE API used to send and receive email via SMTP, POP3 and IMAP. Jakarta Mail is built into the Jakarta EE platform, but also provides an optional package for use in Java SE.
The Java programming language and the Java virtual machine (JVM) is designed to support concurrent programming. All execution takes place in the context of threads. Objects and resources can be accessed by many separate threads. Each thread has its own path of execution, but can potentially access any object in the program. The programmer must ensure read and write access to objects is properly coordinated between threads. Thread synchronization ensures that objects are modified by only one thread at a time and prevents threads from accessing partially updated objects during modification by another thread. The Java language has built-in constructs to support this coordination.
Generics are a facility of generic programming that were added to the Java programming language in 2004 within version J2SE 5.0. They were designed to extend Java's type system to allow "a type or method to operate on objects of various types while providing compile-time type safety". The aspect compile-time type safety required that parametrically polymorphic functions are not implemented in the Java virtual machine, since type safety is impossible in this case.
Simple Logging Facade for Java (SLF4J) provides a Java logging API by means of a simple facade pattern. The underlying logging backend is determined at runtime by adding the desired binding to the classpath and may be the standard Sun Java logging package java.util.logging, Log4j, Reload4j, Logback or tinylog.
Java Database Connectivity (JDBC) is an application programming interface (API) for the Java programming language which defines how a client may access a database. It is a Java-based data access technology used for Java database connectivity. It is part of the Java Standard Edition platform, from Oracle Corporation. It provides methods to query and update data in a database, and is oriented toward relational databases. A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source in the Java virtual machine (JVM) host environment.