• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

Regarding Apache Logging API,

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
sudhakar_koundinya
Asked:
sudhakar_koundinya
  • 9
  • 6
  • 5
  • +1
1 Solution
 
girionisCommented:
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
 
expertmbCommented:
     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
 
sudhakar_koundinyaAuthor Commented:
HTTPClient is not using any property file there??
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
armoghanCommented:
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
 
sudhakar_koundinyaAuthor Commented:
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
 
armoghanCommented:
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
 
armoghanCommented:
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
 
girionisCommented:
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
 
sudhakar_koundinyaAuthor Commented:
0
 
sudhakar_koundinyaAuthor Commented:
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
 
sudhakar_koundinyaAuthor Commented:
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
 
sudhakar_koundinyaAuthor Commented:
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
 
armoghanCommented:
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
 
sudhakar_koundinyaAuthor Commented:
>>By default commons/logging is integrated with log4j

I am just looking at the log4J sources. I don't think it is integrated
0
 
girionisCommented:
> 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
 
armoghanCommented:
yes girionis probably that is the case :)

0
 
sudhakar_koundinyaAuthor Commented:
Yes I have Solved my Problem :)

And I would like to close this question.

Regards
Sudhakar

0
 
girionisCommented:
So what was it?
0
 
sudhakar_koundinyaAuthor Commented:
static Log log
static
    {
        LOG = LogFactory.getLog(org.apache.commons.httpclient.HttpClient.class);
    }

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

}
0
 
girionisCommented:
Nice, thanks for letting us know :)

Well better ask a mod to PAQ this and refund the points to you.
0
 
girionisCommented:
Fine by me.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 9
  • 6
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now