Example 3: Logs
If you can't play the video, make sure that you are logged in at Wex Solutions.
-
What will we do? - Learn how to implement logging capability to the extensions and how to use it
-
What do you need? - Site access to a non-production Windchill
-
How long will it take - 10 minutes
This example demonstrates how to incorporate logging into the WEX's code. Logging can be turned on and off and logs can be downloaded from the Extension Manager. If you want to learn more about logging, make sure you check out the Development section of the Developer Guide.
You can find the code for this example in our GitHub repository.
Implementation
You can find the code that includes the logging in this file:
com/wincomplm/wex/example/log/methods/ExampleMethods.java
As you will see, there are several types of log entry:
logger.error("Will always appear, for serious errors {0}", anObjectWithToString);
logger.warn("Something we want to know about {0}", anObjectWithToString);
logger.info("Used to give information on data {0}", anObjectWithToString);
// Debug and trace only appear if the extension logging is enabled in the manager
logger.debug("Used to give information on executiom {0}", anObjectWithToString);
The different types of logging are meant to be used with a purpose. They differ in their way of being enabled and the locations in which they appear:
Log type | Enable via action | Appears on Method Server | Description |
---|---|---|---|
error | false | true | Indicates a serious error, normally put into caught exceptions. |
warn | false | true | Provide information on anomalous events. |
info | true | true | General information that show interesting data. |
debug | true | false | Debug messages. |
trace | true | false | Used to mark entry and exit points of methods. |
Execution
The testing is done from a link located in the WEX's User Guide, which can be accessed from the Extension Manager:
It will use a simple JSP to run the test. The error and warn messages will appear in the Method Server logs:
Now try turning the WEX's logging on through the Extension Manager:
This will make the info messages pop up on the Method Server too:
You can also download the logs from the Manager:
The wex-example-log file will contain the trace type logs, which were not displayed on the Method Server.
2021-04-06 05:01:00 ERROR com.wincomplm.wex-example-log.ExampleMethods - Will always appear, for serious errors My object
2021-04-06 05:01:00 WARN com.wincomplm.wex-example-log.ExampleMethods - Something we want to know about My object
2021-04-06 05:01:00 INFO com.wincomplm.wex-example-log.ExampleMethods - Used to give information on data My object
2021-04-06 05:01:00 DEBUG com.wincomplm.wex-example-log.ExampleMethods - Used to give information on executiom My object
2021-04-06 05:01:00 TRACE com.wincomplm.wex-example-log.ExampleMethods - =>exampleTrace An argument
2021-04-06 05:01:00 TRACE com.wincomplm.wex-example-log.ExampleMethods - <=exampleTrace Done!