Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   * 
   * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   * 
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License. You can obtain
  * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
  * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  * 
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
  * Sun designates this particular file as subject to the "Classpath" exception
  * as provided by Sun in the GPL Version 2 section of the License file that
  * accompanied this code.  If applicable, add the following below the License
  * Header, with the fields enclosed by brackets [] replaced by your own
  * identifying information: "Portions Copyrighted [year]
  * [name of copyright owner]"
  * 
  * Contributor(s):
  * 
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 /*
  * Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 //----------------------------------------------------------------------------
 //
 // Module:      ErrorLog.java
 //
 // Description: Error logging facility.
 //
 // Product:     com.sun.jts.CosTransactions
 //
 // Author:      Simon Holdsworth
 //
 // Date:        March, 1997
 //
 // Copyright (c):   1995-1997 IBM Corp.
 //
 //   The source code for this program is not published or otherwise divested
 //   of its trade secrets, irrespective of what has been deposited with the
 //   U.S. Copyright Office.
 //
 //   This software contains confidential and proprietary information of
 //   IBM Corp.
 //----------------------------------------------------------------------------
 
 package com.sun.jts.CosTransactions;
 
 // Import required classes.
 
 import java.io.*;
 import java.util.*;
Provides a log of error messages.

Author(s):
Simon Holdsworth, IBM Corporation
Version:
0.01
See also:
 
 //----------------------------------------------------------------------------
 // CHANGE HISTORY
 //
 // Version By     Change Description
 //   0.01  SAJH   Initial implementation.
 //------------------------------------------------------------------------------
 
 public class ErrorLog extends Object {
    
The message format strings.
 
     private static Messages messages = null;

    
The default error log file name.
 
     static final String DEFAULT_LOGFILE = "jts.log"/*#Frozen*/;

    
The path of the log file.
 
     private static String errorLogPath = null;

    
The name of the server.
    private static String serverName = null;

    
Sets up the error log path.

Parameters:
Returns:
See also:
    private static final void setup() {
        // Get the error log file path.
        int[] result = new int[1];
         = Configuration.getDirectory(.,
                                                  .,
                                                  result);
        // If a default was used, display a message.
        ifresult[0] == . ||
            result[0] == . ) {
            // 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(.)
                != null;
            if ( != null && loggingOn) {
                ..println(
                    ErrorLog.getMessage(.,
                                        new java.lang.Object[]
                                            {  })
                                  );
            }
            // In the case where the SOMBASE default is invalid, the value returned is
            // the invalid default. We then default to the current directory.
            ifresult[0] == . ) {
                if (loggingOn) {
                    ..println(
                        ErrorLog.getMessage(.)
                                      );
                }
                 = "."/*#Frozen*/;
            }
        }
        // Get the server name too.
         = Configuration.getServerName();
        if == null )
             = "Anonymous transient server"/*#Frozen*/;
        // Get the ResourceBundle contents for message formats.
         = (Messages)ResourceBundle.getBundle("com.sun.jts.CosTransactions.Messages");
    }

    
Writes an error message to the error log.

Parameters:
message The error message.
Returns:
See also:
    private static final void fileWriteString message ) {
        if (Configuration.getPropertyValue(.) == null) {
            return;
        }
        // Open the error log file and append the message.
        try {
            File errFileHandle = new File();
            RandomAccessFile fileOutput = new RandomAccessFile(errFileHandle,"rw"/*#Frozen*/);
            fileOutput.seek(fileOutput.length());
            fileOutput.writeBytes(message);
            fileOutput.close();
        } catchThrowable e ) {
            ..println(
                ErrorLog.getMessage(.)
                              );
        }
    }

    
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.

Parameters:
message The error message number.
inserts The error message inserts.
fatal Indicates whether the error is fatal.
Returns:
See also:
    public static final void error(int messageObject[] inserts,
                                    boolean fatal) {
        String messageStr = getMessage(messageinserts);
        // First display the message to the screen.
        ..println(
            ErrorLog.getMessage(.,
                                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(.,
                                         new java.lang.Object[] {
                                            dateString,
                                            .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);
        }
    }

    
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.

Parameters:
message The warning message number.
inserts The warning message inserts.
Returns:
See also:
    public static final void warning(int messageObject[] inserts) {
        String messageStr = getMessage(messageinserts);
        // First display the message to the screen.
        ..println(
            ErrorLog.getMessage(.,
                                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(.,
                                         new java.lang.Object[] {
                                            dateString,
                                            .getMessageNumber(message),
                                            "W"/*#Frozen*/messageStr,
                                         });
        fileWrite(messageStr);
    }

    
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.

Parameters:
message The informational message number.
inserts The informational message inserts.
Returns:
See also:
    public static final void info(int messageObject[] inserts) {
        String messageStr = getMessage(messageinserts);
        // First display the message to the screen.
        ..println(
            ErrorLog.getMessage(.,
                                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(.,
                                         new java.lang.Object[] {
                                            dateString,
                                            .getMessageNumber(message),
                                            "I"/*#Frozen*/messageStr,
                                         });
        fileWrite(messageStr);
    }

    
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.

Parameters:
message The message number.
inserts The message inserts.
Returns:
The formatted string.
See also:
    static final String getMessage(int messageObject[] inserts) {
        String result = null;
        // Get the error log file path, and the message formats.
        if ( == null) {
            setup();
        }
        // Format the message.
        if (inserts == null) {
            inserts = new Object[0];
        }
        return .getMessage(messageinserts);
    }

    
Returns an unformatted message given the message number.

Parameters:
messageNum The message number.
Returns:
The unformatted string.
See also:
    public static final String getMessage(int messageNum) {
        String result = null;
        // Get the error log file path, and the message formats.
        if ( == null) {
            setup();
        }
        return .getMessage(messageNum);
    }
New to GrepCode? Check out our FAQ X