ArticleslgStudy

computer science

Java logging framework

Java logging framework is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Java logging framework rather than just read about it. In short: A Java logging framework is a computer data logging package for the Java platform. This article covers general purpose logging frameworks.

Key takeaways

  • Java logging framework belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Java logging framework to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Java logging framework from memory before moving on to harder problems.

Reference excerpt

A Java logging framework is a computer data logging package for the Java platform. This article covers general purpose logging frameworks. Logging refers to the recording of activity by an application and is a common issue for development teams. Logging frameworks ease and standardize the process of logging for the Java platform. In particular they provide flexibility by avoiding explicit output to the console (see Appender below). Where logs are written becomes independent of the code and can be customized at runtime. Unfortunately the JDK did not include logging in its original release so by the time the Java Logging API was added several other logging frameworks had become widely used – in particular Apache Commons Logging (also known as Java Commons Logging or JCL) and Log4j. This led to problems when integrating different third-party libraries (JARs) each using different logging frameworks. Pluggable logging frameworks (wrappers) were developed to solve this problem.

Functionality overview Logging is typically broken into three major pieces: the Logger, the Formatter and the Appender (or Handler).

The Logger is responsible for capturing the message to be logged along with certain metadata and passing it to the logging framework. After receiving the message, the framework calls the Formatter with the message which formats it for output. The framework then hands the formatted message to the appropriate Appender/Handler for disposition. This might include output to a console display, writing to disk, appending to a database, or generating an email. Simpler logging frameworks, like |Java Logging Framework by the Object Guy, combine the logger and the appender. This simplifies default operation, but it is less configurable, especially if the project is moved across environments.

Logger A Logger is an object that allows the application to log without regard to where the output is sent/stored. The application logs a message by passing an object or an object and an exception with an optional severity level to the logger object under a given name/identifier.

Name A logger has a name. The name is usually structured hierarchically, with periods (.) separating the levels. A common scheme is to use the name of the class or package that is doing the logging. Both Log4j and the Java logging API support defining handlers higher up the hierarchy. For example, the logger might be named "com.sun.some.UsefulClass". The handler can be defined for any of the following:

com com.sun com.sun.some com.sun.some.UsefulClass As long as there is a handler defined somewhere in this stack, logging may occur. For example a message logged to the com.sun.some.UsefulClass logger, may get written by the com.sun handler. Typically there is a global handler that receives and processes messages generated by any logger.

Severity level The message is logged at a certain level. Common level names are copied from Apache Commons Logging (although the Java Logging API defines different level names):

The logging framework maintains the current logging level for each logger. The logging level can be set more or less restrictive. For example, if the logging level is set to "WARNING", then all messages of that level or higher are logged: ERROR and FATAL. Severity levels can be assigned to both loggers and appenders. Both must be enabled for a given severity level for output to be generated. So a logger enabled for debug output will not generate output if the handler that gets the message is not also enabled for debug.

Filters Filters cause a log event to be ignored or logged. The most commonly used filter is the logging level documented in the previous section. Logging frameworks such as Log4j 2 and SLF4J also provide Markers, which when attached to a log event can also be used for filtering. Filters can also be used to accept or deny log events based on exceptions being thrown, data within the log message, data in a ThreadLocal that is exposed through the logging API, or a variety of other methods.

Formatters, Layouts or renderers A Formatter is an object that formats a given object. Mostly this consists of taking the binary object and converting it to a string representation. Each framework defines a default output format that can be overridden if desired.

Appenders or handlers Appenders listen for messages at or above a specified minimum severity level. The Appender takes the message it is passed and posts it appropriately. Message dispositions include:

display on the console write to a file or syslog append to a database table distribute via Java Messaging Services send via email write to a socket discard to the "bit-bucket" (/dev/null)

Feature comparison

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Java logging framework

Start with the simplest possible case. Write down what Java logging framework claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Java logging framework before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Java logging framework ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Java logging framework

In research
Java logging framework appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Java logging framework in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Java logging framework is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer logging, Java (software platform), so understanding it makes those chapters shorter.
In everyday life
Look for Java logging framework outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Java logging framework” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Java logging framework in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Java logging framework means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Java logging framework out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Java logging framework in simple terms?

A Java logging framework is a computer data logging package for the Java platform. This article covers general purpose logging frameworks.

Why does Java logging framework matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Java logging framework?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Java logging framework.

Tags

  • Computer logging
  • Java (software platform)

Keep exploring