|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--com.sap.tc.logging.Configurator
|
+--com.sap.tc.logging.PropertiesConfigurator
Configures the Logging API according to a set of properties. A single properties configurator is set to get its properties either from a specific properties object or read it from a specific properties file. The configuration call itself does not take arguments and can therefore be automatically repeated with a desired periodicity.
The syntax of keys in the properties specification follows the general
syntax <Name>.<Attribute>,
where <Name> is the name of a location or category, and
<Attribute> is one of its attributes, for example
severity. If you want to set the severity for a location named
com.sap.tc.monitoring.Node to Severity.INFO you would
write:
If you would like to set a relative severity, for example for trace messages regarding object management, you use a kind of array element notation with the name of the corresponding category and write:com.sap.tc.monitoring.Node.severity = INFO
com.sap.tc.monitoring.Node.severity[/Objects/Management] = DEBUG
If you want to define logs for controllers or formatters for logs you often have to set additional attributes. In order to do this, you refer to these objects using variables. A variable uses an array element notation with the array name specifying the kind of object and the index giving the name of the variable. For example, with
you make a newlog[Trace] = FileLog
FileLog object, and assign it to a log variable
named Trace, which you then with
set the file name pattern attribute for. When you want to attach the file log to a location calledlog[Trace].pattern = %t/std.trc
com.sap.tc you write:
The plus sign in front of the log variable tells the configurator to attach the log in addition to other logs already set for the controller. If you omit it, logs already present will be discarded. Care has to be taken for if a log with the same attributes is already present it will be kept and the new log not attached. This has the advantage that periodic evaluation of, at least in part, unchanged configuration files does not lead to loss of state of the attached objects. Removing all logs is also possible using an empty log list:com.sap.tc.logs = + log[Trace]
Please note that it is not sufficient to just omit the logs attribute, as the configurator leaves alone all attributes not mentioned in the properties.com.sap.tc.logs =
To illustrate the use of formatter variables we want to configure a trace formatter with a custom pattern for the file log:
formatter[Trace] = TraceFormatter formatter[Trace].pattern = %24d: %m log[Trace].formatter = formatter[Trace]
Another typical application of log and formatter variables is to attach the same object to several other objects. For example, you first define a log variable refering to a console log, and then attach the log to several different controllers using the variable.
Sometimes you do not want to use a predefined class but one of your own to make an object. In rare cases, this might be your own log or formatter class but more often it is going to be a filter class for which there are no prefabricated implementations at all. You can do this by specifying the qualified name of this custom class:
However, for this to work the custom class needs to provide a no-argument constructor and either has to be installed in the class path or be part of your application. If not, the class loader to be used has to be set via the corresponding constructor, or later the call:log[Trace].filters = com.sap.tc.monitoring.Filter
You can set attributes of a custom class if inherited from a predefined class. For example, you can assign a value to the inherited attributepropertiesConfigurator.setClassLoader(classLoader)
pattern of a custom log class derived from FileLog.
The sequence in which all the above settings occur does not matter. What is left is to tell the properties configurator where to find the properties described above. Most often, a properties file is used, and you tell the configurator so when you make it, so the call reads something like:
propertiesConfigurator = new PropertiesConfigurator(new File("logging.properties"));
The complete syntax in case of a properties specification in a file looks like this:
In the above grammar, the words in quotes like
<Configuration> = <Entry>*. <Entry> = <Key> '='<Value>| <Key> ':'<Value>| <Key> <Value>. .<Key> = [<LogController> '.'] <LogControllerAttr>| <Log> [ '.'<LogAttr>]| <Formatter> [ '.'<FormatterAttr>].<LogController> = <Location> | <Category>. <Location> = [<Identifier> ( '.'<Identifier> ['('<Types>')'])*].<Types> = [<Type> ( ','<Type>)*].<Type> = <Identifier> ( '.'<Identifier>)* ('['']')*.<Category> = '/'[<Identifier> ('/'<Identifier>)*].<LogControllerAttr> = 'severity'[<Relative>]| 'effSeverity'[<Relative>]| 'minSeverity'[<Relative>]| 'maxSeverity'[<Relative>]| 'logs'| 'localLogs'| 'privateLogs'| 'filters'| 'bundleName'.<Relative> = '['<LogController>']'.<Log> = 'log''['<Identifier>']'.<LogAttr> = 'severity'| 'effSeverity'| 'encoding'| 'filters'| 'formatter'| 'desc'| 'autoFlush'| 'append'| 'pattern'| 'limit'| 'cnt'.<Formatter> = 'formatter''['<Identifier>']'.<FormatterAttr> = 'pattern'.<Value> = <Severity> | <Objects> | <String> | <Boolean> | <Identifier>. <Severity> = [ 'Severity''.'] ('NONE'|'FATAL'|'ERROR'|'WARNING'|'INFO'|'PATH'|'DEBUG')<Objects> = [[ '+'] <Object> (','<Object>)*].<Object> = <Class> | <Log> | <Formatter>. <Class> = 'FileLog'| 'ConsoleLog'| 'TraceFormatter'| 'ListFormatter'| 'XMLFormatter'| <Identifier> ( '.'<Identifier>)*.
'logs' or
'XMLFormatter' are reserved. If you want to use such a word as
an identifier, for example in a custom class name, escape it with
single quotes, like in:
In case of a properties object, use the syntax rules of <Key> and <Value> for defining keys and values of properties, respectively.log[Trace] = com.sap.tc.'logs'.GreatLog
Please find fundamental information about the principles of error handling
in the package description. For this class, there are two cases where the
methods Configurator.getException() and Configurator.throwException() are served.
First, if you forgot to provide a properties object or a properties file
you specified could not be found, constructors and setters leave a
java.lang.IllegalArgumentException. Second, the method
configure() hands over the same exception with different messages
if syntactical or semantical errors are discovered in a properties
specification. These errors are logged in even more detail to the category
/System/Logging which in turn writes messages to the console.
So if some properties do not quite work as you expected, have a look there
to find out about misspelled attribute names and the like.
| Constructor Summary | |
PropertiesConfigurator(java.io.File file)
Configures this properties configurator with a properties file and the class loader used for this class. |
|
PropertiesConfigurator(java.io.File file,
java.lang.ClassLoader classLoader)
Configures this properties configurator with a properties file and a custom class loader. |
|
PropertiesConfigurator(java.util.Properties properties)
Configures this properties configurator with a properties object and the class loader used for this class. |
|
PropertiesConfigurator(java.util.Properties properties,
java.lang.ClassLoader classLoader)
Configures this properties configurator with a properties object and a custom class loader. |
|
| Method Summary | |
void |
configure()
Configures tracing and logging according to the settings of the configurator. |
java.io.File |
getFile()
Gets the file used for this configurator. |
java.util.Properties |
getProperties()
Gets the properties object used for this configurator. |
void |
initConfigure()
To initialize configuration setting defined by user in the settings of the configurator. |
void |
setFile(java.io.File file)
Sets the file used for this configurator. |
void |
setProperties(java.util.Properties properties)
Sets the properties object used for this configurator. |
| Methods inherited from class com.sap.tc.logging.Configurator |
getClassLoader, getException, getPeriodicity, setClassLoader, setPeriodicity, throwException |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public PropertiesConfigurator(java.util.Properties properties)
properties - Properties objectPropertiesConfigurator(java.util.Properties,
java.lang.ClassLoader)
public PropertiesConfigurator(java.util.Properties properties,
java.lang.ClassLoader classLoader)
properties - Properties objectclassLoader - Custom class loaderPropertiesConfigurator(java.util.Properties)public PropertiesConfigurator(java.io.File file)
file - Properties filePropertiesConfigurator(java.io.File,
java.lang.ClassLoader)
public PropertiesConfigurator(java.io.File file,
java.lang.ClassLoader classLoader)
file - Properties fileclassLoader - Custom class loaderPropertiesConfigurator(java.io.File)| Method Detail |
public java.util.Properties getProperties()
null if there is nonesetProperties(java.util.Properties)public void setProperties(java.util.Properties properties)
properties - Properties objectgetProperties()public java.io.File getFile()
null if there is nonesetFile(java.io.File)public void setFile(java.io.File file)
file - Filejava.lang.IllegalArgumentException - No filegetProperties()public void configure()
Configuratorconfigure in class Configurator
public void initConfigure()
throws java.lang.IllegalArgumentException,
java.io.FileNotFoundException,
java.io.IOException,
java.lang.Exception
configure()
that is bundled with periodic feature.java.lang.IllegalArgumentException - Null properties contentjava.io.FileNotFoundException - Properties file(if specified) cannot be locatedjava.io.IOException - Problems reading properties file content
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||