You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Ishihara, Noriaki" <No...@fiserv.com> on 2001/09/24 23:14:54 UTC
configureHierarchy method
Hi, all.
Following is the source code for configureHierarchy method which is in SocketServer class.
The code I am in question is that when 7 and 8th line of code (including comment).
When inetAddress.toString() gets executed, it returns /my.local.ip.number.
And then next line it searches for the index of "/". Since toString method returns a string starting with "/", index will be set to zero.
Thus on the else clause, "String key = s.substring(0, i);". The key variable will be set to blank.
So, that is the reason why my File statement fails. (c:/.lcf will be the formed string)
How is everybody coping with this, if you want to run the client from command line by passing the configuration file absolute path?
Thanks for your help!!
// This method assumes that there is no hiearchy for inetAddress
// yet. It will configure one and return it.
Hierarchy configureHierarchy(InetAddress inetAddress) {
cat.info("Locating configuration file for "+inetAddress);
// We assume that the toSting method of InetAddress returns is in
// the format hostname/d1.d2.d3.d4 e.g. torino/192.168.1.1
String s = inetAddress.toString();
int i = s.indexOf("/");
if(i == -1) {
cat.warn("Could not parse the inetAddress ["+inetAddress+
"]. Using default hierarchy.");
return genericHierarchy();
} else {
String key = s.substring(0, i);
File configFile = new File(dir, key+CONFIG_FILE_EXT);
if(configFile.exists()) {
Hierarchy h = new Hierarchy(new RootCategory(Priority.DEBUG));
hierarchyMap.put(inetAddress, h);
new PropertyConfigurator().doConfigure(configFile.getAbsolutePath(), h);
return h;
} else {
cat.warn("Could not find config file ["+configFile+"].");
return genericHierarchy();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: configureHierarchy method
Posted by Cory Omand <co...@Sun.com>.
Ishihara,
There is a far easier way to get the address or hostname from the InetAddress...
String addr = inetAddress.getLocalHost().getHostAddress(); // Returns '192.168.1.1'
String host = inetAddress.getLocalHost().getHostName(); // Returns 'torino'
C.
"Ishihara, Noriaki" wrote:
>
> Hi, all.
> Following is the source code for configureHierarchy method which is in SocketServer class.
> The code I am in question is that when 7 and 8th line of code (including comment).
>
> When inetAddress.toString() gets executed, it returns /my.local.ip.number.
> And then next line it searches for the index of "/". Since toString method returns a string starting with "/", index will be set to zero.
> Thus on the else clause, "String key = s.substring(0, i);". The key variable will be set to blank.
> So, that is the reason why my File statement fails. (c:/.lcf will be the formed string)
>
> How is everybody coping with this, if you want to run the client from command line by passing the configuration file absolute path?
>
> Thanks for your help!!
>
> // This method assumes that there is no hiearchy for inetAddress
> // yet. It will configure one and return it.
> Hierarchy configureHierarchy(InetAddress inetAddress) {
> cat.info("Locating configuration file for "+inetAddress);
> // We assume that the toSting method of InetAddress returns is in
> // the format hostname/d1.d2.d3.d4 e.g. torino/192.168.1.1
> String s = inetAddress.toString();
> int i = s.indexOf("/");
> if(i == -1) {
> cat.warn("Could not parse the inetAddress ["+inetAddress+
> "]. Using default hierarchy.");
> return genericHierarchy();
> } else {
> String key = s.substring(0, i);
> File configFile = new File(dir, key+CONFIG_FILE_EXT);
> if(configFile.exists()) {
> Hierarchy h = new Hierarchy(new RootCategory(Priority.DEBUG));
> hierarchyMap.put(inetAddress, h);
>
> new PropertyConfigurator().doConfigure(configFile.getAbsolutePath(), h);
>
> return h;
> } else {
> cat.warn("Could not find config file ["+configFile+"].");
> return genericHierarchy();
> }
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
--
===============================================================
Cory C. Omand - Test Engineer Direct: 510.574.6096
Sun Microsystems Fax: 510.774.6194
World Wide Operations Pager: 510.774.PAGE (7423)
Newark, CA USA [PIN - 5107742570]
===============================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org