Logging Aspect
Logging Aspect is an aspect and provides functionality of logging which includes free-form messages and tokens.
How logging aspect is different from logging?
Logging is part of the business component and you need to decide what needs to be logged at the design time. If any change is needed, then that business component has to go entire development life cycle .. design, development, built, test, deploy and the entire project may need to be restarted to pick up the changes.
Logging aspect is complementary to the logging. Logging aspect is external to components. The information thats being exchanged among components and the state of that message exchange can be logged. You can deploy this aspect any time you want and you can undeploy at your will without affecting your main project. And, its javafree thus no Java developer is needed.
How to create Logging Aspect
In Fuji Milestone 4 (M4), the aspects are taken a huge step forward to provide javafree aspects. Aspects user just need to specify a set of properties to enjoy the aspects.
In Fuji Milestone 7 (M7), aspects can be created at command line. The command for creation of aspect is "create-aspect key=value,key=value,*".
An example for creating an logging aspect.
-> fuji create-aspect name=Log-1 type=log status=Active log.content=Message
Alternatively, you can create aspects by the supported archetypes. Once after having Fuji, at least M4 version, here are the steps that are need to create Logging Aspects Project:
- In Netbeans, create a maven based project from Logging Aspect Archetype.
- For that project, edit log.properties under Other Sources/Aspects/Log.
- Build, Deploy and start the project
Logging aspect is ready and you see the specified log content is available at the specified interception points.
How to create more logging aspects
You can create as many logging aspects as you want in either of the following ways:
- Create multiple property files under Other Sources/Aspects/Log. Please ensure that "name" property is unique.
- Create multiple logging aspect projects from the provided logging aspect archetype.
Properties of Logging Aspect
You can specify any of the following interceptor related properties. You can refer
How to write an Interceptor for the recent supported properties.
| Property | For logging, intercept Message Exchange based on |
| name | Name of the Logging aspect. Must be unique in Fuji run time. By default, project name is chosen. |
| provider | service provider |
| consumer | service consumer |
| message | message type : ( "in", "out") |
| service | service name, can be the local name or the fully qualified service name |
| endpoint | endpoint name |
| status | message exchange status : {"DONE", "ERROR", "ACTIVE"} |
And you can specify any of the following logging properties:
| Property | Necessity | Description | Default Value |
| log.content | Needed | Free form messages, tokens, Header/Status/Message/Properties/All Ex: log.content=Status Ex: log.conent=Header,Properties Ex: log.content=First Name : {xpath://Employee/FName},Message,Status | Exchange:{exchangeid} Status:{status} |
| log.xpaths | Optional | Logs evaluated XPath expressions. Ex: /Employee/FName | None |
| log.token.<TokenName> | Optional | User defined token. Ex: log.token.country={xpath://Employee/Country} and this country token can be used log.content as log.conent={xpath://Employee/FName} lives in {country}. | None |
| log.console | Optional | True/False. Determines whether output is directed to console. Ex: log.console=true | If no other output option is chosen, its true. |
| log.config.dir | Optional | Directory name where the specified log.config.files resides. | <FujiDir>\trunk\packaging\release-packages\felix\target\classes\fuji |
| log.config.files | Optional | File names where logging is directed. | None |
| log.config.patterns | Optional | The pattern for naming the output file. Refer: http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/FileHandler.html | None |
| log.config.uris | Optional | URIs | None |
| log.config.file.limit | Optional | the maximum number of bytes to write to any one file | 0 |
| log.config.file.count | Optional | The number of files to use. | 1 |
| log.config.file.append | Optional | true/false. Specifies append mode | true |
| log.config.file.formatter | Optional | xml/simple | simple |
| log.header | Optional | Entire log.content can be given a heading of your choice. Ex: log.header=***This logging is for my MATH CALCULATIONS debugging******* | None |
| log.level | Optional | Logging level. This level need to be less restrictive than jdk logging level to log the log.content. | INFO |
Tokens of logging aspect
A token is enclosed by curly brackets, {} and is evaluated for the value. A token can embed other tokens. The tokens are processed recursively until there are no valid tokens to evaluate.
Built-in tokens
The following are built-in tokens.
role
endpoint.name/endpointname
message.type/messagetype
exchange.id/exchangeid
endpoint
service
operataion
pattern
status
error
fault
interface.name/interfacename
in-place tokens
XPaths expressions and property expressions can be used as an in-place token, which will be evaluated while logging the content.
- XPath expression in-place token example: {xpath://Employee/FName}
- Property expression in-place token example: {property:groupid}
Example of Logging Aspect
If the properties are,
log.content = Attempt to invoke {operataion} on service {endpoint.name}., The message of { xpath://Employee/FName} with {property:groupid} is being processed and his Address = {Emp.Address} . He is from {Country}.
log.token.Emp.Address={Emp.FullName} {Emp.Company}, {xpath://Employee/Street}, {xpath://Employee/City}, {xpath://Employee/State} - {xpath://Employee/ZIP}
log.token.Country = {xpath://Employee/Country}
and if the input is:
<Employee>
<EmpId>123</EmpId>
<FName>Ramesh</FName>
<LName>Dara</LName>
<Company>Sun Micro Systems</Company>
<Street>800, Royal Oaks Dr</Street>
<City>Monrovia</City>
<ZIP>91016</ZIP>
<State>CA</State>
<Country>USA</Country>
</Employee>
The output would be:
Attempt to invoke {http://fuji.dev.java.net/application/myJRuby}requestReply on service transform_endpoint.
The message of Ramesh with 402af89d-cf28-4211-bb60-484b44fdb710 is being processed and his Address = Ramesh Dara, Sun Micro Systems, 800, Royal Oaks Dr, Monrovia, CA - 91016 . He is from USA.