Logging
The ThingWorx Edge Java SDK provides logging capabilities that provide a mechanism for writing data to text files. The logging mechanism is designed to isolate logging by class to help you log only what is of interest.
This SDK uses SLF4J (Simple Logging Facade for Java) as a façade for its logging operations, and includes the logback framework (http://logback.qos.ch/documentation.html). By using SLF4J, you can incorporate the logging of the SDK into your application, using your chosen logging implementation. For more information, visit http://www.slf4j.org/.
Click a section title to display its content:
Log Levels 
Each log level writes out any messages that are written in a lower log level. For example, if the logging of the application is set to Trace, then Debug, Info, Warn, and Error level messages are written to the log file. If the logging of the application is set to Warn, only Warn and Error level messages are written to the log.
* 
Logs are very useful for debugging during development or later for troubleshooting an issue, away from the production environment. Never run in a production environment with the Debug or Trace log levels.
To troubleshoot an issue, set the log level to Trace or Debug, and re-run the application. Review the resulting logs to locate messages that indicate the issue. If you call PTC Technical Support, be prepared with as much information as possible. It is strongly recommended that you run a trace log first so that you are ready to send it when asked.
The following table describes the supported log levels:
Log Level
Description
Trace
The most detailed logs, useful for debugging while you develop an application. Trace logs can provide fine-grained information when tracking down issues that are difficult to find.
Debug
Logs used to help in debugging issues. These log messages contain information about what the code is doing at the moment and the values of any important variables.
Info
Important system information, such as periodic tasks that are running and changes in the state of an application. In most cases, exceptions are not logged at this level
Warn
Unexpected exceptions that are acceptable or that can be worked around. Any problems that could become errors if left unattended.
Error
Issues that affect the usage or performance of the system.
The next two sections describe the classes to use for logging in the ThingWorx Edge Java SDK.
LoggerFactory Class 
The LoggerFactory class is a helper class that makes logging much simpler than having to create the logging from scratch. It is part of the SLF4J logging.
Logger getLogger(Class clazz) — The getLogger method returns a Logger to perform logging for a specific class. This is usually done on a static, non-modifiable member variable. For example:

// The following line creates a logger based on the SteamThing class
private static final Logger LOG = LoggerFactory.getLogger(SteamThing.class);
Logger Class 
The Logger class performs the logging. Methods exist for each log level. Only the most used trace methods are outlined here, but they can all be interpolated from these. The same method signatures are available for debug, info, warn, and error. For more information, visit http://logback.qos.ch/documentation.html (logback) or http://www.slf4j.org/ (SLF4J)
* 
All the examples below assume that an instance of the Logger class, named LOG was previously created.
info(String arg0) — Logs a simple message. For example:

LOG.info("Initialization complete.");
info(String arg0, Object arg1) — Logs a message with a single object argument. For example:

LOG.info("Thing {} has successfully started.", thing.getName());
trace(String arg0, Throwable arg1) — Logs a message with a throwable type as well. For example:

LOG.info("Exception occurred", e);
info(String arg0, Object… arg1) — Logs a message with many object arguments. For example:

LOG.info("Thing {} was started with {} properties at {}", thing.getName(),
thing.getProperties().size(), new DateTime());
Was this helpful?