Skip to Content
Log4J
book

Log4J

by J. Steven Perry
October 2009
Intermediate to advanced
74 pages
1h 58m
English
O'Reilly Media, Inc.
Content preview from Log4J

Configuring and Using Log4j

Most problems I’ve ever had when using log4j are related to bad configuration, usually stemming from a basic lack of understanding of how the various components of log4j work together. The core concepts of log4j are not well understood by the average user, or there wouldn’t be as many configuration problems as there are. In this section, we will take a look at the core concepts of the log4j architecture, along with an example for each, taken from the Example Application used with the Short Cut.

Each concept will be presented with an example so the reader can see how it works right out of the gate. Simple usage patterns are presented here for Appender usage and where to place the configuration file and how to name it.

Log4J Concepts

Let’s spend a minute looking at how the most basic components of log4j fit together. Figure 3 illustrates this.

Basic log4j components

Figure 3. Basic log4j components

Below is a short description of each component in Figure 3. We will look at each of these in more detail in later sections.

logger

This is a named entity—where you control the name—with which you interact directly from your Java code to do logging.

Appender

This represents a destination for logging output such as a file, the console, or even a database. Log4j comes packaged with a number of appenders that represent the most common log destinations you will need, but extensible so that if we have ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Pro Apache Log4j, Second Edition

Pro Apache Log4j, Second Edition

Samudra Gupta
Tomcat: The Definitive Guide

Tomcat: The Definitive Guide

Jason Brittain, Ian F. Darwin
Introduction to JVM Languages

Introduction to JVM Languages

Ramasubramanian Sankar, Vincent van der Leun

Publisher Resources

ISBN: 9781449379735Errata