?
Solved

Regarding Apache Logging API,

Posted on 2004-08-31
23
Medium Priority
?
293 Views
Last Modified: 2010-03-31
Hello All,


Have you ever worked on Apache Logging API??

I am facing aproblem in supressing the messages of API.

In my current project I am using apache's HttpClient API. By default it is using Apache logging API.

In order to supress those messages, I know this condition should be used. (if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)))

But I am not understanding how to write the related code in my API??

Do I need to set any properties file for this or any thing else. I just can't understand how to supress messages of Apache HTTP client

Your help needed

thanks
sudhakar

0
Comment
Question by:sudhakar_koundinya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 5
  • +1
23 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11940895
Check the log4j.properties file. That's the one that defines the level of the messages you want to receive (errors, warnings, info etc).
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11940985
     public static final       String INFO       = "INFO";
      public static final       String DEBUG       = "DEBUG";
      public static final       String WARN       = "WARN";
      public static final       String ERROR       = "ERROR";
      public static final       String FATAL       = "FATAL";
      
public static void log(String level, String msg)
      {
            /*calls method to initialize Logger Object*/
            if (level == null)
                  logger.debug(msg);
            else if (level.equalsIgnoreCase(DEBUG))
                  logger.debug(msg);
            else if (level.equalsIgnoreCase(INFO))
                  logger.info(msg);
            else if (level.equalsIgnoreCase(WARN))
                  logger.warn(msg);
            else if (level.equalsIgnoreCase(ERROR))
                  logger.error(msg);
            else if (level.equalsIgnoreCase(FATAL))
                  logger.fatal(msg);

      }

LoggerClass.log("INFO", "something happened");
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11940989
HTTPClient is not using any property file there??
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:armoghan
ID: 11941174
you need to create a file with the name
log4j.properties
and add such lines into it to set the properties

log4j.rootLogger=INFO, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n


0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11941205
Ok,
I understand that I need to create a property file. But how HtpClient is working (I mean it is able to give warn messages and related logs), although there is no property file??
0
 
LVL 18

Expert Comment

by:armoghan
ID: 11941217
You may not need to write create a class has been given by expertmb

just include the log4j.properties file in path

for details see the short manual

http://logging.apache.org/log4j/docs/documentation.html
0
 
LVL 18

Expert Comment

by:armoghan
ID: 11941257
You may not need to write create a class has been given by expertmb
if you use common logging of apache on top of log4j

http://jakarta.apache.org/commons/logging/ 
0
 
LVL 35

Expert Comment

by:girionis
ID: 11941292
If you have installed log4j then there should be a log4j.properites file. There is no need to hack log4j source code, that's why log4j.properties file is there for. Log4j reads the info level from there and appends occordingly.
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11941389
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11941419
Hello guys,

 Just need some clarificication

are you talking about
http://apache.swift-networks.com/jakarta/commons/logging/binaries/commons-logging-1.0.4.zip (HTTPClient uses this one)

or

http://logging.apache.org/log4j/docs/download.html

I think commons-logging API is entirely different from log4J API
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11941437
Javadoc for apache commons logging is this

http://jakarta.apache.org/commons/logging/api/index.html

Javadoc fo apache log4j is this
http://logging.apache.org/log4j/docs/api/index.html

0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11941560
Hello All,

As I said earlier log4J is not the subcomponent of HttpClient. And I think I have found the solution. I will let you know if that works for me.

Thanks
Sudhakar

0
 
LVL 18

Expert Comment

by:armoghan
ID: 11941627
http://jakarta.apache.org/commons/logging/ is a thin wrapper on different logging frameworks.
While log4j is a logging framework

By default commons/logging is integrated with log4j
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11941670
>>By default commons/logging is integrated with log4j

I am just looking at the log4J sources. I don't think it is integrated
0
 
LVL 35

Expert Comment

by:girionis
ID: 11941701
> I am just looking at the log4J sources. I don't think it is integrated

I think it is since we usually include both commons-logging and log4j jars in our classpath.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 11941784
yes girionis probably that is the case :)

0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11943848
Yes I have Solved my Problem :)

And I would like to close this question.

Regards
Sudhakar

0
 
LVL 35

Expert Comment

by:girionis
ID: 11943975
So what was it?
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 0 total points
ID: 11949082
static Log log
static
    {
        LOG = LogFactory.getLog(org.apache.commons.httpclient.HttpClient.class);
    }

public void init()
{
LOG.setLevel(LOG.LOG_LEVEL_OFF);

}
0
 
LVL 35

Expert Comment

by:girionis
ID: 11949581
Nice, thanks for letting us know :)

Well better ask a mod to PAQ this and refund the points to you.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11949973
Fine by me.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question