"ravi" <[EMAIL PROTECTED]> wrote:
>>Center> Tech Notes> Docs> Release Notes> Patches> Tech Blitz> Developer Connection>
         Developer Forums> Developer Tour> Training> Download>>> Contact Support> 
North America>
         Europe> Web Contact Form>>> New phone number:  877-838-7224>>> Old Phone 
number,>valid
         till 30 Nov 1999:  650-462-7600>>>> >   netdynamics.public.support.nd4.talk 
item
         19579 >Top All Mailing List Subscribe Recent Items Related Items Reply Post 
Search
         This Group Search All Groups >>>>Subject: Help with redirecting critical 
errors >Date:
         13 Oct 1999 10:22:07 -0700 >From: "ravi" <[EMAIL PROTECTED]> >>>>>Hi!>can 
anybody
         please help me out with this situation.>all the errors are sent to the log 
service
         of command center. suppose we do not view it daily and there has been some 
critical
         error occuring like say database access is down or its not going to 
underwriting,
         now such errors we wont realise unless some user calls and tells us that he 
his unable
         to proceed further on the web site beyond a particular point.>so is there any 
way
         that we can send these critical errors to a flat file in addition to the log 
service
         and view them directly from the flat file.>If we can, then How?>>please help 
me out.Urgent
        !!!>>thanks,>ravi>> 


public class ErrorLog {

        public final static int EMERGENCY       = 0;      // system is unusable
        public final static int ALERT           = 1;      // action must be taken 
immediately
        public final static int CRITICAL        = 2;      // critical conditions
        public final static int ERROR           = 3;      // error conditions
        public final static int WARNING         = 4;      // warning conditions
        public final static int NOTICE          = 5;      // normal but signification 
condition
        public final static int INFORMATIONAL   = 6;      // informational
        public final static int DEBUG           = 7;      // debug-level messages

        private static FileOutputStream logstr = null;
        private static String logfile = new String("applicationError.log");
        private static boolean loggingdisabled = false;
        private static final String LogMsg[] = {        // String representation of 
log levels
                                "Emergency",
                                "Alert",
                                "Critical",
                                "Error",
                                "Warning",
                                "Notice",
                                "Information",
                                "Debug",
                                "Query" };

/**
 *      send ()
 *      write event to log file
 *  @param Object
 *  @param severity
 *  @param Object
 * 
 */     
        public static void send (Object classPtr, int severity, Object content)
        {
                if (content instanceof Exception) {
                        writeLog( classPtr, severity, (Exception)content);
                        return;
                }
                if (content instanceof String) {
                        writeLog( classPtr, severity, (String)content);
                        return;
                }
        }

/**
 *      writeLog ()
 *      write event to log file
 *      @param severity
 *      @param debug message
 * 
 */     

        private static synchronized void writeLog (Object obj, int sev, String message)
        {

                Date    now = new Date();
                String  outmessage;
                byte    b[];

                outmessage = new String ("[" + now + "] " + LogMsg[sev] +": " + 
obj.toString() + ":  " + message + "\r\n");
                b = outmessage.getBytes();

                try {
                        if (logstr == null)
                           logstr = new FileOutputStream(
 CSpUtil.getEnv( "NETDYN_INSTALL" ) + "/bin/applicationError.log", true); // open 
logging output stream
                        logstr.write(b);
                }
                catch (IOException e) {
                        // what happens on log file open error ??
                           try {
                               logstr = new FileOutputStream(logfile, true); // open 
logging output stream
                               logstr.write(b);
                           }
                           catch ( IOException e2 ) {}
                }
        }

/**
 *      writeLog ()
 *      write event to log file
 *      @param  java.lang.Exception
 * 
 */     
        
        private static synchronized void writeLog (Object obj, int sev, Exception ex)
        {
                Date    now = new Date();
                String  outmessage;
                byte    b[];
                FileOutputStream logstr = null;
                
                
                outmessage = new String ("[" + now + "] " + LogMsg[sev] + ": " + 
obj.toString() + ":  " + "**Exception**" + "\r\n");
                b = outmessage.getBytes();

                try {
                        if (logstr == null)
                           logstr = new FileOutputStream(
     CSpUtil.getEnv( "NETDYN_INSTALL" ) + "/bin/applicationError.log", true); // open 
logging output stream
                        logstr.write(b);
                }
                catch (IOException e) {
                        // what happens on log file write error ??
                           try {
                               logstr = new FileOutputStream(logfile, true); // open 
logging output stream
                               logstr.write(b);
                           }
                           catch ( IOException e2 ) {}
                }
                                
                if (logstr != null) {
                // PrintWriter pw = new PrintWriter(logstr);  // printStackTrace 
doesn't like PrintWriter
                   PrintStream ps = new PrintStream(logstr);       // so we use a 
deprecated method which
                   ex.printStackTrace(ps);                         // works.
                }
        }
}
_________________________________________________________________________

For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html

For dire need help, email: [EMAIL PROTECTED]

Reply via email to