org.safs.staf.service.logging
Class AbstractSAFSLoggingService

java.lang.Object
  extended by org.safs.staf.service.logging.AbstractSAFSLoggingService
Direct Known Subclasses:
SAFSLoggingService, SAFSLoggingService3

public abstract class AbstractSAFSLoggingService
extends java.lang.Object

AbstractSAFSLoggingService is an external STAF service that handles standard SAFS logging. This class is defined as an abstract class, for different version of STAF, you may extends this class and implements the staf-version-related interface (STAFServiceInterfaceLevel30 or STAFServiceInterfaceLevel3). We have implemented the class for version 2 and 3: SAFSLoggingService and SAFSLoggingService3

This service supports multiple processes (SAFS-aware testing tools) running in support of the same test at the same time to write to the same log facility (see AbstractLogFacility). It provides all standard SAFS logging functions, including creating new log facilities, interrogating and manipulating settings of existing log facilities, logging messages etc. This service also keeps track of all log facilities that it created. All tools should perform standard SAFS logging via this service so that their logging actions can be coordinated.

Internally this service uses STAF LOG service to store messages for running logs until they are closed, when the content of the STAF log is exported to the destination. Upon initializing, this service will load a unique instance of STAF LOG service to use for the temporary STAF logs (The name of this STAF LOG service instance is "<ServiceName>Log", where <ServiceName> is the registered name of this service).

This service can operate in two modes: local or remote, which is specified when this service is registered with STAF (statically via STAF.cfg file or dynamically using the SERVICE service). In local mode, logs are generated on the local machine. In remote mode, logs are generated on a remote machine. In this case, the remote machine must be running this service in local mode. Settings such as the default log directory are all with respect to the remote machine. The local service simply serves as a proxy to the remote service. From a user's perspective, however, there is absolutely no difference at all in how to submit requests to this service.

This service can also invoke custom logging functions, which must be implemented as a STAF service. A custom logging service is required to expose certain commands that this service will call. Custom logging can only be enabled in local mode.

Registration of this service takes the following format:

SERVICE <ServiceName> LIBRARY JSTAF EXECUTE <ServiceJarFile> PARMS [DIR <LogDir>] [REMOTE <RemoteMachine> [NAME <RemoteServiceName>]] [CUSTOMLOGGING <CustomLoggingService>]

Example:

SERVICE SAFSLogs LIBRARY JSTAF EXECUTE c:\staf\services\SAFSLogs.jar PARMS DIR c:\safslogs
SERVICE SAFSLogs LIBRARY JSTAF EXECUTE c:\staf\services\SAFSLogs.jar PARMS DIR c:\safslogs CUSTOMLOGGING SAFSCustomLogs
SERVICE SAFSLogs LIBRARY JSTAF EXECUTE c:\staf\services\SAFSLogs.jar PARMS REMOTE LogServer

This service provides the following commands:

 HANDLEID
 INIT        <facname> [TEXTLOG [<altname>]] [XMLLOG [<altname>]] [TOOLLOG] [CONSOLELOG] [ALL]
             [LINKEDFAC <name>] [OVERWRITE] [CAPXML]
 QUERY       <facname> [TEXTLOG | XMLLOG | TOOLLOG | CONSOLELOG | ALL]
 LIST        [SETTINGS]
 SUSPENDLOG  <facname> | ALL
 RESUMELOG   <facname> | ALL
 LOGLEVEL    <facname> [DEBUG | INFO | WARN | ERROR]
 LOGMESSAGE  <facname> MESSAGE <msg> [DESCRIPTION <desc>] [MSGTYPE <msgType>]
 CLOSE       <facname> | ALL  [CAPXML]
 HELP        [MSGTYPE]
 VERSION
 

Since:
MAY 19, 2009 (LW) Add two abstract methods getSTAFTextLogItem() and getSTAFXmlLogItem() Modify method handleInit() so that the right STAF-version LogItem will be instantiated.
See Also:
AbstractLogFacility, SLSLogFacility, SAFSCustomLoggingService, SAFSCustomLoggingService3, "SAFSLogs Service User's Guide", SAFSLoggingService, SAFSLoggingService3

Field Summary
protected  com.ibm.staf.service.STAFCommandParser closeParser
           
protected  java.lang.String customService
           
protected  ServiceDebugLog debugLog
           
protected  java.lang.String defaultDir
           
protected static com.ibm.staf.STAFHandle handle
           
static java.lang.String HELP_MSGTYPE_STR
           
static java.lang.String HELP_STR
           
protected  com.ibm.staf.service.STAFCommandParser helpParser
           
protected  com.ibm.staf.service.STAFCommandParser initParser
           
protected  com.ibm.staf.service.STAFCommandParser listParser
           
protected  java.util.Hashtable logfacs
          Stores all open log facilities created by this service.
protected  com.ibm.staf.service.STAFCommandParser logLevelParser
           
protected  com.ibm.staf.service.STAFCommandParser logMessageParser
           
protected  java.lang.String mode
           
protected  java.lang.String procName
           
protected  com.ibm.staf.service.STAFCommandParser queryParser
           
protected  java.lang.String remoteMachine
           
protected  java.lang.String remoteService
           
protected  com.ibm.staf.service.STAFCommandParser resumeLogParser
           
static java.lang.String SLS_SERVICE_MODE_LOCAL
           
static java.lang.String SLS_SERVICE_MODE_REMOTE
           
static java.lang.String SLS_SERVICE_OPTION_CUSTOMLOGGING
           
static java.lang.String SLS_SERVICE_OPTION_DIR
           
static java.lang.String SLS_SERVICE_OPTION_NAME
           
static java.lang.String SLS_SERVICE_OPTION_REMOTE
           
static java.lang.String SLS_SERVICE_PARM_ALL
           
static java.lang.String SLS_SERVICE_PARM_CAPXML
           
static java.lang.String SLS_SERVICE_PARM_CONSOLELOG
           
static java.lang.String SLS_SERVICE_PARM_DEBUG
           
static java.lang.String SLS_SERVICE_PARM_DESCRIPTION
           
static java.lang.String SLS_SERVICE_PARM_ERROR
           
static java.lang.String SLS_SERVICE_PARM_INFO
           
static java.lang.String SLS_SERVICE_PARM_LINKEDFAC
           
static java.lang.String SLS_SERVICE_PARM_MESSAGE
           
static java.lang.String SLS_SERVICE_PARM_MSGTYPE
           
static java.lang.String SLS_SERVICE_PARM_OVERWRITE
           
static java.lang.String SLS_SERVICE_PARM_SETTINGS
           
static java.lang.String SLS_SERVICE_PARM_TEXTLOG
           
static java.lang.String SLS_SERVICE_PARM_TOOLLOG
           
static java.lang.String SLS_SERVICE_PARM_WARN
           
static java.lang.String SLS_SERVICE_PARM_XMLLOG
           
static java.lang.String SLS_SERVICE_REQUEST_CLOSE
           
static java.lang.String SLS_SERVICE_REQUEST_HANDLEID
           
static java.lang.String SLS_SERVICE_REQUEST_HELP
           
static java.lang.String SLS_SERVICE_REQUEST_INIT
           
static java.lang.String SLS_SERVICE_REQUEST_LIST
           
static java.lang.String SLS_SERVICE_REQUEST_LOGLEVEL
           
static java.lang.String SLS_SERVICE_REQUEST_LOGMESSAGE
           
static java.lang.String SLS_SERVICE_REQUEST_QUERY
           
static java.lang.String SLS_SERVICE_REQUEST_RESUMELOG
           
static java.lang.String SLS_SERVICE_REQUEST_SUSPENDLOG
           
static java.lang.String SLS_SERVICE_REQUEST_VERSION
           
static java.lang.String SLS_SETTINGS_CUSTOM_LOGGING_PREFIX
          Prefix to the custom logging service setting of this service in response to the LIST SETTINGS command.
static java.lang.String SLS_SETTINGS_DEFAULT_DIR_PREFIX
          Prefix to the default directory setting of this service in response to the LIST SETTINGS command.
static java.lang.String SLS_SETTINGS_MODE_PREFIX
          Prefix to the mode setting of this service in response to the LIST SETTINGS command.
static java.lang.String SLS_SETTINGS_REMOTE_MACHINE_PREFIX
          Prefix to the remote machine setting of this service in response to the LIST SETTINGS command.
static java.lang.String SLS_SETTINGS_REMOTE_SERVICE_PREFIX
          Prefix to the remote service setting of this service in response to the LIST SETTINGS command.
static java.lang.String SLS_STAF_LOG_SERVICE_NAME
          The name of the separate instance of STAF LOG service loaded and used solely by this service in local mode.
static java.lang.String SLS_STATES_CONSOLELOG_PREFIX
          Prefix to the consolelog state of this service in the result buffer of every LOGMESSAGE command.
static java.lang.String SLS_STATES_LOGLEVEL_PREFIX
          Prefix to the log level state of this service in the result buffer of every LOGMESSAGE command.
static java.lang.String SLS_STATES_TOOLLOG_PREFIX
          Prefix to the toollog state of this service in the result buffer of every LOGMESSAGE command.
protected  com.ibm.staf.service.STAFCommandParser suspendLogParser
           
static java.lang.String VERSION_STR
           
 
Constructor Summary
AbstractSAFSLoggingService()
           
 
Method Summary
 com.ibm.staf.STAFResult acceptRequest(InfoInterface.RequestInfo info)
          Handles service request from STAF.
protected  void createCloseParser()
           
protected  void createHelpParser()
           
protected  void createInitParser()
           
protected  void createListParser()
           
protected  void createLogLevelParser()
           
protected  void createLogMessageParser()
           
protected  void createQueryParser()
           
protected  void createResumeParser()
           
protected  void createSuspendLogParser()
           
protected abstract  AbstractSTAFTextLogItem getSTAFTextLogItem(java.lang.String name, java.lang.String directory, java.lang.String filename)
           
protected abstract  AbstractSTAFXmlLogItem getSTAFXmlLogItem(java.lang.String name, java.lang.String directory, java.lang.String filename)
           
protected  com.ibm.staf.STAFResult handleClose(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleHandleId(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleHelp(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleInit(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleList(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleLogLevel(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleLogMessage(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleQuery(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleResumeLog(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleSuspendLog(InfoInterface.RequestInfo info)
           
protected  com.ibm.staf.STAFResult handleVersion(InfoInterface.RequestInfo info)
           
 com.ibm.staf.STAFResult init(InfoInterface.InitInfo info)
           
protected  int loadServiceInitParameters(InfoInterface.InitInfo info)
          Loads the service initialization parameters.
protected  java.lang.String normalizeAltname(java.lang.String altname, java.lang.String filename)
          Makes sure the altname option value is a file.
 com.ibm.staf.STAFResult terminate()
          Handles removing this service from STAF.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SLS_STAF_LOG_SERVICE_NAME

public static java.lang.String SLS_STAF_LOG_SERVICE_NAME
The name of the separate instance of STAF LOG service loaded and used solely by this service in local mode. This is built based on the name of the service to guarantee it is unique.


SLS_SERVICE_MODE_LOCAL

public static final java.lang.String SLS_SERVICE_MODE_LOCAL
See Also:
Constant Field Values

SLS_SERVICE_MODE_REMOTE

public static final java.lang.String SLS_SERVICE_MODE_REMOTE
See Also:
Constant Field Values

SLS_SERVICE_OPTION_DIR

public static final java.lang.String SLS_SERVICE_OPTION_DIR
See Also:
Constant Field Values

SLS_SERVICE_OPTION_CUSTOMLOGGING

public static final java.lang.String SLS_SERVICE_OPTION_CUSTOMLOGGING
See Also:
Constant Field Values

SLS_SERVICE_OPTION_REMOTE

public static final java.lang.String SLS_SERVICE_OPTION_REMOTE
See Also:
Constant Field Values

SLS_SERVICE_OPTION_NAME

public static final java.lang.String SLS_SERVICE_OPTION_NAME
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_HANDLEID

public static final java.lang.String SLS_SERVICE_REQUEST_HANDLEID
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_INIT

public static final java.lang.String SLS_SERVICE_REQUEST_INIT
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_QUERY

public static final java.lang.String SLS_SERVICE_REQUEST_QUERY
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_LIST

public static final java.lang.String SLS_SERVICE_REQUEST_LIST
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_SUSPENDLOG

public static final java.lang.String SLS_SERVICE_REQUEST_SUSPENDLOG
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_RESUMELOG

public static final java.lang.String SLS_SERVICE_REQUEST_RESUMELOG
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_LOGLEVEL

public static final java.lang.String SLS_SERVICE_REQUEST_LOGLEVEL
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_LOGMESSAGE

public static final java.lang.String SLS_SERVICE_REQUEST_LOGMESSAGE
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_CLOSE

public static final java.lang.String SLS_SERVICE_REQUEST_CLOSE
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_HELP

public static final java.lang.String SLS_SERVICE_REQUEST_HELP
See Also:
Constant Field Values

SLS_SERVICE_REQUEST_VERSION

public static final java.lang.String SLS_SERVICE_REQUEST_VERSION
See Also:
Constant Field Values

SLS_SERVICE_PARM_ALL

public static final java.lang.String SLS_SERVICE_PARM_ALL
See Also:
Constant Field Values

SLS_SERVICE_PARM_TEXTLOG

public static final java.lang.String SLS_SERVICE_PARM_TEXTLOG
See Also:
Constant Field Values

SLS_SERVICE_PARM_XMLLOG

public static final java.lang.String SLS_SERVICE_PARM_XMLLOG
See Also:
Constant Field Values

SLS_SERVICE_PARM_TOOLLOG

public static final java.lang.String SLS_SERVICE_PARM_TOOLLOG
See Also:
Constant Field Values

SLS_SERVICE_PARM_CONSOLELOG

public static final java.lang.String SLS_SERVICE_PARM_CONSOLELOG
See Also:
Constant Field Values

SLS_SERVICE_PARM_LINKEDFAC

public static final java.lang.String SLS_SERVICE_PARM_LINKEDFAC
See Also:
Constant Field Values

SLS_SERVICE_PARM_OVERWRITE

public static final java.lang.String SLS_SERVICE_PARM_OVERWRITE
See Also:
Constant Field Values

SLS_SERVICE_PARM_CAPXML

public static final java.lang.String SLS_SERVICE_PARM_CAPXML
See Also:
Constant Field Values

SLS_SERVICE_PARM_SETTINGS

public static final java.lang.String SLS_SERVICE_PARM_SETTINGS
See Also:
Constant Field Values

SLS_SERVICE_PARM_DEBUG

public static final java.lang.String SLS_SERVICE_PARM_DEBUG
See Also:
Constant Field Values

SLS_SERVICE_PARM_INFO

public static final java.lang.String SLS_SERVICE_PARM_INFO
See Also:
Constant Field Values

SLS_SERVICE_PARM_WARN

public static final java.lang.String SLS_SERVICE_PARM_WARN
See Also:
Constant Field Values

SLS_SERVICE_PARM_ERROR

public static final java.lang.String SLS_SERVICE_PARM_ERROR
See Also:
Constant Field Values

SLS_SERVICE_PARM_MESSAGE

public static final java.lang.String SLS_SERVICE_PARM_MESSAGE
See Also:
Constant Field Values

SLS_SERVICE_PARM_DESCRIPTION

public static final java.lang.String SLS_SERVICE_PARM_DESCRIPTION
See Also:
Constant Field Values

SLS_SERVICE_PARM_MSGTYPE

public static final java.lang.String SLS_SERVICE_PARM_MSGTYPE
See Also:
Constant Field Values

SLS_SETTINGS_MODE_PREFIX

public static final java.lang.String SLS_SETTINGS_MODE_PREFIX
Prefix to the mode setting of this service in response to the LIST SETTINGS command.

See Also:
Constant Field Values

SLS_SETTINGS_REMOTE_MACHINE_PREFIX

public static final java.lang.String SLS_SETTINGS_REMOTE_MACHINE_PREFIX
Prefix to the remote machine setting of this service in response to the LIST SETTINGS command.

See Also:
Constant Field Values

SLS_SETTINGS_REMOTE_SERVICE_PREFIX

public static final java.lang.String SLS_SETTINGS_REMOTE_SERVICE_PREFIX
Prefix to the remote service setting of this service in response to the LIST SETTINGS command.

See Also:
Constant Field Values

SLS_SETTINGS_DEFAULT_DIR_PREFIX

public static final java.lang.String SLS_SETTINGS_DEFAULT_DIR_PREFIX
Prefix to the default directory setting of this service in response to the LIST SETTINGS command.

See Also:
Constant Field Values

SLS_SETTINGS_CUSTOM_LOGGING_PREFIX

public static final java.lang.String SLS_SETTINGS_CUSTOM_LOGGING_PREFIX
Prefix to the custom logging service setting of this service in response to the LIST SETTINGS command.

See Also:
Constant Field Values

SLS_STATES_TOOLLOG_PREFIX

public static final java.lang.String SLS_STATES_TOOLLOG_PREFIX
Prefix to the toollog state of this service in the result buffer of every LOGMESSAGE command.

See Also:
Constant Field Values

SLS_STATES_CONSOLELOG_PREFIX

public static final java.lang.String SLS_STATES_CONSOLELOG_PREFIX
Prefix to the consolelog state of this service in the result buffer of every LOGMESSAGE command.

See Also:
Constant Field Values

SLS_STATES_LOGLEVEL_PREFIX

public static final java.lang.String SLS_STATES_LOGLEVEL_PREFIX
Prefix to the log level state of this service in the result buffer of every LOGMESSAGE command.

See Also:
Constant Field Values

VERSION_STR

public static final java.lang.String VERSION_STR
See Also:
Constant Field Values

HELP_STR

public static final java.lang.String HELP_STR
See Also:
Constant Field Values

HELP_MSGTYPE_STR

public static final java.lang.String HELP_MSGTYPE_STR
See Also:
Constant Field Values

logfacs

protected java.util.Hashtable logfacs
Stores all open log facilities created by this service.


handle

protected static com.ibm.staf.STAFHandle handle

initParser

protected com.ibm.staf.service.STAFCommandParser initParser

queryParser

protected com.ibm.staf.service.STAFCommandParser queryParser

listParser

protected com.ibm.staf.service.STAFCommandParser listParser

suspendLogParser

protected com.ibm.staf.service.STAFCommandParser suspendLogParser

resumeLogParser

protected com.ibm.staf.service.STAFCommandParser resumeLogParser

logLevelParser

protected com.ibm.staf.service.STAFCommandParser logLevelParser

logMessageParser

protected com.ibm.staf.service.STAFCommandParser logMessageParser

closeParser

protected com.ibm.staf.service.STAFCommandParser closeParser

helpParser

protected com.ibm.staf.service.STAFCommandParser helpParser

procName

protected java.lang.String procName

mode

protected java.lang.String mode

defaultDir

protected java.lang.String defaultDir

remoteMachine

protected java.lang.String remoteMachine

remoteService

protected java.lang.String remoteService

customService

protected java.lang.String customService

debugLog

protected ServiceDebugLog debugLog
Constructor Detail

AbstractSAFSLoggingService

public AbstractSAFSLoggingService()
Method Detail

loadServiceInitParameters

protected int loadServiceInitParameters(InfoInterface.InitInfo info)
Loads the service initialization parameters.

Parameters:
info - the InitInfo from STAF.
Returns:
a STAF RC.


createInitParser

protected void createInitParser()

createQueryParser

protected void createQueryParser()

createListParser

protected void createListParser()

createSuspendLogParser

protected void createSuspendLogParser()

createResumeParser

protected void createResumeParser()

createLogLevelParser

protected void createLogLevelParser()

createLogMessageParser

protected void createLogMessageParser()

createCloseParser

protected void createCloseParser()

createHelpParser

protected void createHelpParser()

handleHandleId

protected com.ibm.staf.STAFResult handleHandleId(InfoInterface.RequestInfo info)

getSTAFTextLogItem

protected abstract AbstractSTAFTextLogItem getSTAFTextLogItem(java.lang.String name,
                                                              java.lang.String directory,
                                                              java.lang.String filename)

getSTAFXmlLogItem

protected abstract AbstractSTAFXmlLogItem getSTAFXmlLogItem(java.lang.String name,
                                                            java.lang.String directory,
                                                            java.lang.String filename)

handleInit

protected com.ibm.staf.STAFResult handleInit(InfoInterface.RequestInfo info)

normalizeAltname

protected java.lang.String normalizeAltname(java.lang.String altname,
                                            java.lang.String filename)
Makes sure the altname option value is a file.

The altname option in the INIT request can specify either a file or a directory. Directory spec ends with a name separator, e.g. "\" for Win32. In this case, altname + filename is returned as the file spec for the log file.

Parameters:
altname - the altname option value. Directory spec ends with File.separator.
filename - the default file name to use to build the file spec in case altname is a directory. Ignored if altname is a file.
Returns:
the normalized log file spec.

handleQuery

protected com.ibm.staf.STAFResult handleQuery(InfoInterface.RequestInfo info)

handleList

protected com.ibm.staf.STAFResult handleList(InfoInterface.RequestInfo info)

handleSuspendLog

protected com.ibm.staf.STAFResult handleSuspendLog(InfoInterface.RequestInfo info)

handleResumeLog

protected com.ibm.staf.STAFResult handleResumeLog(InfoInterface.RequestInfo info)

handleLogLevel

protected com.ibm.staf.STAFResult handleLogLevel(InfoInterface.RequestInfo info)

handleLogMessage

protected com.ibm.staf.STAFResult handleLogMessage(InfoInterface.RequestInfo info)

handleClose

protected com.ibm.staf.STAFResult handleClose(InfoInterface.RequestInfo info)

handleHelp

protected com.ibm.staf.STAFResult handleHelp(InfoInterface.RequestInfo info)

handleVersion

protected com.ibm.staf.STAFResult handleVersion(InfoInterface.RequestInfo info)

init

public com.ibm.staf.STAFResult init(InfoInterface.InitInfo info)

acceptRequest

public com.ibm.staf.STAFResult acceptRequest(InfoInterface.RequestInfo info)
Handles service request from STAF.


terminate

public com.ibm.staf.STAFResult terminate()
Handles removing this service from STAF.

All log facilities are forced to close.