Solved

Regarding Apache Logging API,

Posted on 2004-08-31
23
281 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now