Re: concurrency issues with one log file for multiple

2009-06-21 Thread Yair Ogen
log4j  is thread safe and should handle the concurrency efficiently.
I suggest you place tour OrderId in the log message using MDC.

On Sat, Jun 20, 2009 at 12:12 PM, benedikt herudek 
benedikt.heru...@gmail.com wrote:

 Hi,

 we are intending to use log4J in a call center: we have around 100
 simultaneous sessions working on one tool to create orders. W set up one
 logger per session (identified by basically the order id). All these
 loggers
 will write to one log file produced by log4J.

 Since we didnt use log4J before we want to be sure we are not creating
 concurrency issues and performance bottlenecks with having 100 session
 writing to one file. E.g. worst case scenario: 1st session loggs the file
 throughout its complete session and only releases it at the end, then in
 the
 meanwhile all other sessions queue up and wait. Rather, we suspect, log4J
 is
 automatically able to handle such a multiple sessions writing to one file
 situation and we dont have to bother with the details of that mechanism.

 Does anyone have experience, information, weblinks to documentation, tips
 or
 comments as to that problem ... ? ...:-)

 thx a lot !!!

 gruesse / regards / groetjes / adios

 Benedikt Herudek



Re: concurrency issues with one log file for multiple

2009-06-21 Thread benedikt herudek
I am using one logger per session and use the name of the logger to place in
the log file, no nested diagnostic context.

threadsafe in this context means: no blocking of whole file for one session,
no building of queues I assume ... ? ... :-)

regards

Benedikt


On Sun, Jun 21, 2009 at 8:36 AM, Yair Ogen yairo...@gmail.com wrote:

 log4j  is thread safe and should handle the concurrency efficiently.
 I suggest you place tour OrderId in the log message using MDC.

 On Sat, Jun 20, 2009 at 12:12 PM, benedikt herudek 
 benedikt.heru...@gmail.com wrote:

  Hi,
 
  we are intending to use log4J in a call center: we have around 100
  simultaneous sessions working on one tool to create orders. W set up one
  logger per session (identified by basically the order id). All these
  loggers
  will write to one log file produced by log4J.
 
  Since we didnt use log4J before we want to be sure we are not creating
  concurrency issues and performance bottlenecks with having 100 session
  writing to one file. E.g. worst case scenario: 1st session loggs the file
  throughout its complete session and only releases it at the end, then in
  the
  meanwhile all other sessions queue up and wait. Rather, we suspect, log4J
  is
  automatically able to handle such a multiple sessions writing to one file
  situation and we dont have to bother with the details of that mechanism.
 
  Does anyone have experience, information, weblinks to documentation, tips
  or
  comments as to that problem ... ? ...:-)
 
  thx a lot !!!
 
  gruesse / regards / groetjes / adios
 
  Benedikt Herudek
 



Re: concurrency issues with one log file for multiple

2009-06-21 Thread Yair Ogen
AFAIK.

On Sun, Jun 21, 2009 at 10:31 AM, benedikt herudek 
benedikt.heru...@gmail.com wrote:

 I am using one logger per session and use the name of the logger to place
 in
 the log file, no nested diagnostic context.

 threadsafe in this context means: no blocking of whole file for one
 session,
 no building of queues I assume ... ? ... :-)

 regards

 Benedikt


 On Sun, Jun 21, 2009 at 8:36 AM, Yair Ogen yairo...@gmail.com wrote:

  log4j  is thread safe and should handle the concurrency efficiently.
  I suggest you place tour OrderId in the log message using MDC.
 
  On Sat, Jun 20, 2009 at 12:12 PM, benedikt herudek 
  benedikt.heru...@gmail.com wrote:
 
   Hi,
  
   we are intending to use log4J in a call center: we have around 100
   simultaneous sessions working on one tool to create orders. W set up
 one
   logger per session (identified by basically the order id). All these
   loggers
   will write to one log file produced by log4J.
  
   Since we didnt use log4J before we want to be sure we are not creating
   concurrency issues and performance bottlenecks with having 100 session
   writing to one file. E.g. worst case scenario: 1st session loggs the
 file
   throughout its complete session and only releases it at the end, then
 in
   the
   meanwhile all other sessions queue up and wait. Rather, we suspect,
 log4J
   is
   automatically able to handle such a multiple sessions writing to one
 file
   situation and we dont have to bother with the details of that
 mechanism.
  
   Does anyone have experience, information, weblinks to documentation,
 tips
   or
   comments as to that problem ... ? ...:-)
  
   thx a lot !!!
  
   gruesse / regards / groetjes / adios
  
   Benedikt Herudek
  
 



Changing log4j configuration runtime ...

2009-06-21 Thread Preetam Palwe
Hello all,

 

I have successfully configured log4j in my standalone java application
using PropertyConfigurator.configure()

Here is the configuration file 

 

log4j.rootLogger=DBUG, LogFile

 

log4j.logger.com.server.core=INFO

log4j.logger. com.server.core.SecurityManager =DEBUG

log4j.logger. com.server.core.SecurityPatternsCreator =DEBUG

 

 
log4j.appender.LogFile=org.apache.log4j.RollingFileAppender

log4j.appender.LogFile.File=c:/server.log

log4j.appender.LogFile.MaxFileSize=5MB

log4j.appender.LogFile.MaxBackupIndex=10

 
log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout

log4j.appender.LogFile.layout.ConversionPattern=%d{
MM dd HH:mm:ss:SSS}# [%-5p]# [%t]# %c# %C{1}.%M# %m%n

 

In case of my application I have a security related library
(securitylib.jar) in which there we do some is a critical security
related processing. And I want to set logging level of INFO to all the
classes/loggers from this jar.

The log4j configuration is done before loading securitylib.jar using
above configuration file.

When securitylib.jar is loaded I tried to re-configure log4j using
following code.

(what I have done here is removed all the explicit loggers set in
configuration file, updated the configuration properties and configured
logger again)

 

But when I test the system I am still able to see the DEBUG logs for
classes/loggers com.server.core.SecurityManager and
com.server.core.SecurityPatternsCreator (which I had marked as DEBUG in
config files)

 

My questions are ...

1.   Why after reconfiguring the loggers the new configuration is
not getting reflected ?

2.   Is there any way to get the current log4j configuration and
change it at runtime ?

 

Thanks in advance for your help!

~PP

 

private void reinitLog4j()

{

try

{

String log4jFile = System.getProperty(log4j.file);

Properties properties = new Properties();

properties.load(new FileInputStream(log4jFile));

updateLoggingConfiguration(properties);

PropertyConfigurator.configure(properties);

}

catch (IOException ioEx)

{

throw new RuntimeException(failed to reconfigure
logger 

+ ioEx.getMessage(), ioEx);

}

logger = Logger.getLogger(this.getClass());

logger.info(Log4j RE initialised to use INFO logs
everywhere !);

logger.debug(THIS SHOULD NEVER COME IN LOGS);

}

 

private void updateLoggingConfiguration(Properties properties)

{

for (Iterator iterator =
properties.entrySet().iterator(); iterator

.hasNext();)

{

Entry entry = (Entry) iterator.next();

String key = (String) entry.getKey();

if (key.equalsIgnoreCase(log4j.rootLogger))

{

 
entry.setValue(getRootLoggerConfiguration((String) entry

.getValue()));

}

else if (key.startsWith(log4j.logger))

{

iterator.remove();

}

}

}

 

private String getRootLoggerConfiguration(String currentConfig)

{

String[] tokens = IOUtil.tokenizeString(currentConfig,
,);

StringBuilder builder = new StringBuilder();

for (int i = 0; i  tokens.length; i++)

{

if (i == 0)

{

builder.append(INFO);

continue;

}

builder.append(,  + tokens[i]);

}

return builder.toString();

}

 

 

 



Re: Changing log4j configuration runtime ...

2009-06-21 Thread Yair Ogen
Why not use a regular property file?

Then when you to update the file you can load the changes automatically
using the PropertyConfigurator.configureAndWatch mechanism.


On Sun, Jun 21, 2009 at 11:41 AM, Preetam Palwe preet...@aftek.com wrote:

 Hello all,



 I have successfully configured log4j in my standalone java application
 using PropertyConfigurator.configure()

 Here is the configuration file



 log4j.rootLogger=DBUG, LogFile



 log4j.logger.com.server.core=INFO

 log4j.logger. com.server.core.SecurityManager =DEBUG

 log4j.logger. com.server.core.SecurityPatternsCreator =DEBUG




 log4j.appender.LogFile=org.apache.log4j.RollingFileAppender

log4j.appender.LogFile.File=c:/server.log

log4j.appender.LogFile.MaxFileSize=5MB

log4j.appender.LogFile.MaxBackupIndex=10


 log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout

log4j.appender.LogFile.layout.ConversionPattern=%d{
 MM dd HH:mm:ss:SSS}# [%-5p]# [%t]# %c# %C{1}.%M# %m%n



 In case of my application I have a security related library
 (securitylib.jar) in which there we do some is a critical security
 related processing. And I want to set logging level of INFO to all the
 classes/loggers from this jar.

 The log4j configuration is done before loading securitylib.jar using
 above configuration file.

 When securitylib.jar is loaded I tried to re-configure log4j using
 following code.

 (what I have done here is removed all the explicit loggers set in
 configuration file, updated the configuration properties and configured
 logger again)



 But when I test the system I am still able to see the DEBUG logs for
 classes/loggers com.server.core.SecurityManager and
 com.server.core.SecurityPatternsCreator (which I had marked as DEBUG in
 config files)



 My questions are ...

 1.   Why after reconfiguring the loggers the new configuration is
 not getting reflected ?

 2.   Is there any way to get the current log4j configuration and
 change it at runtime ?



 Thanks in advance for your help!

 ~PP



 private void reinitLog4j()

{

try

{

String log4jFile = System.getProperty(log4j.file);

Properties properties = new Properties();

properties.load(new FileInputStream(log4jFile));

updateLoggingConfiguration(properties);

PropertyConfigurator.configure(properties);

}

catch (IOException ioEx)

{

throw new RuntimeException(failed to reconfigure
 logger 

+ ioEx.getMessage(), ioEx);

}

logger = Logger.getLogger(this.getClass());

logger.info(Log4j RE initialised to use INFO logs
 everywhere !);

logger.debug(THIS SHOULD NEVER COME IN LOGS);

}



private void updateLoggingConfiguration(Properties properties)

{

for (Iterator iterator =
 properties.entrySet().iterator(); iterator

.hasNext();)

{

Entry entry = (Entry) iterator.next();

String key = (String) entry.getKey();

if (key.equalsIgnoreCase(log4j.rootLogger))

{


 entry.setValue(getRootLoggerConfiguration((String) entry

.getValue()));

}

else if (key.startsWith(log4j.logger))

{

iterator.remove();

}

}

}



private String getRootLoggerConfiguration(String currentConfig)

{

String[] tokens = IOUtil.tokenizeString(currentConfig,
 ,);

StringBuilder builder = new StringBuilder();

for (int i = 0; i  tokens.length; i++)

{

if (i == 0)

{

builder.append(INFO);

continue;

}

builder.append(,  + tokens[i]);

}

return builder.toString();

}