I need to modify the log system we currently have. At the moment it writes
out to 4 separate files: warnings.log, trace.log, errors.log and notice.log.
What I need to do is to have only two log files: trace.log and errors.log
The detail of the info in the trace.log file needs to be set on three
levels. I need to set up variable that can be set to "compact", "verbose"
and "debug" depending on the current settings. If anyone could give me a
hint on how I would do it. Thanx much!
In case is someone is interested to take a look at the code, here it is:
import java.io.*;
import grace.log.*;
import org.w3c.dom.*;

public class LogWrapper {

private static Log instancelog = null;

private static LogWrapper log = null;


public static final String ERROR ="error";
/** */
public static final String WARNING = "warning";
/** */
public static final String TRACE = "trace";
/** */
public static final String NOTICE = "notice";

private String logMode;

public static synchronized LogWrapper getInstance()
{
if (log == null)
log = new LogWrapper();
return log;
}

public static synchronized LogWrapper getInstance( String smsRoot, Element e
)
{
if (log == null)
log = new LogWrapper( smsRoot, e );
return log;
}

private LogWrapper()
{
}


private LogWrapper(String smsRoot, Element logConf)
{
String pathfilelog = null;
String event_display = null;
String event = null;
String mode = null;

logMode = "normal";

instancelog = Log.getInstance ();

int numFileHandler = logConf.getElementsByTagName( "FileHandler"
).getLength();
for(int n=0; n<numFileHandler; n++)
{
pathfilelog = smsRoot + ( (Element)logConf.getElementsByTagName(
"FileHandler" ).item(n)).getAttribute( "file" );

event_display = ((Element)logConf.getElementsByTagName( "FileHandler"
).item(n)).getAttribute( "display");

event = event_display.toLowerCase();

mode = ((Element)logConf.getElementsByTagName( "FileHandler"
).item(n)).getAttribute( "mode");

if ( event.equalsIgnoreCase("all"))
this.addFileHandler(pathfilelog,mode);
else
this.addFileHandler(pathfilelog,mode,event);

if (event.equals("trace")) {
this.logMode = "testing";
}

}
}


public void addFileHandler(String pathfilelog, String mode)
{
System.out.println("Open file "+ pathfilelog +" to check for All events");
try
{
if (mode.equalsIgnoreCase("replace"))
{
File filelog = new File(pathfilelog);

File fullPath = filelog.getParentFile();
if (!fullPath.exists())
{
fullPath.mkdirs();
}

filelog.delete();
}
FileHandler fh = new FileHandler(pathfilelog);
instancelog.addHandler (fh);
}
catch(java.rmi.RemoteException exc)
{
exc.printStackTrace ();
}
}

public void addFileHandler(String pathfilelog, String mode, String event)
{
boolean testevent = false;

System.out.println("Open file "+ pathfilelog +" to check for "+event+"s");
try
{
testevent = control(event);
}
catch(EventTypeException exc)
{
System.out.println(exc.getMessage());
}

if (testevent==true)
{
try
{
if (mode.equalsIgnoreCase("replace"))
{
File filelog = new File(pathfilelog);

File fullPath = filelog.getParentFile();
if (!fullPath.exists())
{
fullPath.mkdirs();
}

filelog.delete();
}
FileHandler fh = new FileHandler(pathfilelog);
instancelog.addHandler(fh,event);
}
catch(java.rmi.RemoteException exc)
{
exc.printStackTrace ();
}
}
}

private boolean control(String event) throws EventTypeException
{
if (event.equalsIgnoreCase("error") || event.equalsIgnoreCase("notice") ||
event.equalsIgnoreCase("trace") || event.equalsIgnoreCase("warning"))
{
return true;
}
else
{
throw new EventTypeException("ERROR : USAGE name= \"error\" or \"warning\"
or \"notice\" or \"trace\"");
}
}

public static void error(String message)
{
instancelog.error(message);
}

public static void error(Exception exc)
{
instancelog.error(exc);
}

public static void error(String message, Exception exc)
{
String messagexc = message + " : "+exc.toString();
instancelog.error(messagexc);
}

public static void error(String message, Object obj)
{
instancelog.error(message,obj);
}


public static void warning(String message)
{
instancelog.warning(message);
}

public static void warning(String message, Exception exc)
{
String messagexc = message + " : "+exc.toString();
instancelog.warning(messagexc);
}

public static void warning(String message, Object obj)
{
instancelog.warning(message,obj);
}

public static void notice(String message)
{
instancelog.notice(message);
}

public static void notice(String message, Object obj)
{
instancelog.notice(message,obj);
}

public static void trace()
{
instancelog.trace();
}

public static void trace(Object obj)
{
instancelog.trace(obj);
}

public static void trace(String message)
{
instancelog.trace(message);
}

public static void trace(String message, Object obj)
{
instancelog.trace(message,obj);
}

public String getLogMode()
{
return this.logMode;
}

}


Alex.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to