Link to home
Start Free TrialLog in
Avatar of sudhakar_koundinya
sudhakar_koundinya

asked on

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

Avatar of girionis
girionis
Flag of Greece image

Check the log4j.properties file. That's the one that defines the level of the messages you want to receive (errors, warnings, info etc).
Avatar of expertmb
expertmb

     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");
Avatar of sudhakar_koundinya

ASKER

HTTPClient is not using any property file there??
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


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??
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
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/ 
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.
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
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

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
>>By default commons/logging is integrated with log4j

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

Yes I have Solved my Problem :)

And I would like to close this question.

Regards
Sudhakar

So what was it?
ASKER CERTIFIED SOLUTION
Avatar of sudhakar_koundinya
sudhakar_koundinya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice, thanks for letting us know :)

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