Logging Details

From Phidgets Support
Jump to: navigation, search

The Phidget22 API supports a general logging API that supports log levels, named sources of logs, and the writing of logs to a file or to a Phidget Network Server. The Phidget software library uses this logging system internally, but also allows you to log from your own software, so you can keep track of what your program is doing alongside information about what the Phidget libraries are doing in the background. Refer to the Logging API in the Phidget22 API for language specific information.

Log Levels

There are five different logging levels, ranging from "Give me Everything!" to "Tell me only about critical problems". Note that the DEBUG log level is only active for Debug builds of the library and should not be used.


Critical error messages.
Errors at this level are generally non-recoverable and indicate either hardware problems, library bugs, or other serious issues.


Non-critical error messages.
Errors at this level are generally automatically recoverable, but may help to track down issues.


Warning messages.
Warnings are used to log behavior that is not necessarily in error, but is nevertheless odd or unexpected.


Informational messages.
Informational messages communicate useful operations and states changes within the software


Verbose messages.
Verbose messages are informational messages that are expected to happen so frequently that they tend to drown out other log messages.

These are available in the Enumerations section of Logging API in the Phidget22 API documentation.

Writing in the Phidgets Log

You can log your own messages to the Phidgets Log file by using the log() method from the Logging API.

For example, in C:

PhidgetLog_log(PHIDGET_LOG_INFO, "Something happened in loop iteration %d!", i);

Or in Java:

Log.log(LogLevel.INFO, "Something happened in loop iteration " + i + "!");

Log Sources

The logging API supports the concept of a log source, where the log source is a textual identifier of where the log message originated. The log source is output to the log file along with the log message to help organize the data.

The following examples define and create a log source, and then write a log message using that source.

#define MYSOURCE "mysource"
PhidgetLog_log(__FILE__, __LINE__, __func__, MYSOURCE, PHIDGET_LOG_INFO, "Something happened");

Or in Java:

public static final String MYSOURCE = "mysource";
Log.addSource(MYSOURCE, LogLevel.INFO);
Log.log(LogLevel.INFO, MYSOURCE, "Something happened);