|
Home > Archive > WebSphere Portal Server > June 2005 > Portlet logging using Log4j
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Portlet logging using Log4j
|
|
| Lee Francis Wilhelmsen 2005-06-15, 7:49 am |
| Hi
Our portlets use Apache Log4j for Java logging. Each portlet ships with
it's own log4j.properties file (in the application classpath) to
configure the logging. Everything works fine, but we are missing a way
to dynamically change the logging settings at runtime for helping us to
locate errors in portlet code.
Is there an easy way to configure log4j logging settings dynamically,
but without explicitly programming it in the portlet code using the
Log4j API?
From what I understand log4j looks for a system property named
log4j.configuration before looking for the the log4j.properties file in
the application classpath. However, surly that also means that all
server applications will share the same log4j settings given by the
system property? That isn't exactly what we want, but looking over the
WAS admin console I can't see any way to set system properties for one
particular application.
Also, does the server need to be restarted to make the it re-read the
system property for changes to the new logging settings? If not then
when does it read any changes to the logging configuration file that the
system property points to?
So basically this is the scenario I'm looking for:
- have each application ship with its own log4j.properties file
for production logging
- if an error occurs and more logging is required then the
administrator creates a new temporary log4j.properties file and
the log4j.configuration system setting is set to point to this file
- the server notices this new system variable dynamically and
reads and configures the logging based on the new logging
configuration settings
- the error is reproduced in the application and logged for further
analysis using the new logging settings
- the system setting log4j.configuration is removed, the server notices
the variable has been removed and dynamically returns to use settings
from the applications log4j.properties file for production logging as
if nothing had ever happened
Possible? I'm not so sure the LogManager is that flexable.
Like to hear your input. What are you guys doing for logging?
Regards
Lee Francis
| |
| George Daswani 2005-06-15, 6:11 pm |
| We use Log4J also for our portlet development. But instead of sticking
log4j in the individual WAR files, we have one in the system wide class
path - along with a system wide configuration..
eq. we copied log4j-1.2.X.jar to $APPSERVER/lib/ext directory..
Then copied the log4j.properties to $APPSERVER/classes directory - we then
use a Custom Service that initializes log4j during Server Startup, and a
Log4J Portlet that allows the developers and admins to force a
log4j.properties configuration reload..
This IMHO makes it easier for our admins to set/reset logging configuration
(instead of having multiple log4j properties embedded in WAR files).
Let me know if you need some sample code (in regards to the custom service,
and the portlet)..
G
"Lee Francis Wilhelmsen" <leefw@start.no-n-o-s-p-a-m> wrote in message
news:d8p5sc$4hgu$1@news.boulder.ibm.com...
> Hi
>
> Our portlets use Apache Log4j for Java logging. Each portlet ships with
> it's own log4j.properties file (in the application classpath) to configure
> the logging. Everything works fine, but we are missing a way to
> dynamically change the logging settings at runtime for helping us to
> locate errors in portlet code.
>
> Is there an easy way to configure log4j logging settings dynamically, but
> without explicitly programming it in the portlet code using the Log4j API?
>
> From what I understand log4j looks for a system property named
> log4j.configuration before looking for the the log4j.properties file in
> the application classpath. However, surly that also means that all server
> applications will share the same log4j settings given by the system
> property? That isn't exactly what we want, but looking over the WAS admin
> console I can't see any way to set system properties for one particular
> application.
>
> Also, does the server need to be restarted to make the it re-read the
> system property for changes to the new logging settings? If not then when
> does it read any changes to the logging configuration file that the system
> property points to?
>
> So basically this is the scenario I'm looking for:
> - have each application ship with its own log4j.properties file
> for production logging
> - if an error occurs and more logging is required then the
> administrator creates a new temporary log4j.properties file and
> the log4j.configuration system setting is set to point to this file
> - the server notices this new system variable dynamically and
> reads and configures the logging based on the new logging
> configuration settings
> - the error is reproduced in the application and logged for further
> analysis using the new logging settings
> - the system setting log4j.configuration is removed, the server notices
> the variable has been removed and dynamically returns to use settings
> from the applications log4j.properties file for production logging as
> if nothing had ever happened
>
> Possible? I'm not so sure the LogManager is that flexable.
>
> Like to hear your input. What are you guys doing for logging?
>
> Regards
> Lee Francis
| |
| Lee Francis Wilhelmsen 2005-06-20, 7:53 am |
| George Daswani wrote:
> Let me know if you need some sample code (in regards to the custom service,
> and the portlet)..
Thanks for your reply. Yes, I would be interested in seeing sample code
for the service if possible...
Regards
Lee Francis
| |
| Brian J. Sayatovic 2005-06-20, 6:10 pm |
| It's really not that bad to programatically modify the basic Log4J
properties. I built a Lquick-n-dirty JSP page that shows all of the logging
categories, each with a drop box that has their current level allowing you
to char ge it to another level. Let me know if you need any details.
Regards,
Brian.
"Lee Francis Wilhelmsen" <leefw@start.no-n-o-s-p-a-m> wrote in message
news:d8p5sc$4hgu$1@news.boulder.ibm.com...
> Hi
>
> Our portlets use Apache Log4j for Java logging. Each portlet ships with
> it's own log4j.properties file (in the application classpath) to
> configure the logging. Everything works fine, but we are missing a way
> to dynamically change the logging settings at runtime for helping us to
> locate errors in portlet code.
>
> Is there an easy way to configure log4j logging settings dynamically,
> but without explicitly programming it in the portlet code using the
> Log4j API?
>
> From what I understand log4j looks for a system property named
> log4j.configuration before looking for the the log4j.properties file in
> the application classpath. However, surly that also means that all
> server applications will share the same log4j settings given by the
> system property? That isn't exactly what we want, but looking over the
> WAS admin console I can't see any way to set system properties for one
> particular application.
>
> Also, does the server need to be restarted to make the it re-read the
> system property for changes to the new logging settings? If not then
> when does it read any changes to the logging configuration file that the
> system property points to?
>
> So basically this is the scenario I'm looking for:
> - have each application ship with its own log4j.properties file
> for production logging
> - if an error occurs and more logging is required then the
> administrator creates a new temporary log4j.properties file and
> the log4j.configuration system setting is set to point to this file
> - the server notices this new system variable dynamically and
> reads and configures the logging based on the new logging
> configuration settings
> - the error is reproduced in the application and logged for further
> analysis using the new logging settings
> - the system setting log4j.configuration is removed, the server notices
> the variable has been removed and dynamically returns to use settings
> from the applications log4j.properties file for production logging as
> if nothing had ever happened
>
> Possible? I'm not so sure the LogManager is that flexable.
>
> Like to hear your input. What are you guys doing for logging?
>
> Regards
> Lee Francis
| |
| George Daswani 2005-06-20, 6:10 pm |
| public class Log4JWAS51Service implements CustomService,
NotificationListener {
private Log logger = LogFactory.getLog(getClass());
public Log4JWAS51Service() {
super();
}
/*
* (non-Javadoc)
*
* @see
com.ibm.websphere.runtime.CustomService#initialize(java.util.Properties)
*/
public void initialize(Properties properties) throws Exception {
URL configFile = getClass().getResource("/log4j.properties");
if (configFile != null) {
logger
.info("Log4JWAS51Service.initialize() configuring Log4J to use
configFile=["
+ configFile + "].");
LogManager.resetConfiguration();
PropertyConfigurator.configure(configFile);
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(NotificationConstants.TYPE_J2EE_STATE_RUNNING);
ObjectName target = new ObjectName("WebSphere:*,type=Server");
AdminServiceFactory
.getAdminService()
.addNotificationListenerExtended(target, this, filter, null);
logger
.info("Log4JWAS51Service.initialize(): Waiting for system startup.");
} else {
logger
.fatal("Log4JWAS51Service.initialize() failed to configure Log4J, could
not find log4j.properties in classpath.");
}
}
/*
* (non-Javadoc)
*
* @see com.ibm.websphere.runtime.CustomService#shutdown()
*/
public void shutdown() throws Exception {
logger
.info("Log4JWAS51Service.shutdown() resetting log4j configuration.");
LogManager.resetConfiguration();
}
/*
* (non-Javadoc)
*
* @see
javax.management. NotificationListener#handleNotification(
javax.management.Notification,
* java.lang.Object)
*/
public void handleNotification(Notification notification, Object argument)
{
// TODO Auto-generated method stub
logger
.info("Log4JWAS51Service.handleNotification(): System has started, done
with log handling.");
}
}
"Lee Francis Wilhelmsen" <leefw@start.no-n-o-s-p-a-m> wrote in message
news:d961j2$56kc$1@news.boulder.ibm.com...
> George Daswani wrote:
>
> Thanks for your reply. Yes, I would be interested in seeing sample code
> for the service if possible...
>
> Regards
> Lee Francis
|
|
|
|
|