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
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.
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
Check the log4j.properties file. That's the one that defines the level of the messages you want to receive (errors, warnings, info etc).
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(DE BUG))
logger.debug(msg);
else if (level.equalsIgnoreCase(IN FO))
logger.info(msg);
else if (level.equalsIgnoreCase(WA RN))
logger.warn(msg);
else if (level.equalsIgnoreCase(ER ROR))
logger.error(msg);
else if (level.equalsIgnoreCase(FA TAL))
logger.fatal(msg);
}
LoggerClass.log("INFO", "something happened");
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(DE
logger.debug(msg);
else if (level.equalsIgnoreCase(IN
logger.info(msg);
else if (level.equalsIgnoreCase(WA
logger.warn(msg);
else if (level.equalsIgnoreCase(ER
logger.error(msg);
else if (level.equalsIgnoreCase(FA
logger.fatal(msg);
}
LoggerClass.log("INFO", "something happened");
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.apac he.log4j.C onsoleAppe nder
log4j.appender.A1.layout=o rg.apache. log4j.Patt ernLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.C onversionP attern=%d [%t] %-5p %c - %m%n
log4j.properties
and add such lines into it to set the properties
log4j.rootLogger=INFO, A1
log4j.appender.A1=org.apac
log4j.appender.A1.layout=o
# Print the date in ISO 8601 format
log4j.appender.A1.layout.C
ASKER
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??
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
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 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.
ASKER
Just need some clarificication
are you taking abt t
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
are you taking abt t
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
ASKER
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
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
ASKER
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
http://jakarta.apache.org/commons/logging/api/index.html
Javadoc fo apache log4j is this
http://logging.apache.org/log4j/docs/api/index.html
ASKER
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
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
While log4j is a logging framework
By default commons/logging is integrated with log4j
ASKER
>>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 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.
I think it is since we usually include both commons-logging and log4j jars in our classpath.
yes girionis probably that is the case :)
ASKER
Yes I have Solved my Problem :)
And I would like to close this question.
Regards
Sudhakar
And I would like to close this question.
Regards
Sudhakar
So what was it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nice, thanks for letting us know :)
Well better ask a mod to PAQ this and refund the points to you.
Well better ask a mod to PAQ this and refund the points to you.
Fine by me.