• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

problem in configuring log4j in struts

 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
i have a class which has a static block and a static method.For the first time i call the static method in the class its strange that its excuting a part of the static block and entering the method later and agian turning back to static block.
but for the secon time when i call the static method in that class its fine that static block is not executed..
here is the code of the class which contains static block and static method
and propertyprovider is a class which contains methods for returning the path and .. which are in propeties file "plas.properties"
public class LogServices
{
private static String propFilename="plas.properties";
private static String file="vdvd";
static
{
System.out.println("Inside static block");
try
{
System.out.println("Inside static block of Plasma Log Services ");
file=PropertyProvider.getProperty(propFilename,"Log4jprops"); // here i am calling another method in another class to get some string from properties
System.out.println("\n File is ********************************** "+file);
}
catch(Exception e)
{
System.out.println("Exception encountered the following Exception ["+e.getMessage()+"]");
}
System.out.println("Finished static block");
}
public static Logger initLog()
{

Logger logger=Logger.getLogger(PlasmaLogServices.class);

System.out.println("File in method is:"+file);
return logger;
}
}
and in my main program i am calling this
LogServices.initLog(); and the output i observed on the screen is
---------------------------------------------
Inside static block
Inside static block of Plasma Log Services
File in method is:vdvd
File is ********************************** log.properties
Finished static block
------------------------------------------
if u look at the output after " Inside static block of Plasma Log Services" (part of static block) its enetering method where " File in method is:vdvd" is printed .
After some debugging i came to know that if i remove the line
file=PropertyProvider.getProperty(propFilename,"Log4jprops"); and replace it by file="log.properties";(mean hardcoded) then the static block executes and later that method executes.

can any one pls help me in this regard???
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic