FileDocCategorySizeDatePackage
ErrorLog.javaAPI DocGlassfish v2 API13152Fri May 04 22:36:38 BST 2007com.sun.jts.CosTransactions

ErrorLog

public class ErrorLog extends Object
Provides a log of error messages.
version
0.01
author
Simon Holdsworth, IBM Corporation
see

Fields Summary
private static Messages
messages
The message format strings.
static final String
DEFAULT_LOGFILE
The default error log file name.
private static String
errorLogPath
The path of the log file.
private static String
serverName
The name of the server.
Constructors Summary
Methods Summary
public static final voiderror(int message, java.lang.Object[] inserts, boolean fatal)
Writes an error message to the error log and to the screen.

Note that the inserts should be Strings, Integers or Dates. Exceptions should be converted to strings before calling this method.

param
message The error message number.
param
inserts The error message inserts.
param
fatal Indicates whether the error is fatal.
return
see

        String messageStr = getMessage(message, inserts);

        // First display the message to the screen.

        System.err.println(
            ErrorLog.getMessage(Messages.MSG_JTS_ERROR,
                                new java.lang.Object[] { messageStr })
                          );
        (new Exception()).printStackTrace();

        // Write the message to the log file.
        /*
        messageStr = new Date().toString() + " : " + serverName + " : JTS" +
            messages.getMessageNumber(message)+
            (fatal ? "F " : "E ") +
            messageStr + "\n";
        */
        String dateString = DateFormat.getDateTimeInstance().format(new Date());
        messageStr = ErrorLog.getMessage(Messages.LOG_MESSAGE,
                                         new java.lang.Object[] {
                                            dateString, serverName,
                                            messages.getMessageNumber(message),
                                            (fatal ? "F"/*#Frozen*/ : "E"/*#Frozen*/),
                                            messageStr,
                                         });

        fileWrite(messageStr);

        // If the error is fatal, then end the process.

        if (fatal) {
            // CHANGED(Ram J) - fatal errors should not cause VM crash.
            //System.exit(1);

            // throw a system exception, so that the app or the app server
            // may catch it. Note: This may leave the tx objects in an
            // inconsistent state, and may result in a memory leak (?).
            throw new org.omg.CORBA.INTERNAL(messageStr);
        }
    
private static final voidfileWrite(java.lang.String message)
Writes an error message to the error log.

param
message The error message.
return
see

        if (Configuration.getPropertyValue(Configuration.ERR_LOGGING) == null) {
            return;
        }

        // Open the error log file and append the message.

        try {
            File errFileHandle = new File(errorLogPath, DEFAULT_LOGFILE);
            RandomAccessFile fileOutput = new RandomAccessFile(errFileHandle,"rw"/*#Frozen*/);
            fileOutput.seek(fileOutput.length());
            fileOutput.writeBytes(message);
            fileOutput.close();
        } catch( Throwable e ) {
            System.err.println(
                ErrorLog.getMessage(Messages.LOG_FILE_WRITE_ERROR)
                              );
        }
    
static final java.lang.StringgetMessage(int message, java.lang.Object[] inserts)
Returns a formatted message given the message number and inserts.

Note that the inserts should be Strings, Integers or Dates. Exceptions should be converted to strings before calling this method.

param
message The message number.
param
inserts The message inserts.
return
The formatted string.
see

        String result = null;

        // Get the error log file path, and the message formats.

        if (errorLogPath == null) {
            setup();
        }

        // Format the message.

        if (inserts == null) {
            inserts = new Object[0];
        }

        return messages.getMessage(message, inserts);
    
public static final java.lang.StringgetMessage(int messageNum)
Returns an unformatted message given the message number.

param
messageNum The message number.
return
The unformatted string.
see

        String result = null;

        // Get the error log file path, and the message formats.

        if (errorLogPath == null) {
            setup();
        }

        return messages.getMessage(messageNum);
    
public static final voidinfo(int message, java.lang.Object[] inserts)
Writes an informational message to the error log and to the screen.

Note that the inserts should be Strings, Integers or Dates. Exceptions should be converted to strings before calling this method.

param
message The informational message number.
param
inserts The informational message inserts.
return
see

        String messageStr = getMessage(message, inserts);

        // First display the message to the screen.

        System.err.println(
            ErrorLog.getMessage(Messages.MSG_JTS_INFO,
                                new java.lang.Object[] { messageStr })
                          );

        // Write the message to the log file.
        /*
        messageStr = new Date().toString() + " : " + serverName + " : JTS" +
            messages.getMessageNumber(message)+"I "+
            messageStr + "\n";
        */
        String dateString = DateFormat.getDateTimeInstance().format(new Date());
        messageStr = ErrorLog.getMessage(Messages.LOG_MESSAGE,
                                         new java.lang.Object[] {
                                            dateString, serverName,
                                            messages.getMessageNumber(message),
                                            "I"/*#Frozen*/, messageStr,
                                         });
        fileWrite(messageStr);
    
private static final voidsetup()
Sets up the error log path.

param
return
see


                 
         
        // Get the error log file path.

        int[] result = new int[1];
        errorLogPath = Configuration.getDirectory(Configuration.TRACE_DIRECTORY,
                                                  Configuration.JTS_SUBDIRECTORY,
                                                  result);

        // If a default was used, display a message.

        if( result[0] == Configuration.DEFAULT_USED ||
            result[0] == Configuration.DEFAULT_INVALID ) {

            // In the case where the SOMBASE default is used, only display a message if
            // an invalid value was specified in the environment value.

            boolean loggingOn =
                Configuration.getPropertyValue(Configuration.ERR_LOGGING)
                != null;

            if (errorLogPath != null && loggingOn) {
                System.err.println(
                    ErrorLog.getMessage(Messages.INVALID_LOG_PATH,
                                        new java.lang.Object[]
                                            { errorLogPath })
                                  );
            }

            // In the case where the SOMBASE default is invalid, the value returned is
            // the invalid default. We then default to the current directory.

            if( result[0] == Configuration.DEFAULT_INVALID ) {
                if (loggingOn) {
                    System.err.println(
                        ErrorLog.getMessage(Messages.INVALID_DEFAULT_LOG_PATH)
                                      );
                }
                errorLogPath = "."/*#Frozen*/;
            }
        }

        // Get the server name too.

        serverName = Configuration.getServerName();
        if( serverName == null )
            serverName = "Anonymous transient server"/*#Frozen*/;

        // Get the ResourceBundle contents for message formats.

        messages = (Messages)ResourceBundle.getBundle("com.sun.jts.CosTransactions.Messages");
    
public static final voidwarning(int message, java.lang.Object[] inserts)
Writes a warning message to the error log and to the screen.

Note that the inserts should be Strings, Integers or Dates. Exceptions should be converted to strings before calling this method.

param
message The warning message number.
param
inserts The warning message inserts.
return
see

        String messageStr = getMessage(message, inserts);

        // First display the message to the screen.

        System.err.println(
            ErrorLog.getMessage(Messages.MSG_JTS_WARNING,
                                new java.lang.Object[] { messageStr })
                          );

        // Write the message to the log file.
        /*
        messageStr = new Date().toString() + " : " + serverName + " : JTS" +
            messages.getMessageNumber(message)+"W "+
            messageStr + "\n";
        */
        String dateString = DateFormat.getDateTimeInstance().format(new Date());
        messageStr = ErrorLog.getMessage(Messages.LOG_MESSAGE,
                                         new java.lang.Object[] {
                                            dateString, serverName,
                                            messages.getMessageNumber(message),
                                            "W"/*#Frozen*/, messageStr,
                                         });
        fileWrite(messageStr);