Logging Details: Difference between revisions

From Phidgets Support
(Redirected page to Phidget Logging)
Tag: New redirect
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{|
#REDIRECT [[Phidget Logging]]
|style="vertical-align:middle; width: 60%;"|
The {{Phidget22API}} 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 {{Phidget22API}} for language specific information.
|{{TOC limit|2}}
|}
 
==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'''
:Critical error messages.
:Errors at this level are generally non-recoverable and indicate either hardware problems, library bugs, or other serious issues.
 
'''ERROR'''
:Non-critical error messages.
:Errors at this level are generally automatically recoverable, but may help to track down issues.
 
'''WARNING'''
:Warning messages.
:Warnings are used to log behavior that is not necessarily in error, but is nevertheless odd or unexpected.
 
'''INFO'''
:Informational messages.
:Informational messages communicate useful operations and states changes within the software
 
'''VERBOSE'''
: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 {{Phidget22API}} documentation.
 
== Writing in the Phidgets Log ==
 
You can log your own messages to the Phidgets Log file by using the <code>log()</code> method from the Logging API.
 
For example, in C:
 
<syntaxhighlight lang=c>
PhidgetLog_log(PHIDGET_LOG_INFO, "Something happened in loop iteration %d!", i);
</syntaxhighlight>
 
Or in Java:
 
<syntaxhighlight lang=java>
Log.log(LogLevel.INFO, "Something happened in loop iteration " + i + "!");
</syntaxhighlight>
 
==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.
 
<syntaxhighlight lang=c>
#define MYSOURCE "mysource"
PhidgetLog_addSource(MYSOURCE, PHIDGET_LOG_INFO);
PhidgetLog_log(__FILE__, __LINE__, __func__, MYSOURCE, PHIDGET_LOG_INFO, "Something happened");
</syntaxhighlight>
 
Or in Java:
 
<syntaxhighlight lang=java>
public static final String MYSOURCE = "mysource";
Log.addSource(MYSOURCE, LogLevel.INFO);
Log.log(LogLevel.INFO, MYSOURCE, "Something happened);
</syntaxhighlight>

Latest revision as of 21:38, 3 August 2023

Redirect to: