ErrorLogpublic class ErrorLog extends Object Provides a log of error messages. |
Fields Summary |
---|
private static Messages | messagesThe message format strings. | static final String | DEFAULT_LOGFILEThe default error log file name. | private static String | errorLogPathThe path of the log file. | private static String | serverNameThe name of the server. |
Methods Summary |
---|
public static final void | error(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.
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 void | fileWrite(java.lang.String message)Writes an error message to the error log.
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.String | getMessage(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.
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.String | getMessage(int messageNum)Returns an unformatted message given the message number.
String result = null;
// Get the error log file path, and the message formats.
if (errorLogPath == null) {
setup();
}
return messages.getMessage(messageNum);
| public static final void | info(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.
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 void | setup()Sets up the error log path.
// 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 void | warning(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.
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);
|
|