Phidget Logging: Difference between revisions
(Created page with "Category:Overview __TOC__ 400px|link=https://www.phidgets.com/docs/images/8/8d/Logging_logfileexample.png|thumb|<center>A log file generated by the Phidget library</center> ==What Is Phidget Logging?== The Phidget library can automatically create a timestamped log describing the state of your program for you. This is extremely useful for debugging purposes and is recommended for all Phidget programs. <br><br><br> <br><br> ===Enabl...") |
|||
Line 91: | Line 91: | ||
===Log Rotation=== | ===Log Rotation=== | ||
Log rotation is enabled by default. When the log file reaches 10MiB, the Phidget library will automatically archive the contents in a new file at the same location. The new file will be timestamped showing when the rotation occurred. | Log rotation is enabled by default. When the log file reaches 10MiB, the Phidget library will automatically archive the contents in a new file at the same location. The new file will be timestamped showing when the rotation occurred. | ||
[[File:Logging_logrotation.png|center|link=]] | [[File:Logging_logrotation.png|center|link=]] | ||
If the log file reaches 10MiB again, the previous archive will be deleted, and a new one will be created in its place. As a result of the default behavior, the maximum amount of space that log files will use is 20MiB. | If the log file reaches 10MiB again, the previous archive will be deleted, and a new one will be created in its place. As a result of the default behavior, the maximum amount of space that log files will use is 20MiB. | ||
You can change the maximum log file size (from 32 KiB to 10 MiB) and the number of log archives to keep (up to 64) through the Logging API. | You can change the maximum log file size (from 32 KiB to 10 MiB) and the number of log archives to keep (up to 64) through the Logging API. |
Latest revision as of 22:27, 3 August 2023
What Is Phidget Logging?
The Phidget library can automatically create a timestamped log describing the state of your program for you. This is extremely useful for debugging purposes and is recommended for all Phidget programs.
Enable Logging
Only one line of code is required to enable logging. After setting a log level and a file path, the Phidget library will automatically log any important Phidget events for you.
It is important to enable logging before making any other calls to the Phidget library.
Log.enable(LogLevel.PHIDGET_LOG_INFO, "phidgetlog.log")
Log.enable(LogLevel.INFO, "phidgetlog.log");
Log.Enable(LogLevel.Info, "phidgetlog.log");
PhidgetLog_enable(PHIDGET_LOG_INFO, "phidgetlog.log");
phidget22.Log.enable(phidget22.LogLevel.INFO, "logfile.log"); //not available client-side
Custom Log Messages
After logging has been enabled, you can choose to log your own custom messages.
Log.log(LogLevel.PHIDGET_LOG_INFO, "custom message")
Log.log(com.phidget22.LogLevel.INFO, "custom message");
Log.WriteLine(Phidget22.LogLevel.Info, "custom message");
PhidgetLog_log(PHIDGET_LOG_INFO, "custom message");
phidget22.Log.log(phidget22.LogLevel.INFO, "custom message"); //not available client-side
Log Entry Format
Each log entry will have the following components:
Log Levels
In the code examples above, you may have noticed the INFO log level being referenced. There are six different log levels that are used to sort messages in terms of importance:
Importance | Log Level | Description | Notes |
---|---|---|---|
High | CRITICAL | A fatal error has occurred in the Phidget library and the program will be aborted. | |
ERROR | An unexpected error has occurred which has not been handled. This will impact a user. | Recommended for space-constrained systems. | |
WARNING | An error has occurred that the library has handled. This should not impact a user. | ||
INFO | Information about the state of the program (e.g. attach/detach events, server connects/disconnects, etc.). | Recommended for all systems without space limitations. | |
DEBUG | Do not use. | ||
Low | VERBOSE | Do not use. |
When setting a log level, all levels with higher importance will automatically be logged. For example, if the log level is set to WARNING, both ERROR and CRITICAL messages will also be logged.
It is recommended to use INFO when possible, and ERROR on space-constrained systems.
Advanced Use
Log Rotation
Log rotation is enabled by default. When the log file reaches 10MiB, the Phidget library will automatically archive the contents in a new file at the same location. The new file will be timestamped showing when the rotation occurred.
If the log file reaches 10MiB again, the previous archive will be deleted, and a new one will be created in its place. As a result of the default behavior, the maximum amount of space that log files will use is 20MiB.
You can change the maximum log file size (from 32 KiB to 10 MiB) and the number of log archives to keep (up to 64) through the Logging API.