Alex Rivera | Logout

What is "logger" in Java?

Asked 2010-03-09T17:21:43.683
10

I have a class in which I see the following things:

this.logger.severe("");
this.logger.warning("");
this.logger.info("");

I do not understand several things:

  1. How can we use a method that was not defined earlier? I mean, there are no "logger" methods defined in the class. I thought that these methods could be defined because the considered class is an extension of another class in which the "logger" is defined. But in the definition of the class there no "extends" statement (only "implements").

  2. I can understand things like that: "objectName.methodName". But what is that "objectName.something1.something2"? "something1.something2" is name of a method? Can method names contain dots?

  3. What exactly these "logger.*" do? I think they save information about the execution of the code. They kind of write report about what happened during the execution. But where I can find this information?

ADDED:

In the beginning of the file I have: import java.util.logging.Logger;
And then in the class I have: private Logger logger = Logger.getLogger("a.b.c.d");
So, logger is an object of the class Logger (but I do not understand why they could not instantiate the class in a usual way using "new Logger()). I also do not understand what exactly logger.severe("") do.

Edit
Report

1 Answer

3
  1. The logger usually refers to the usage of a class in log4j.
  2. The logger is a member object whose function e.g. severe is called.
  3. The logger usually logs into a file (this can be configured through log4j.xml or some other config file or during the program start).

Edit: Changed the log4j link.

answered 2010-03-09T17:31:52.630

Your Answer